#!/usr/bin/make -f

CPPFLAGS=$(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS)
CPPFLAGS+= -I/usr/include/opencv
LDFLAGS+=-Wl,-z,defs -Wl,--as-needed

export CPPFLAGS LDFLAGS

EXAMPLEPKG = libdecodeqr-examples

%:
	dh $@ --with quilt

override_dh_clean:
	- $(MAKE) -C src distclean
	rm -rf src/Makefile src/libdecodeqr/Makefile src/sample/Makefile src/sample/simple/Makefile src/sample/webcam/Makefile src/test/Makefile
	rm -rf modules/python/src2/hdr_parser.pyc
	rm -f src/config.log
	dh_clean

override_dh_auto_configure:
	dh_auto_configure --sourcedirectory=src -- --with-cv=opencv_core --with-highgui=opencv_highgui 
	sed -i s/cxcore/opencv_imgproc/ src/libdecodeqr/Makefile
	sed -i s/cxcore/opencv_imgproc/ src/sample/simple/Makefile
	sed -i s/cxcore/opencv_imgproc/ src/sample/webcam/Makefile

override_dh_auto_build:
	$(MAKE) -C src DESTDIR=$(CURDIR)/debian/tmp

	dh_auto_build

override_dh_auto_install:
	dh_auto_install --sourcedirectory=src

override_dh_install:
	# Install QR image files
	install -d $(CURDIR)/debian/tmp/usr/share/doc/$(EXAMPLEPKG)/img
	install -m 755 $(CURDIR)/img/* $(CURDIR)/debian/tmp/usr/share/doc/$(EXAMPLEPKG)/img
	
	dh_install --sourcedir=debian/tmp
