#!/usr/bin/make -f

# Get the supported Python versions
PYVERS = $(shell py3versions -vr) $(shell pyversions -vr)

export INSTALLDIRS=vendor

%:
	dh "$@" --with python2,python3,autoreconf

override_dh_auto_configure:
	for v in $(PYVERS); do env PYTHON=python$$v dh_auto_configure -B build-$$v; done

override_dh_auto_build:
	for v in $(PYVERS); do dh_auto_build -B build-$$v; done

override_dh_auto_test:
	for v in $(PYVERS); do dh_auto_test -B build-$$v; done

override_dh_auto_clean:
	for v in $(PYVERS); do rm -rf build-$$v; done
	find -name "*.pyc" | xargs rm -f
	find -name "__pycache__" | xargs rm -rf

override_dh_auto_install:
	for v in $(PYVERS); do $(MAKE) -C build-$$v install DESTDIR=$(CURDIR)/debian/tmp; done
	for v in $(PYVERS); do python$$v setup.py install --install-layout=deb --single-version-externally-managed --root=$(CURDIR)/debian/tmp; done
	find debian/tmp/ -name "*.pyc" | xargs rm -f
	find debian/tmp/ -name "__pycache__" | xargs rm -rf

# for some readon dh_python3 is not called?
override_dh_python2:
	dh_python2
	dh_python3 --no-package=subunit --shebang=/usr/bin/python3
