#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DEBPKGNAME     := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')

# Fails to build with the following settings
# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# export DEB_BUILD_MAINT_OPTIONS = hardening=+pie
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

%:
	dh $@  --with autoreconf --with python3

override_dh_auto_install:
	dh_auto_install
	# pybuild --install --system=distutils
	cd python && \
	python3 setup.py install --root=../debian/gubbins --install-layout=deb --install-lib=/usr/share/gubbins --install-scripts=/usr/share/gubbins

override_dh_auto_test:
	dh_auto_test
	cd python && \
	python3 setup.py test

override_dh_install:
	dh_install
	find debian -name "*.la" -delete
	find debian -name "*.a" -delete
	mkdir -p debian/$(DEBPKGNAME)/usr/lib/$(DEBPKGNAME)
	mv debian/$(DEBPKGNAME)/usr/bin/gubbins debian/$(DEBPKGNAME)/usr/lib/$(DEBPKGNAME)

override_dh_clean:
	dh_clean
	rm -rf python/*.egg-info python/build  python/Makefile
	find . -name "*.pyc" -delete
