#!/usr/bin/make -f

export DH_VERBOSE = 1

# allow bashism's in commandlines
SHELL = /bin/bash

# Copy needed files into build directory before test are running.
export PYBUILD_BEFORE_TEST=cp tests/cert.pem tests/key.pem tests/sphinx.cfg tests/start-servers.sh {build_dir}; mkdir -p {build_dir}/data; cp tests/data/masterkey {build_dir}/data; mkdir -p data
# And remove files after the test before the data is geting copied into the package.
export PYBUILD_AFTER_TEST=rm {build_dir}/cert.pem {build_dir}/key.pem {build_dir}/sphinx.cfg {build_dir}/start-servers.sh {build_dir}/data/masterkey; rm -rf {build_dir}/data data

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

dh_auto_configure:
	dh_auto_configure --buildsystem=pybuild
	dh_auto_configure --sourcedirectory=contrib

override_dh_auto_test:
	# ignore all errors in tests
	-dh_auto_test

### alternative: If the DEB_BUILD_OPTIONS environment variable contains nocheck, no tests
### will be performed.
###
##override_dh_auto_test:
##	echo "all build time tests skipped"

### disable all tests in tests/test.py, only run the other ones in tests/*.py
##override_dh_auto_test:
##	mv tests/test.py tests/test.py.disabled
##	dh_auto_test
##	mv tests/test.py.disabled tests/test.py

override_dh_auto_install:
	dh_auto_install --buildsystem=pybuild
	$(MAKE) -C contrib DESTDIR=$(CURDIR)/debian/tmp install
	# test hardening: remove possible leftover test stuff
	-rm -rf $(CURDIR)/debian/tmp/usr/lib/python3.1?/dist-packages/{cert.pem,key.pem,sphinx.cfg,start-servers.sh,data}

