#!/usr/bin/make -f

export DH_VERBOSE=1
export SPECFILE_USE_GNU_SOURCE=1
export WITH_CYTHON=1
export QHULL_CFLAGS=-I/usr/include/qhull
export QHULL_LIBS=-lqhull
export PYMCA_DATA_DIR=/usr/share/pymca
export PYMCA_DOC_DIR=$(PYMCA_DATA_DIR)/doc
export PYMCA_DISTUTILS=1

export PYBUILD_NAME=pymca5
export PYBUILD_AFTER_INSTALL=rm -rf {destdir}/usr/bin/ {destdir}/usr/share/man {destdir}$(PYMCA_DATA_DIR)

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

override_dh_clean:
	dh_clean
	# remove the .c cython generated files
	find PyMca5 -iname *.pyx | sed -e 's,\.pyx,\.c,g' | xargs -r rm -f
	# remove the build documentation
	rm -rf doc/build

override_dh_auto_build:
	dh_auto_build
	env -u PYMCA_DATA_DIR -u PYMCA_DOC_DIR python setup.py build build_doc

override_dh_installchangelogs:
	dh_installchangelogs changelog.txt

override_dh_install:
	dh_install -O--buildsystem=pybuild

	# pymca
	#python3 setup.py install_scripts -d debian/pymca/usr/bin
	#dh_install -p pymca debian/python3-pymca5/usr/bin /usr/bin
	dh_install -p pymca ./build/scripts-3.5/* /usr/bin
	python setup.py install_man -d debian/pymca/usr/share/man

	dh_install -p pymca package/desktop/*.desktop usr/share/applications
	dh_install -p pymca package/desktop/PyMca.png usr/share/icons/hicolor/256x256/apps
	dh_install -p pymca package/desktop/pymca.xml usr/share/mime/packages

	# pymca-data
	python setup.py install_data --root debian/pymca-data/
	rm -f debian/pymca-data/usr/share/pymca/EPDL97/LICENSE
	rm -f debian/pymca-data/usr/share/pymca/LICENSE
	rm -f debian/pymca-data/usr/share/pymca/LICENSE.GPL
	rm -f debian/pymca-data/usr/share/pymca/LICENSE.LGPL
	rm -f debian/pymca-data/usr/share/pymca/LICENSE.MIT
	rm -rf debian/pymca-data/usr/share/pymca/doc/HTML/PyMCA_files/

	dh_numpy
	dh_numpy3

override_dh_auto_test:
	echo "Remember to run tests after installing the packages"

override_dh_installdocs:
	dh_installdocs "build/sphinx/html" -p pymca-doc
	dh_installdocs
