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

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

# For SOURCE_DATE_EPOCH
include /usr/share/dpkg/pkg-info.mk

BUILD_DATE = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "@$(SOURCE_DATE_EPOCH)")

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

# Override needed for docs and egg-info
override_dh_auto_clean:
	dh_auto_clean
	rm -rf Pyevolve.egg-info
	rm -rf docs/html

# Override needed for building documentation; jquery link
override_dh_auto_build:
	dh_auto_build
	cd docs && sphinx-build -E -a -b html -D today="$(BUILD_DATE)" ./source ./html

# Run the autopkgtest as unit test
override_dh_auto_test:
	# Simulate partial autopkgtest run by providing an AUTOPKGTEST_TMP and
	# letting pybuild drive the test
	testrundir=$$(mktemp -d) ;\
		AUTOPKGTEST_TMP=$$testrundir \
		PYBUILD_SYSTEM=custom \
		PYBUILD_TEST_ARGS="/bin/sh $(CURDIR)/debian/tests/run-most-examples" \
	dh_auto_test ;\
	res=$$? ;\
	rm -rf "$$testrundir" ;\
	[ $$res -eq 0 ] || exit $$res

# Override needed for multiple binary package;
# script must be renamed, line endings converted to Unix
override_dh_auto_install:
	dh_auto_install --destdir=debian/python-pyevolve
	tr -d '\r' < debian/python-pyevolve/usr/bin/pyevolve_graph.py \
	           > debian/python-pyevolve/usr/bin/pyevolve-graph
	rm -f debian/python-pyevolve/usr/bin/pyevolve_graph.py
