#!/usr/bin/make -f

export PYBUILD_NAME=MACS2
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

include /usr/share/dpkg/default.mk

subcommands=callpeak bdgpeakcall bdgbroadcall bdgcmp bdgopt cmbreps bdgdiff \
	      filterdup predictd pileup randsample refinepeak
tagline=\- Model\-based Analysis for ChIP\-Sequencing
# DH_VERBOSE := 1

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

override_dh_auto_build:
	#for pyx in `find MACS2/ -name "*.pyx" | grep -v khash`; do \
	#	rm -f $${pyx%%.pyx}.{h,c}; touch $${pyx}; done
	dh_auto_build
	PYTHONPATH=./.pybuild/pythonX.Y_*/build/ help2man \
		--no-discard-stderr --no-info \
		--name "macs2 ${tagline}" "python3 bin/macs2" > debian/macs2.1
	for subcommand in ${subcommands}; do printf \
		"[NAME]\nmacs2_$${subcommand} ${tagline}\n" \
		> debian/macs2_$${subcommand}-man-include; done
	for subcommand in ${subcommands}; do \
		PYTHONPATH=./.pybuild/pythonX.Y_*/build/ help2man \
		--no-discard-stderr --no-info --version-string="$(DEB_VERSION_UPSTREAM)" \
		--include debian/macs2_$${subcommand}-man-include \
		"python3 bin/macs2 $${subcommand}" > \
		debian/macs2_$${subcommand}.1; done

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/*.1 debian/*-man-include
