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

export PYBUILD_NAME=plip
%:
	dh $@ --buildsystem=pybuild

include /usr/share/dpkg/pkg-info.mk

mandir := $(CURDIR)/debian/$(PYBUILD_NAME)/usr/share/man/man1
HELP2MAN := help2man --no-info --no-discard-stderr --version-string="$(DEB_VERSION)"
PYTHON_DEFAULT_VERSION := $(shell py3versions -d)

override_dh_auto_install:
	dh_auto_install

# Unfortunately, dh_python3's --shebang option doesn't work in this
# case.  We have to rewrite the shebang ourselves.
#
# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1103150 for
# more information.
	find $(CURDIR)/debian/$(PYBUILD_NAME)/usr/bin \
		-executable -type f \
		-exec sed -i 's,^#!python$$,#!/usr/bin/python3,' '{}' ';'

	rm -rvf $(CURDIR)/debian/$(PYBUILD_NAME)/usr/bin/plip
	mv $(CURDIR)/debian/$(PYBUILD_NAME)/usr/bin/plipcmd.py \
           $(CURDIR)/debian/$(PYBUILD_NAME)/usr/bin/plipcmd
	mkdir -p $(mandir)
	export PYTHONPATH=$(CURDIR)/debian/$(PYBUILD_NAME)/usr/lib/$(PYTHON_DEFAULT_VERSION)/dist-packages/:\
	$(CURDIR)/plip/modules; \
    $(HELP2MAN)  --name='Protein-Ligand Interaction Profiler (PLIP)' \
    $(CURDIR)/debian/$(PYBUILD_NAME)/usr/bin/plipcmd > $(mandir)/plipcmd.1

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# skip all other tests since they require exluded pdb files
	export PYTHONPATH=$(CURDIR)/.pybuild/cpython3_$(shell py3versions -dv)_plip/build/; \
	debian/tests/xml-parser
endif
