#!/usr/bin/make -f

#export DH_VERBOSE=1
PYTHON3=$(shell py3versions -sv)

# Prevent setuptools/distribute from accessing the internet.
export http_proxy = http://127.0.9.1:9
export https_proxy = https://127.0.9.1:9


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

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
test-python%:
	nodot=$(shell echo $* | cut --complement -b 2); \
	PYTHONPATH=`pwd`:$$PYTHONPATH DEB_SKIP_TOX_TESTS=1 \
	python$* -mtox --sitepackages -e py$${nodot}

override_dh_auto_test: $(PYTHON3:%=test-python%)
endif

# pybuild can't yet handle Python 3 packages that don't start with "python3-".
# See bug #751908 - In the meantime, this override isn't perfect, but it gets
# close enough.
override_dh_auto_install:
	dh_auto_install
	mv debian/python-tox/usr/lib/python3.? \
	   debian/python-tox/usr/lib/python3
	find debian/python-tox -name __pycache__ | xargs rm -rf

override_dh_installdocs:
	python3 setup.py build_sphinx
	dh_installdocs build/sphinx/html

override_dh_installman:
	(cd debian/manpage; \
	 sphinx-build -b man -d _build/doctrees . _build/man)
	dh_installman debian/manpage/_build/man/tox.1

override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build
	rm -rf *.egg-info
	rm -rf .tox
	rm -rf debian/manpage/_build
