#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export LC_ALL=C.UTF-8
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

export PYBUILD_BEFORE_TEST=cp -r {dir}/tests/data {build_dir}
export PYBUILD_TEST_PYTEST=1
export PYBUILD_TEST_ARGS=-k 'not test_pickleable_member_roundtrip and not test_pickleable_roundtrip'
export PYBUILD_NAME=cogent3
ifneq (,$(filter $(DEB_HOST_ARCH), armel mipsel s390x mips64el))
export PYBUILD_DISABLE=test
endif

include /usr/share/dpkg/default.mk

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

override_dh_clean:
	#These files are rebuilt on-the-fly
	for f in `find -name '*.c'` ; do \
	    head -n 1 "$$f" | grep -q '^/\* Generated by Cython' && rm "$$f" ; \
	done
	rm -rf build build-stamp
	rm -rf doc/_build
	dh_clean

override_dh_auto_build:
	dh_auto_build
ifeq (,$(filter $(DEB_HOST_ARCH), armel mipsel))
	set -x; cd doc; PYTHONPATH=$(CURDIR) http_proxy='127.0.0.1:9' $(MAKE) html
	# remove superfluous files and dirs
	find doc/_build -name "*.doctree*" -delete
	rm -f doc/_build/html/_sources/COGENT_LICENSE.txt
	rm -f doc/_build/html/_static/jquery.js
	rm -f doc/_build/html/_static/underscore.js
	rm -rf doc/_build/html/_images/math/
endif

override_dh_shlibdeps:
	dh_shlibdeps
	dh_numpy3

override_dh_compress:
	dh_compress --exclude=.js --exclude=.fasta --exclude=.txt --exclude=.pdb

override_dh_installdocs:
	dh_installdocs
	rm -rf debian/$(DEB_SOURCE)/usr/share/doc/$(DEB_SOURCE)/html/_sources
	find debian -name doctrees -type d | xargs rm -rf

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3