#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
PYTHON2:=$(shell pyversions -r)
PYTHON3:=$(shell py3versions -r)
py3sdo=set -e; $(foreach py, $(PYTHON3), $(py) $(1);)
pyalldo=set -e; $(foreach py, $(PYTHON2) $(PYTHON3), $(py) $(1);)

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

%:
	dh $@ --with python2,python3

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	$(call pyalldo, setup.py test)
endif

override_dh_auto_build:
	dh_auto_build
	$(call py3sdo, setup.py build)

override_dh_auto_install:
	$(call py3sdo, setup.py install --root=$(CURDIR)/debian/$(DEB_SOURCE) --install-layout=deb)
	cd $(CURDIR)/debian/$(DEB_SOURCE)/usr/bin && mv pyflakes pyflakes3
	dh_auto_install

override_dh_installchangelogs:
	dh_installchangelogs NEWS.txt

override_dh_python2:
	dh_python2 -ppyflakes

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3 -ppyflakes

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build
	rm -rf *.egg-info
