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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export PYBUILD_NAME=epr
export DEB_BUILD_MAINT_OPTIONS=hardening=+all


include /usr/share/dpkg/pkg-info.mk
BUILD_DATE="$(date --utc --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y-%m-%d)"
SPHINXOPTS := -D today=\"$(BUILD_DATE)\"
SPHINXOPTS += -D html_last_updated_fmt=\"$(BUILD_DATE)\"


# Get the supported Python versions
#PY2VERS=$(shell pyversions -vr)
#PY3VERS=$(shell py3versions -vr)


ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
export CFLAGS ?= -O0
endif


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


override_dh_gencontrol:
	dh_numpy
	dh_numpy3
	dh_gencontrol


override_dh_auto_clean:
	dh_auto_clean
	$(RM) src/epr.c
	$(RM) -r doc/_build doc/html
	$(RM) -r build
	$(RM) -r *.egg-info


# suppress dh_auto_test since it requires a large download
override_dh_auto_test:
#ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
#	set -e -x;\
#	for py in $(PY2VERS); do \
#		PYTHONPATH=$(CURDIR)/build/lib.*-$$py python$$py test/test_all.py ;\
#		PYTHONPATH=$(CURDIR)/build/lib.*-$$py-pydebug python$$py-dbg test/test_all.py ;\
#	for py in $(PY3VERS); do \
#		PYTHONPATH=$(CURDIR)/build/lib.*-$$py python$$py test/test_all.py ;\
#		PYTHONPATH=$(CURDIR)/build/lib.*-$$py-pydebug python$$py-dbg test/test_all.py ;\
#	done
#endif


override_dh_strip:
	dh_strip -ppython-epr  --dbg-package=python-epr-dbg
	dh_strip -ppython3-epr --dbg-package=python3-epr-dbg


override_dh_installchangelogs:
	dh_installchangelogs -k doc/NEWS.txt


override_dh_compress:
	dh_compress -X.txt -X.html -X.py


override_dh_sphinxdoc:
ifneq "$(shell dh_listpackages | grep -- -doc)" ""
	dh_sphinxdoc
endif


override_dh_installdocs:
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C doc html SPHINXOPTS="$(SPHINXOPTS)"
else
	mkdir -p doc/html
endif
	dh_installdocs -ppython-epr-doc --doc-main-package=python-epr
	dh_installdocs --remaining-packages


override_dh_installexamples:
	dh_installexamples -ppython-epr-doc --doc-main-package=python-epr
	dh_installexamples --remaining-packages


.PHONY: override_dh_gencontrol override_dh_auto_clean override_dh_auto_test \
        override_dh_strip override_dh_installchangelogs override_dh_compress \
        override_dh_sphinxdoc override_dh_installdocs override_dh_installexamples

