#!/usr/bin/make -f
export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS=hardening=+BINDNOW
export PYBUILD_NAME=pycorrfit
export PYBUILD_TEST_PYTEST=1
ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
        export PYBUILD_TEST_PYTEST=0
endif

include /usr/share/dpkg/architecture.mk
ifeq ($(DEB_HOST_ARCH),s390x)
        export PYBUILD_TEST_PYTEST=0
endif

export PYBUILD_AFTER_INSTALL=rm -fr {destdir}/usr/lib/python3*/dist-packages/pycorrfit-*/top_level.txt \
                             rm -fr {destdir}/usr/lib/python3*/dist-packages/${PYBUILD_NAME}/readfiles/read_pt3_scripts/README \
                             rm -fr {destdir}/usr/lib/python3*/dist-packages/${PYBUILD_NAME}/readfiles/read_pt3_scripts/LICENSE

%:
	dh $@ --buildsystem=pybuild --with numpy3

execute_before_dh_auto_build:
	convert -background "rgba(255,255,255,0)" -geometry 32x32 \
		doc/Images/PyCorrFit_icon.svg debian/pycorrfit.xpm

execute_after_dh_auto_build:
	cd docs && PYTHONPATH=.. sphinx-build -b man . ../build/man
	mv build/man/PyCorrFit.1 build/man/pycorrfit.1

override_dh_installman:
	dh_installman build/man/*.1

execute_after_dh_install:
	dh_install -X__pycache__ -X.*pyc
	install -Dm644 debian/pycorrfit.xpm \
		debian/${PYBUILD_NAME}/usr/share/pixmaps/pycorrfit.xpm

execute_after_dh_fixperms:
	find debian/${PYBUILD_NAME}/usr/share/doc/${PYBUILD_NAME}/examples -type f -name "*.txt" -exec chmod 644 \{\} \;

override_dh_compress:
	dh_compress -Xexternal_model_functions

execute_before_dh_installexamples:
	tar --sort=name \
            --mtime="@${SOURCE_DATE_EPOCH}" \
            --owner=root --group=root --numeric-owner \
            --mode=go=rX,u+rw,a-s \
            -cJf debian/${PYBUILD_NAME}/usr/share/doc/${PYBUILD_NAME}/examples/tests.tar.xz  tests/
