#!/usr/bin/make -f

PY3VERS := $(shell py3versions -r)

DEB_VERSION := $(shell dpkg-parsechangelog --show-field=Version)

%:
	dh $@ --with=python3

override_dh_auto_install:
	dh_auto_install
	set -ex; for python in $(PY3VERS); do \
		$$python setup.py build --executable=/usr/bin/python && \
		$$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
	done
	chmod 755 $(CURDIR)/debian/tmp/usr/lib/curtin/helpers/*
	for f in $$(find $(CURDIR)/debian/tmp/usr/lib -type f -name version.py); do [ -f "$$f" ] || continue; sed -i 's,@@PACKAGED_VERSION@@,$(DEB_VERSION),' "$$f"; done

override_dh_auto_test:
	make unittest3

override_dh_clean:
	dh_clean
	find . -name __pycache__ -exec rm -rf {} +
