#!/usr/bin/make -f

export DH_VERBOSE=1

export PYBUILD_TEST_CUSTOM := 1
export PYBUILD_TEST_ARGS := cd test && {interpreter} testspf.py

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_install:
	# Make dirs for the tools package (then move scripts from python3-spf)
	mkdir -p debian/spf-tools-python/usr/bin/
	# Rename the `spfquery` tool for the alternatives system
	# (omitting the ".py" language extension):
	mv $(CURDIR)/debian/tmp/usr/bin//spfquery.py debian/spf-tools-python/usr/bin/spfquery.pyspf
	# Give the `type99` tool a more specific name
	# (omitting the ".py" language extension):
	mv $(CURDIR)/debian/tmp/usr/bin//type99.py	 debian/spf-tools-python/usr/bin/pyspf-type99
	rm -rf $(CURDIR)/debian/tmp/usr/bin

override_dh_installdocs:
	cp $(CURDIR)/CHANGELOG $(CURDIR)/changelog
	dh_installdocs
	rm $(CURDIR)/changelog

override_dh_auto_clean:
	set -e && for py3vers in $(shell py3versions -sv); do \
	        python$$py3vers setup.py clean -a; \
	done
	find . -name \*.pyc -exec rm {} \;

execute_after_dh_fixperms:
	chmod +x $(CURDIR)/debian/python3-spf/usr/lib/python3*/dist-packages/spf.py

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