#!/usr/bin/make -f
#export DH_VERBOSE=1
export PYBUILD_NAME=pies

PIES2OVERRIDES_PKG=debian/python-pies2overrides

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

override_dh_auto_build:
	dh_auto_build -O--buildsystem=pybuild

override_dh_auto_install:
	dh_auto_install -O--buildsystem=pybuild
	# remove rampant egg PKG-INFO
	rm -rf debian/python3-pies/usr/lib/python3.4/dist-packages/pies-*.egg-info/PKG-INFO
	# manual install of pies2overrides because dh_python2 can't handle two
	# packages, and pyinstall can't install to empty namespace
	$(foreach dir,html http xmlrpc,$(shell mkdir -p $(PIES2OVERRIDES_PKG)/usr/share/pyshared/$(dir)))
	for file in $$(tail -n+2 pies2overrides/MANIFEST | grep -v setup.py); do \
		cp pies2overrides/$$file \
			$(PIES2OVERRIDES_PKG)/usr/share/pyshared/$$file; \
		dh_link -ppython-pies2overrides \
			usr/share/pyshared/$$file \
			usr/lib/python2.7/dist-packages/$$file; \
	done
