#!/usr/bin/make -f

export PYBUILD_NAME=fabio
export PYBUILD_AFTER_INSTALL=rm -rf {destdir}/usr/bin/

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

override_dh_clean:
        # remove the cython generated files distributed by upstream
	rm -f $(patsubst %.pyx,%.c,$(wildcard fabio/ext/*.pyx))
	rm -rf doc/build/html
	rm -rf build/man
	rm -rf *.egg-info
	dh_clean

override_dh_auto_build:
	dh_auto_build
#	PYBUILD_SYSTEM=custom \
	PYBUILD_BUILD_ARGS="PYTHONPATH={build_dir} cd {build_dir} && xvfb-run -a --server-args=\"-screen 0 1024x768x24\" {interpreter} -m fabio.app.convert --help" dh_auto_build
#	PYBUILD_SYSTEM=custom \
	PYBUILD_BUILD_ARGS="PYTHONPATH={build_dir} cd {build_dir} && xvfb-run -a --server-args=\"-screen 0 1024x768x24\" {interpreter} -m fabio.app.viewer --help" dh_auto_build
	PYBUILD_SYSTEM=custom \
	PYBUILD_BUILD_ARGS="PYTHONPATH={build_dir} xvfb-run -a --server-args=\"-screen 0 1024x768x24\" {interpreter} setup.py build_man" dh_auto_build

override_dh_auto_test:
#       https://github.com/silx-kit/fabio/issues/153
#	PYBUILD_SYSTEM=custom \
	PYBUILD_TEST_ARGS="PYTHONPATH={build_dir} http_proxy='127.0.0.1:9' FABIO_TESTIMAGES=testimages xvfb-run -a --server-args=\"-screen 0 1024x768x24\" {interpreter} ./run_tests.py" dh_auto_test

override_dh_install:
	dh_install
	dh_numpy
	dh_numpy3

        # install scripts into fabio-viewer
	python3 setup.py install_scripts -d debian/fabio-viewer/usr/bin

override_dh_installman:
	dh_installman -p fabio-viewer build/man/*.1

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYBUILD_SYSTEM=custom \
	PYBUILD_BUILD_ARGS="cd doc && PYTHONPATH={build_dir} http_proxy='127.0.0.1:9' {interpreter} -m sphinx -N -bhtml source build/html" dh_auto_build  # HTML generator
	dh_installdocs "doc/build/html" -p python-fabio-doc
	dh_link -p python-fabio-doc /usr/share/javascript/mathjax /usr/share/doc/python-fabio-doc/html/_static/mathjax
	dh_sphinxdoc -X_static/mathjax -O--buildsystem=pybuild
endif