#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

export PYBUILD_NAME=guiqwt
export PYBUILD_BUILD_ARGS=--no-doc

export LC_ALL=C

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

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

override_dh_auto_install:
	dh_auto_install
	dh_numpy3
	# install the .desktop files
	dh_install -p python3-guiqwt debian/guiqwt-tests-py3.desktop /usr/share/applications
	dh_install -p python3-guiqwt debian/sift-py3.desktop /usr/share/applications
	# install the qtdesigner files
	dh_install -p python3-guiqwt qtdesigner/*.py /usr/lib/$(DEB_HOST_MULTIARCH)/qt5/plugins/designer/python

override_dh_python3:
	dh_python3
	dh_python3 -p python3-guiqwt /usr/lib/$(DEB_HOST_MULTIARCH)/qt5/plugins/designer/python

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 . build/html" dh_auto_build  # HTML generator
	dh_installdocs "doc/build/html" -p python-guiqwt-doc --doc-main-package=python-guiqwt-doc
	dh_sphinxdoc -O--buildsystem=pybuild
endif
