#!/usr/bin/make -f

PYTHONS:=$(shell pyversions -vr)
PYTHON3S:=$(shell py3versions -vr)

%:
	dh $@ --with python2,python3

override_dh_auto_build:
	set -e && for pyvers in $(PYTHONS); do \
		python$$pyvers setup.py build; \
	done
	set -e && for pyvers in $(PYTHON3S); do \
		python$$pyvers setup.py build; \
	done
	$(MAKE) docs

override_dh_auto_install:
	set -e && for pyvers in $(PYTHONS); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python-testtools; \
	done
	set -e && for pyvers in $(PYTHON3S); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python3-testtools; \
	done
	# Remove 2x compat file as it causes errors during byte compilation on installation.
	echo 'raise SyntaxError' > \
		$(CURDIR)/debian/python3-testtools/usr/lib/python3/dist-packages/testtools/_compat2x.py

ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	$(MAKE) -C $(CURDIR) check
endif
