#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --with python3 --buildsystem pybuild

execute_before_dh_auto_clean:
	make -C faq clean
	make -C manual clean

execute_before_dh_auto_build:
	cd pyx/data/lfs; python3 createlfs.py

override_dh_auto_build-indep:
	make -C faq all
	make -C manual all

execute_after_dh_auto_install:
	rm $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/pyx/data/lfs/createlfs.*
	rm -f $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/output

override_dh_installdocs-indep:
	mv manual/_build/html/ manual/_build/manual/
	mv faq/_build/html/ faq/_build/faq/
	dh_installdocs -Xobjects.inv
	ln -sf /usr/share/javascript/mathjax/ \
	  debian/python3-pyx-doc/usr/share/doc/python3-pyx/manual/_static/mathjax
	dh_sphinxdoc

execute_after_dh_installexamples-indep:
	# A handful of examples have "#!/usr/bin/env python" that needs
	# cleaning up in the package.
	find debian/python*doc/usr/share/doc/python3-pyx/examples/ \
	  -name \*py \
	  -exec grep -l -e '#!/usr/bin/env' {} + | \
	  xargs sed -i -r 's/(#!\/usr\/bin\/env python)$$/\13/'

override_dh_compress:
	dh_compress --all -X.pdf -X.ipynb

# Use some examples as a test suite
export PYBUILD_TEST_CUSTOM = 1
export PYBUILD_BEFORE_TEST = cp -r {dir}/examples {build_dir}
export PYBUILD_AFTER_TEST = rm -rf {build_dir}/examples
export PYBUILD_TEST_ARGS = {interpreter} -u {dir}/debian/examples-testrunner

override_dh_auto_test-indep:
	# No tests for the doc package

.PHONY: doc lfs
