#!/usr/bin/make -f

DH_VERBOSE := 1

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export PYBUILD_NAME=pybedtools
export MATPLOTLIBRC=$(CURDIR)/debian/

export PYBUILD_BEFORE_TEST=

ifneq ($(PYBUILD_AUTOPKGTEST), 1)
PYBUILD_BEFORE_TEST= cp {dir}/debian/mpl-expected.png {build_dir}/pybedtools/test/ ;
endif

PYBUILD_BEFORE_TEST+= \
	python3 {dir}/setup.py install --user ; \
	export HOME=$(CURDIR)/fakehome

export PYBUILD_TEST_ARGS=-k "not test_chromsizes"
ifeq ($(PYBUILD_AUTOPKGTEST), 1)
PYBUILD_TEST_ARGS+={dir}/pybedtools/test/
endif

export PYBUILD_AFTER_TEST=cd {dir}/docs ; make clean doctest

export HOME=$(CURDIR)/fakehome
export PATH:=$(PATH):$(HOME)/.local/bin

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

override_dh_auto_build:
	python3 setup.py cythonize
	dh_auto_build
	python3 setup.py develop --user
	sphinx-build -N -b html docs/source docs/html

override_dh_install:
	dh_install
	rm -f debian/python3-pybedtools/usr/lib/python3*/dist-packages/pybedtools/test/prevent_open_file_regression \
	      debian/python3-pybedtools/usr/lib/python3*/dist-packages/foo.bed \
	      debian/python3-pybedtools/usr/lib/python3*/dist-packages/genome.txt

override_dh_auto_clean:
	/bin/rm -rf fakehome .eggs .pybuild .pytest_cache
	/bin/rm -rf debian/python3-pybedtools debian/files
	/bin/rm -rf pybedtools.egg-info
	/bin/rm -rf pybedtools/scripts/__pycache__/
	/bin/rm -rf pybedtools/contrib/__pycache__/
	/bin/rm -rf pybedtools/__pycache__/
	find pybedtools -name "*.so" -o -name "*.o" | xargs -r rm
	rm -rf build
	rm -rf docs/build docs/*.bed docs/*.genome
	rm -rf dist
	/bin/rm -rf pybedtools/cbedtools.cpp pybedtools/featurefuncs.cpp
	find docs/source/autodocs/ -name "*.rst" | xargs -r /bin/rm
	# dh_auto_clean
