#!/usr/bin/make -f

export PYBUILD_NAME=tftp
BUILDHOME = $(CURDIR)/debian/build
PYVERS := $(shell pyversions -r)
PY3VERS := $(shell py3versions -r)

%:
	dh $@ --with python2,python3 --buildsystem=pybuild

override_dh_auto_install:
	dh_auto_install
	set -ex; for python in $(PYVERS); do \
		$$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
		dh_install twisted/plugins/tftp_plugin.py usr/lib/$$python/dist-packages/twisted/plugins -ppython-txtftp; \
	done
	set -ex; for python in $(PY3VERS); do \
		$$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
		dh_install twisted/plugins/tftp_plugin.py usr/lib/python3/dist-packages/twisted/plugins -ppython3-txtftp; \
	done

override_dh_auto_build:
	# Do nothing here cause build process installs things
	# from the internet.

override_dh_clean:
	dh_clean
	rm -rf $(BUILDHOME)

override_dh_auto_test:
	mkdir -p $(BUILDHOME)
	HOME=$(BUILDHOME) PYTHONPATH=$PWD trial -B tftp


DEB_DEBIAN_DIR=$(dir $(firstword $(MAKEFILE_LIST)))
REV=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
              | sed -rne 's,^Version: .*[+~]bzr([0-9]+).*,\1,p')
VER=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
              | sed -rne 's,^Version: ([^-]+).*,\1,p')
get-orig-source:
	bzr export -r $(REV) --root=python-tx-tftp-$(VER) \
             python-tx-tftp_$(VER).orig.tar.gz lp:python-tx-tftp
