#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this line to make output verbose
#export DH_VERBOSE=1

PYVERS=$(shell pyversions -vr)
#PKGDIR=$(CURDIR)/debian/python-gpgme

#clean:
	# Enforce removal of *.pyc files. Apparently dh_clean does
	# not perform find on provided filename patterns.
#	rm -rf build/
#	find . -name *.pyc -exec rm -f {} \;
#	find . -name *.so -exec rm -f {} \;
#	dh_clean install-stamp build-stamp \
#		$(PYVERS:%=install-python%) $(PYVERS:%=build-python%) \
#		$(PYVERS:%=install-debug-python%) $(PYVERS:%=build-debug-python%)

override_dh_auto_clean:
	./setup.py clean
	dh_clean

override_dh_auto_test:
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	set -e -x;\
	for py in $(PYVERS); do \
		PYTHON=python$$py PYTHONPATH=$(CURDIR)/build/lib.*-$$py GPG_AGENT_INFO= make check ;\
		PYTHON=python$$py PYTHONPATH=$(CURDIR)/build/lib.*-$$py-pydebug GPG_AGENT_INFO= make check ;\
	done
endif

override_dh_install:
	# Install everything excluding the *_d.so debug extensions to python-gpgme
	dh_install -X"*_d.so" "debian/tmp/*" -p python-gpgme
	# Install the debug extensions to python-gpgme-dbg
	dh_install "debian/tmp/usr/lib/python*/*-packages/gpgme/*_d.so" -p python-gpgme-dbg
	# Continue with regular dh_install
	dh_install

override_dh_strip:
ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	# Stripped symbols go into python-gpgme-dbg
	dh_strip --dbg-package=python-gpgme-dbg
endif

get-orig-source:
	REV=$(shell dpkg-parsechangelog | sed -rne 's,^Version: .*bzr([0-9]{4})([0-9]{2})([0-9]{2}).*,\1-\2-\3,p'); \
	VER=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p'); \
	bzr export --root=pygpgme-$$VER -r date:$$REV ../pygpgme_$$VER.orig.tar.gz lp:pygpgme

%:
	dh $@ --with python2 -Spython_distutils

