#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-

PYTHON2=$(shell pyversions -r)
PYTHON3=$(shell py3versions -r)

%:
	dh $@ --with python2,python3

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build/

override_dh_auto_install:
	set -ex; for python in $(PYTHON3); do \
		$$python setup.py install --install-layout=deb --root=debian/tmp; \
	done
	dh_auto_install

override_dh_auto_build:
	set -ex; for python in $(PYTHON3); do \
		$$python setup.py build; \
	done
	dh_auto_build

ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	set -ex; for python in $(PYTHON2); do \
		$$python run-tests.py; \
	done
	cp -a tests build/lib/tests
	2to3 -w --no-diffs build/lib/tests
	set -ex; for pyversion in $(shell py3versions -vr); do \
		nosetests-$$pyversion -w $(CURDIR)/build/lib/tests; \
	done
	rm -r build/lib/test*
	dh_auto_test
endif

override_dh_compress:
	dh_compress -X.txt

.PHONY: override_dh_auto_clean override_dh_auto_install override_dh_auto_test \
override_dh_compress
