#!/usr/bin/make -f
export DH_VERBOSE = 1

export PYBUILD_NAME=pychopper
export PYBUILD_BEFORE_TEST=cp -av $(CURDIR)/pychopper/tests/ {build_dir}/pychopper/
DEF_PY=$(shell py3versions -d)
DEF_BUILDDIR3 := $(shell pybuild --print build_dir --interpreter python3)

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


override_dh_auto_build:
	dh_auto_build
	cd docs && PYTHONPATH=.. make man

execute_after_dh_auto_build:
	for py in `py3versions -s`; do \
		builddir=$$(pybuild --print build_dir --interpreter $$py); \
		mv $$builddir/pychopper/scripts/pychopper.py $$builddir/pychopper/scripts/pychopper; \
	done

override_dh_auto_clean:
	dh_auto_clean
	make clean
	cd docs && make clean # fails

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test -- --system=custom --test-args="export PATH=$(DEF_BUILDDIR3)/pychopper/scripts:$$PATH; \
	chmod +x $(DEF_BUILDDIR3)/pychopper/scripts/pychopper; PYTHONPATH={build_dir} {interpreter} -m pytest -v"
	set -e; \
	for py in `py3versions -sv`; do \
	rm -rf ".pybuild/cpython3_$${py}_$(PYBUILD_NAME)/pychopper/tests/"; \
	done
endif

execute_after_dh_auto_install:
	find debian/ -name .gitignore -delete

override_dh_fixperms:
	dh_fixperms
	find debian/ -name PCS111_primers.fas -exec chmod -x '{}' \;
