#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
PYTHONS:=$(shell pyversions -vr)
PYTHON3S:=$(shell py3versions -vr)

override_dh_auto_build:
	set -e ; set -x ; for i in $(PYTHONs) $(PYTHON3S) ; do \
		PYTHON=python$$i python$$i setup.py build --force ; \
	done
	a2x -d manpage -f manpage man/pethtool.8.asciidoc
	a2x -d manpage -f manpage man/pifconfig.8.asciidoc
	
	# Make python2/3 versions of each file so packages won't conflict
	cp -p man/pethtool.8 man/pethtool2.8
	cp -p man/pethtool.8 man/pethtool3.8
	cp -p man/pifconfig.8 man/pifconfig2.8
	cp -p man/pifconfig.8 man/pifconfig3.8
	cp -p scripts/pethtool scripts/pethtool2
	cp -p scripts/pethtool scripts/pethtool3
	cp -p scripts/pifconfig scripts/pifconfig2
	cp -p scripts/pifconfig scripts/pifconfig3
	sed -i -e 's/python/python3/' scripts/pethtool3
	sed -i -e 's/python/python3/' scripts/pifconfig3

override_dh_auto_install:
	python2.7 setup.py install --install-layout=deb --root $(CURDIR)/debian/python-ethtool
	set -e ; set -x ; for i in $(PYTHON3S) ; do \
		python$$i setup.py install --install-layout=deb --root $(CURDIR)/debian/python3-ethtool ; \
	done
	
	# Remove original scripts, installed by setup.py. We will update-alternatives later
	rm -rf debian/python-ethtool/usr/bin
	rm -rf debian/python3-ethtool/usr/bin

clean:
	if [ -f setup.py ]; then dh $@ --buildsystem python_distutils --with python2,python3; fi
	rm -f \
	  man/pethtool.8 man/pifconfig.8 \
	  man/pethtool2.8 man/pifconfig2.8 \
	  man/pethtool3.8 man/pifconfig3.8 \
	  scripts/pethtool2 scripts/pifconfig2 \
	  scripts/pethtool3 scripts/pifconfig3 \
	  .directory
	rm -rf build ethtool.egg-info
	rm -f .gitignore

%:
	dh $@ --buildsystem python_distutils --with python2,python3
