#!/usr/bin/make -f
#export DH_VERBOSE=1
#export DEB_BUILD_OPTIONS=nocheck
export PYBUILD_NAME=hovercraft

DEBDATE := $(shell dpkg-parsechangelog -Sdate | date -u +%F -f -)

%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_test:
	# a hack to get the tests running w/o python-logo-master-v3-TM.png:
	ln -s $(CURDIR)/docs/examples/images/hovercraft_logo.png $(CURDIR)/hovercraft/tests/test_data/images/python-logo-master-v3-TM.png
	ln -s $(CURDIR)/docs/examples/images/hovercraft_logo.png $(CURDIR)/hovercraft/tests/test_data/maximal/images/python-logo-master-v3-TM.png
	dh_auto_test
	rm -vf $(CURDIR)/hovercraft/tests/test_data/images/python-logo-master-v3-TM.png
	rm -vf $(CURDIR)/hovercraft/tests/test_data/maximal/images/python-logo-master-v3-TM.png

override_dh_auto_install:
	python3 setup.py install --root=debian/hovercraft --install-layout=deb --install-lib=/usr/share/hovercraft --install-scripts=/usr/share/hovercraft
	# strip tests from binary, they're not running due to missing python-logo-master-v3-TM.png:
	find debian/hovercraft -type d -name tests -print | xargs /bin/rm -rf
	# use packaged impress.js instead of covenience code for binary:
	find debian/hovercraft -name impress.js -exec ln -sfv /usr/share/javascript/impress/impress.js '{}' \;

override_dh_installdocs:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. sphinx-build -N -bhtml docs debian/hovercraft/usr/share/doc/hovercraft/html
	dh_installdocs
endif

override_dh_installman:
	PYTHONPATH=. sphinx-build -N -bman -D today_fmt="$(DEBDATE)" docs .pybuild
	dh_installman .pybuild/hovercraft.1

override_dh_compress:
	dh_compress -X.rst # save examples
