#!/usr/bin/make -f

%:
	dh $@ --with python2,python3

override_dh_auto_install:

	set -e && for pyvers in $(shell pyversions -vr); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python-spf; \
	done

	set -e && for py3vers in $(shell py3versions -sv); do \
		python$$py3vers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python3-spf; \
	done

	# Make dirs for the tools package (then move scripts from python-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/python-spf/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/python-spf/usr/bin/type99.py	 debian/spf-tools-python/usr/bin/pyspf-type99
	rm -rf $(CURDIR)/debian/python-spf/usr/bin
	# Don't ship python3 specific variants of spf-tools (current scripts work for both)
	rm -rf $(CURDIR)/debian/python3-spf/usr/bin

override_dh_installdocs:

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

override_dh_auto_clean:

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

override_dh_fixperms:
	dh_fixperms
	chmod +x $(CURDIR)/debian/python-spf/usr/lib/python2.?/*-packages/spf.py

override_dh_python3:
	dh_python3 -N spf-tools-python
