#!/usr/bin/make -f

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

%:
	dh $@ --with python2,python3

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build

build-python%:
	python$* setup.py build --with-cython

override_dh_auto_build: $(PYTHON3:%=build-python%)
	dh_auto_build

install-python%:
	python$* setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb

override_dh_auto_install: $(PYTHON3:%=install-python%)
	dh_auto_install

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
# do not run test suite on sparc since liblo has problems with 64 bit integers
# on sparc (see #721617)
ifeq (,$(filter sparc,$(DEB_HOST_ARCH)))
pythonpath = $$(ls -d $(CURDIR)/build/lib.*-$(1))

test-python%:
	PYTHONPATH=$(call pythonpath,$*) \
		python$* -m unittest discover -s test/ -p '*.py' -v

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

override_dh_installchangelogs:
	dh_installchangelogs NEWS
