#!/usr/bin/make -f

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

LIBWEBP=$(shell python -c 'from ctypes.util import find_library; print find_library("webp")')
LIBWEBP_PKG=$(shell dpkg-query --search $(LIBWEBP) | head -1 | sed 's/:.*//')
#LIBWEBP_VER=$(shell dpkg-query --show $(LIBWEBP_PKG) | awk 'sub(/\-.*/,""){print $$2}')

%:
	dh $@ --with python2

override_dh_auto_build: webm/__init__.py
	dh_auto_build

webm/__init__.py: webm/__init__.py.in
	$(info I: $(LIBWEBP_PKG): $(LIBWEBP))
	perl -0p -E 's{libwebp.so.0}{$(LIBWEBP)}sg or die q{susbstitution failed};' webm/__init__.py.in >$@

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# custom tests
	set -e \
	;for python in $(shell pyversions -r); do \
	    for test in $(wildcard ./webm/tests/*_tests.py); do \
	        PYTHONPATH=".:$(PYTHONPATH)" \
	        $$python $${test} \
	    ;done \
	;done
	# all tests
	nosetests -s -x -v
endif

override_dh_gencontrol:
	dh_gencontrol -v -- -Vmy:Depends="$(LIBWEBP_PKG)"

override_dh_builddeb:
	dh_builddeb -- -Zxz
