#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

export LC_ALL=C.UTF-8

export PYBUILD_NAME=biom-format
export PYBUILD_DESTDIR=debian/python3-$(PYBUILD_NAME)
export PYBUILD_BEFORE_TEST=cp -r {dir}/examples {build_dir}
export PYBUILD_AFTER_TEST=rm -rf {build_dir}/examples
export PYBUILD_AFTER_INSTALL= rm -fr {destdir}/usr/lib/python3*/dist-packages/biom_format*/top_level.txt \
	                      rm -fr {destdir}/usr/lib/python3*/dist-packages/doc \
	                      rm -fr {destdir}/usr/lib/python3*/dist-packages/licenses \

## When trying better hardening the build fails
# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

%:
	dh $@ --with bash-completion,numpy3 --buildsystem=pybuild

execute_before_dh_install:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR)/debian/python3-biom-format/usr/lib/python$(shell py3versions -dv)/dist-packages \
		    http_proxy='127.0.0.1:9' sphinx-build -N -b html doc build/html
	PYTHONPATH=$(CURDIR)/debian/python3-biom-format/usr/lib/python$(shell py3versions -dv)/dist-packages \
		    http_proxy='127.0.0.1:9' sphinx-build -N -b man doc build/man
endif

execute_after_dh_fixperms:
	find debian -name exercise_cli.sh -exec chmod +x \{\} \;

execute_after_dh_installexamples:
	find debian -name "*.c" -delete
	find debian -name "*.pyx" -delete
	# move tests from Python3 package to examples package
	if [ ! -d biom/tests ] ; then \
	    mv `find debian/python*$(PYBUILD_NAME) -name tests -type d` biom ; \
	else \
	    find debian/python*$(PYBUILD_NAME) -name tests -type d | xargs rm -rf ; \
	fi
