#!/usr/bin/make -f

DH_VERBOSE := 1

include /usr/share/dpkg/default.mk

%:
	dh $@

override_dh_auto_clean:
	cd ./sample_data && for script in ./*/cleanme.pl; do $$($$script); done
	rm -f debian/*.1

override_dh_auto_build:

override_after_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	cd ./sample_data && for script in ./*/cleanme.pl; do $$($$script); done
endif

execute_after_dh_install:
	find debian/transdecoder -name '*.p?' | xargs sed -i \
                's=^#!/usr/local/bin/perl=#!/usr/bin/perl='
	find debian/transdecoder -name '*.p?' | xargs sed -i \
                's=^#!/usr/bin/env perl=#!/usr/bin/perl='
	find debian/*/usr/lib/transdecoder -type d -empty -delete
	find debian/transdecoder/usr/lib/transdecoder/PerlLib/ -name "*.pm" \
		| xargs chmod a-x

execute_before_dh_installman:
	help2man --no-info --version-string=${DEB_VERSION_UPSTREAM} \
		--name "full pipeline wrapper" \
		debian/transdecoder/usr/lib/transdecoder/TransDecoder > debian/TransDecoder.1
	help2man --no-info --version-string=${DEB_VERSION_UPSTREAM} \
		--help-option=-h --no-discard-stderr --name "extract long ORFs" \
		debian/transdecoder/usr/lib/transdecoder/util/TransDecoder.LongOrfs > debian/TransDecoder.LongOrfs.1
	help2man --no-info --version-string=${DEB_VERSION_UPSTREAM} \
		--help-option=-h --no-discard-stderr --name "predicts the likely coding regions among the ORFs" \
		debian/transdecoder/usr/lib/transdecoder/util/TransDecoder.Predict > debian/TransDecoder.Predict.1

override_after_dh_fixperms:

override_after_dh_installdocs:
	for pl in `grep -Rl '#![[:space:]]*/usr/bin/env[[:space:]]\+perl' debian/*/usr/*` ; do \
	    sed -i '1s?^#![[:space:]]*/usr/bin/env[[:space:]]\+perl?#!/usr/bin/perl?' $${pl} ; \
	done
