#!/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 PYBUILD_NAME=bumps

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

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .mplconfig doc/_build doc/api doc/dream doc/tutorial api dream .cache

override_dh_install:
	dh_install
	mv debian/python-bumps/usr/bin/bumps  debian/python-bumps/usr/bin/bumps2
	./debian/relocate python-bumps usr/lib/python2.7/dist-packages/bumps/gui/resources usr/share/python-bumps/python
	for py in `py3versions -i`; do \
	  ./debian/relocate python3-bumps usr/lib/$$py/dist-packages/bumps/gui/resources usr/share/python-bumps/python3; \
	done
	find debian/python3-bumps/usr -name __pycache__ -exec rm -rf {} +

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bhtml     doc/ build/html # HTML generator
	ln -sf /usr/share/javascript/mathjax/ build/html/_static/mathjax
	PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -btexinfo     doc/ build/texinfo # texinfo generator

override_dh_installinfo:
	cd build/texinfo; \
	for p in *.png; do mv $$p bumps-$$p; done; \
	sed "s/@image{/@image{bumps-/" -i bumps.texi; \
	makeinfo bumps.texi
	dh_installinfo

override_dh_installman:
	cp debian/bumps.1 debian/bumps2.1
	dh_installman
	rm debian/bumps2.1

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	LC_ALL=C.UTF-8 \
	  PYBUILD_TEST_ARGS_python2="-v --all-modules --with-doctest --doctest-options=+ELLIPSIS,+NORMALIZE_WHITESPACE bumps" \
	  PYBUILD_TEST_ARGS_python3="-v --all-modules --with-doctest --doctest-options=+ELLIPSIS,+NORMALIZE_WHITESPACE -egui bumps" \
	  dh_auto_test
endif
