#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PYVERS  := $(shell pyversions -d)
PY3VERS  := $(shell py3versions -d)
BLDPATH := build2/lib.$(shell dpkg-architecture -qDEB_HOST_ARCH_OS)-$(shell dpkg-architecture -qDEB_HOST_GNU_CPU)-2.7

%:
	dh $@ --with python2,python3,quilt


override_dh_auto_build:
	$(PYVERS) setup.py build --build-base=build2
	set -e && for py in $(shell py3versions -vr); do \
		python$$py setup.py build --build-base=build$$py; \
	done

override_dh_auto_test:
	PYTHONPATH=$(BLDPATH) $(PYVERS) -m pystache.commands.test
	set -e && for py in $(shell py3versions -vr); do \
		python$$py -c "import os,sys;sys.path.insert(0, os.path.abspath('build$$py/lib')); import pystache.commands.test as t; t.main()"; \
	done

override_dh_auto_install:
	$(PYVERS) setup.py install --no-compile -O0 --install-layout=deb \
	--root $(CURDIR)/debian/python-pystache
	$(PY3VERS) setup.py install --no-compile -O0 --install-layout=deb \
	--root $(CURDIR)/debian/python3-pystache

override_dh_python2:
	dh_python2
	rm -f $(CURDIR)/debian/python-pystache/usr/bin/pystache-test
	rm -rf $(CURDIR)/debian/python-pystache/usr/share/pyshared/pystache/tests
	rm -rf $(CURDIR)/debian/python-pystache/usr/lib/$(PYVERS)/dist-packages/pystache/tests

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
	mv -f $(CURDIR)/debian/python3-pystache/usr/bin/pystache $(CURDIR)/debian/python3-pystache/usr/bin/pystache3
	rm -rf $(CURDIR)/debian/python3-pystache/usr/bin/pystache-test
	rm -rf $(CURDIR)/debian/python3-pystache/usr/share/pyshared/pystache/tests
	rm -rf $(CURDIR)/debian/python3-pystache/usr/lib/python3/dist-packages/pystache/tests/

override_dh_auto_clean:
	$(PYVERS) setup.py clean --build-temp=build
	$(PYVERS) setup.py clean --build-temp=build2
	set -e && for py in $(shell py3versions -vr); do \
		python$$py setup.py clean --build-temp=build$$py; \
	done
	dh_clean
	find $(CURDIR) -name "*.pyc" -delete

