#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PERL_ARCHLIB := $(shell perl -MConfig -e 'print $$Config{vendorarch}')

%:
	dh $@ --with python2

override_dh_auto_configure:
	dh_auto_configure -Dperl
	dh_auto_configure -Dpython

override_dh_auto_build:
	dh_auto_build -Dperl
	dh_auto_build -Dpython

override_dh_auto_install:
	dh_auto_install -Dperl
	dh_auto_install -Dpython

override_dh_install:
	dh_install -plibbuffy-perl $(PERL_ARCHLIB)
	dh_install -ppython-buffy

override_dh_auto_clean:
	dh_auto_clean -Dperl
	dh_auto_clean -Dpython
	dh_auto_clean
	rm -f python/buffy_wrap.cpp python/Buffy.py

# Thanks Stefano Rivera for the python test example
override_dh_auto_test:
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	cd tests && ./test.pl

	set -e; cd tests; \
	for ver in $(shell pyversions -vr); do \
		PYTHONPATH=$$(ls -d $$(readlink -f ../python/build/lib.*-$$ver)) \
			python$$ver test.py; \
	done
endif

# Personal convenience rules
vercheck:
	debian/vercheck > /dev/null

debsrc: vercheck
	git-buildpackage -S -us -uc
