#!/usr/bin/make -f

#DH_VERBOSE = 1

export LC_ALL=C.UTF-8

include /usr/share/dpkg/default.mk

export PYBUILD_NAME := $(DEB_SOURCE)
BINDIR=$(CURDIR)/debian/$(DEB_SOURCE)/usr/bin/
MANDIR=$(CURDIR)/debian/$(DEB_SOURCE)/usr/share/man/

manpages = \
pbgff.5.md \
variantCaller.1.md \

%: %.md
	pandoc -s --to man $< -o $@


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

override_dh_auto_test:
	chmod +x bin/gffToBed
	PYTHONPATH=$(CURDIR) PATH=$(CURDIR)/bin:$$PATH $(MAKE) tests
	chmod -x bin/gffToBed

override_dh_auto_build: docs
	dh_auto_build

.PHONY: docs
docs: $(addprefix $(CURDIR)/debian/man/, $(manpages:.md=))

.PHONY: clean-docs
clean-docs:
	$(RM) $(addprefix $(CURDIR)/debian/man/, $(manpages:.md=))

override_dh_install:
	dh_install
# Place executable programs in the main package
	mkdir -p $(BINDIR)
	mv debian/python-$(DEB_SOURCE)/usr/bin/* $(BINDIR)
# Remove convenience script for poa; it conflicts with the poa package
# See #831220
	$(RM) $(BINDIR)/poa

override_dh_auto_clean: clean-docs
	dh_auto_clean

# Helper for setting up the documentation as manpages
# Usage: VPATH=doc/ debian/rules prepare-doc
prepare-doc: $(manpages)

pbgff.5.md: VariantsGffSpecification.rst
variantCaller.1.md: VariantCallerFunctionalSpecification.rst

$(manpages):
	pandoc -s $< -o $@
