#!/usr/bin/make -f
# debian/rules for murasaki
# Copyright 2015 Andreas Tille
# GPL

DEBPKGNAME	:= $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')
DEBMEDBIN	:= debian/$(DEBPKGNAME)-common/usr/lib/debian-med/bin
MANDIR		:= debian/$(DEBPKGNAME)/usr/share/man/man1
CMANDIR		:= debian/$(DEBPKGNAME)-common/usr/share/man/man1
MMANDIR		:= debian/$(DEBPKGNAME)-mpi/usr/share/man/man1

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- USE_MPI=YES
	for bin in geneparse mbfa murasaki cgr-* testeco align-* ; do \
	    mv $${bin} $${bin}-mpi ; \
	done
	make clean
	dh_auto_build -- USE_MPI=NO

override_dh_installman-indep:
	dh_installman -i
	# create manpages for PL files
	mkdir -p $(CMANDIR)
	for pscript in $(DEBMEDBIN)/* ; do \
	    pod2man $${pscript} > $(CMANDIR)/`basename $${pscript}`.1 ; \
	done
	find $(CMANDIR) -empty -delete

override_dh_link:
	dh_link
	mkdir -p $(MMANDIR)
	for man in $(MANDIR)/* ; do \
	    ln -s `basename $${man}`.gz $(MMANDIR)/`basename $${man} .1`-mpi.1.gz ; \
	done

override_dh_install-arch:
	dh_install -a
	# using wildcards in install files is practical but it duplicates some files
	find debian/$(DEBPKGNAME)/usr -name "*-mpi" -delete

override_dh_fixperms-indep:
	dh_fixperms -i
	chmod a+x debian/$(DEBPKGNAME)-common/usr/share/perl5/murasaki/config.pl
