#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

# DH_VERBOSE := 1
export LC_ALL=C.UTF-8

export PYBUILD_TEST_ARGS = --exclude='(test_requirementobj__version__command_not_executable)'

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

override_dh_auto_test:
	# apply fix that seems to be needed due to improperly set
	# time zone in pbuilder
	sed -i~ 's/"MTime": "2005-07-07 08:50:00"/"MTime": "2005-07-07 06:50:00"/' tests/common_tests/makefile_test.py
	PATH=$(CURDIR)/bin/:$(PATH) dh_auto_test
	mv tests/common_tests/makefile_test.py~ tests/common_tests/makefile_test.py

override_dh_install:
	dh_install
	find debian -name LICENSE -delete

override_dh_fixperms:
	dh_fixperms
	for rs in `find debian -iname "*.r"` ; do \
	    if head -n 1 $$rs | grep -q '^#!/usr/bin/.*Rscript' ; then \
	        chmod +x $$rs ; \
	    else \
	        chmod -x $$rs ; \
	    fi ; \
	done

override_dh_installdocs:
	dh_installdocs
	# since tests dir contains empty files which are used afterwards for
	# testing and dh_installdocs is ignoring empty files we need to make
	# sure all files are really copied
	rsync -a -v tests debian/$(DEB_SOURCE)/usr/share/doc/$(DEB_SOURCE)
	# test runner is seeking for paleomix modules in source - we use inside the installed package
	### sed -i 's:(find paleomix -mindepth 1:(find /usr/lib/python2.7/dist-packages/paleomix -mindepth 1:' debian/*/usr/share/doc/*/tests/run
	#echo "======  Also empty files belong to the docs ======"
	#find debian -name "empty_file*"
	#find debian -name "timestamp_*"
	#echo "======  Hope something was printed between these lines ===="
