#!/usr/bin/make -f

export PYBUILD_NAME=pyfai
export PYBUILD_AFTER_INSTALL=rm -rf {destdir}/usr/bin/
export POCL_CACHE_DIR=$(CURDIR)/.cache/

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

override_dh_clean:
	dh_clean
	rm -f $(patsubst %.pyx,%.c,$(wildcard pyFAI/ext/*.pyx))
	rm -rf doc/build/html
	rm -rf build/man
	rm -rf *.egg-info
	rm -f all_testimage.json fai_cfg.json lima_cfg.json profile.log
	rm -rf $(POCL_CACHE_DIR)

override_dh_auto_build:
	mkdir -p $(POCL_CACHE_DIR) # create POCL cachedir in order to avoid an FTBFS in sbuild
	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:
	mkdir -p $(POCL_CACHE_DIR) # create POCL cachedir in order to avoid an FTBFS in sbuild
	PYBUILD_SYSTEM=custom \
	PYBUILD_TEST_ARGS="PYTHONPATH={build_dir} http_proxy='127.0.0.1:9' PYFAI_TESTIMAGES=testimages PYFAI_DATA=$(shell pwd) xvfb-run -a --server-args=\"-screen 0 1024x768x24\" {interpreter} ./run_tests.py --low-mem --no-opencl --installed" dh_auto_test

override_dh_install:
	dh_numpy
	dh_numpy3

        # install scripts into pyfai
	python setup.py install_scripts -d debian/pyfai/usr/bin

	# Finally install stuff
	dh_install

override_dh_installman:
	dh_installman -p pyfai build/man/*.1

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYBUILD_SYSTEM=custom \
	PYBUILD_DISABLE=build/python2-dbg \
	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-pyfai-doc
	dh_sphinxdoc -O--buildsystem=pybuild
endif
