#! /usr/bin/make -f
%:
	dh $@ --with python2,python3

# Keep pristine copies of some files that setup.py likes to modify.
BACKUP = \
	PKG-INFO \
	src/tblib.egg-info/PKG-INFO \
	src/tblib.egg-info/SOURCES.txt

override_dh_auto_build:
	mkdir -p debian/backup
	set -e; for x in $(BACKUP); do \
		mkdir -p debian/backup/$$(dirname $$x); \
		cp -a $$x debian/backup/$$x; \
	done
	dh_auto_build
	set -e; for python in $$(py3versions -r); do \
		$$python setup.py build; \
	done

override_dh_auto_test:
	HOME=$(CURDIR) tox -e py,py3

override_dh_auto_clean:
	dh_auto_clean
	find -name \*.pyc -print0 | xargs -0r rm -f
	find -name __pycache__ -print0 | xargs -0r rm -rf
	rm -rf build .tox
	if [ -e debian/backup ]; then \
		set -e; for x in $(BACKUP); do \
			cp -a debian/backup/$$x $$x; \
		done; \
		rm -rf debian/backup; \
	fi

override_dh_auto_install:
	dh_auto_install
	set -e; for python in $$(py3versions -r); do \
		$$python setup.py install --root=$(CURDIR)/debian/tmp \
			--no-compile -O0 --install-layout=deb; \
	done
