#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export PYBUILD_NAME=cf

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

override_dh_auto_build-indep:
	PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -E -b html docs/source docs/build/html

override_dh_auto_test-indep:
	# -indep only builds documentations, so tests would fail and are not necessary

override_dh_auto_test-arch:
	dh_auto_test -a -O--buildsystem=pybuild -- --system=custom \
                     --before-test 'cp -R {dir}/test {build_dir}; echo {build_dir}/test >> {home_dir}/build_dirs_to_rm_before_install' \
                     --test-args='cd {build_dir}; {interpreter} test/run_tests.py'
	# Delete (unreproducible) file generated in tests so it does not appear
	# in the .deb.
	find -type f -name delme.nca -delete

override_dh_installdocs-indep:
	dh_installdocs -i
	ln -s /usr/share/javascript/mathjax/MathJax.js $(CURDIR)/docs/build/html/_static/
	ln -s /usr/share/javascript/jquery/jquery.min.js $(CURDIR)/docs/build/html/_static/
	ln -s /usr/share/javascript/requirejs/requirejs.min.js $(CURDIR)/docs/build/html/_static/
	find docs/build/html -name "*.html" -exec sed -i "s|https://cdn.mathjax.org/mathjax/latest/MathJax.js|_static/MathJax.js|" {} \;
	find docs/build/html -name "*.html" -exec sed -i "s|https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js|_static/jquery.min.js|" {} \;
	find docs/build/html -name "*.html" -exec sed -i "s|https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js|_static/require.min.js|" {} \;
	dh_installdocs -ppython-cf-doc docs/build/html
