#!/usr/bin/make -f

#include /usr/share/quilt/quilt.make

export CFLAGS=$(shell dpkg-buildflags --get CFLAGS)
export CPPFLAGS=$(shell dpkg-buildflags --get CPPFLAGS)
export CXXFLAGS=$(shell dpkg-buildflags --get CXXFLAGS)
export LDFLAGS=$(shell dpkg-buildflags --get LDFLAGS)

%:
	dh $@

override_dh_auto_configure:
	cmake \
	 -DCMAKE_INSTALL_PREFIX=/usr \
	 -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=$(CURDIR)/Release \
	 -DCMAKE_BUILD_TYPE=Release \
	 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$(CURDIR)/Release \
	 -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$(CURDIR)/Release \
	 -DCMAKE_CACHEFILE_DIR=$(CURDIR)/build \
	 $(CURDIR)

override_dh_auto_build:
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp VERBOSE=1 \
		CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
		CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)"

override_dh_auto_clean:
	[ ! -f Makefile ] || make clean VERBOSE=1
	-rm -rf CMakeFiles/ pm_*/CMakeFiles porttime/CMakeFiles CMakeCache.txt
	-rm -rf cmake_install.cmake pm_*/cmake_install.cmake porttime/cmake_install.cmake
	-rm -rf Makefile pm_*/Makefile porttime/Makefile
	-rm -f install_manifest.txt

override_dh_auto_install:
	# do not ship executables c files
	chmod a-x $(CURDIR)/pm_test/*.c $(CURDIR)/pm_common/*.h
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install VERBOSE=1
	dh_install --sourcedir=$(CURDIR)/debian/tmp

override_dh_compress:
	dh_compress -X.c -X.h -XMakefile
