#!/usr/bin/make -f

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

LIB := $$(python -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print b.build_platlib")

%:
	dh $@ --with python2

override_dh_clean:
	dh_clean
	$(RM) -r build
	$(RM) -rf mysql/connector/
	find scripts -mindepth 1 -regex '[^.]*' -delete -printf 'removing %p\n'

TESTS=$(wildcard unit_tests/test*.py)
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Link mysql.connector directory in the build dir, as they share the same ns
	# we cd to / as otherwise we pick the local mysql/ dir
	ln -s $$(dirname $$(cd / ; python -c "import mysql.connector as p; print p.__file__" ; cd $(CURDIR))) $(CURDIR)/$(LIB)/mysql
	set -e \
	;for python in $(shell pyversions -r); do \
	    for test in $(TESTS); do \
	        echo -e "\n### $$python::$$test" ;\
	        PYTHONPATH="$(CURDIR)/$(LIB)" $$python $$test ;\
	    done \
	;done
	rm $(CURDIR)/$(LIB)/mysql/connector
endif

override_dh_installdocs:
	dh_installdocs README*

override_dh_python2:
	dh_python2 --no-guessing-deps
