#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

# DH_VERBOSE := 1

# README.rst is parsed in test
export PYBUILD_BEFORE_TEST=cp -a README.rst {build_dir};

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	PATH=$(CURDIR)/bin/:$(PATH) dh_auto_test
endif

override_dh_install:
	dh_install
	find debian -name LICENSE -delete
	find debian -name README.rst -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/python*/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 ===="
	#
	# This test tries to execute setup.sh which does not work outside source directory
	find debian/$(DEB_SOURCE)/usr/share/doc/ -name fileutils_test.py -delete
	find debian/$(DEB_SOURCE)/usr/share/doc/ -name setup.h -delete

override_dh_python3:
	dh_python3 --verbose --shebang=/usr/bin/python3
