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

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

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

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=`pwd` $(MAKE) -C doc/en man html
	cp doc/en/_build/man/pytest.1 debian/py.test.1
	cp debian/py.test.1 debian/py.test-3.1
	sed -i 's/PYTEST/PY.TEST/g' debian/py.test.1
	sed -i 's/PYTEST/PY.TEST-3/g' debian/py.test-3.1
	sed -i 's/py\.test/py.test-3/g' debian/py.test-3.1

# 2015-12-16 barry@debian.org: Because pytest does not clean up after itself,
# use a custom temporary directory (which is easier to clean up manually,
# e.g. in an sbuild).
override_dh_auto_test:
	TMPDIR=`mktemp -t -d pytest.XXXXXXXXXX` \
	PYBUILD_SYSTEM=custom \
	PYBUILD_TEST_ARGS="cd $$TMPDIR && {interpreter} -m pytest --lsof -rfsxX --ignore={dir}/testing/cx_freeze {dir}/testing" dh_auto_test

override_dh_auto_install:
	dh_auto_install
	mv debian/python3-pytest/usr/bin/py.test \
	   debian/python3-pytest/usr/bin/py.test-3

override_dh_auto_clean:
	rm -rf doc/en/_build
	rm -f debian/py.test.1 debian/py.test-3.1
	rm -rf pytest.egg-info .cache
	dh_auto_clean
