#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# lkajan: work in progress, enable this in next upstream release, after speaking to upstream
# tille@d.o: If enabled only ffindex_apply_mpi and for creating the manpage another (not yet
#            known) Build-Depends is needed.

pkgdata:=ffindex
sampledir:=$(CURDIR)/debian/$(pkgdata)/usr/share/doc/$(pkgdata)/examples

export HAVE_MPI:=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

FFMANPAGES = ffindex_apply.1 ffindex_build.1 ffindex_from_fasta.1 ffindex_get.1 ffindex_modify.1 ffindex_unpack.1 ffindex_apply_mpi.1 ffindex_from_tsv.1
ffmanpages: $(FFMANPAGES)
BINNAMES =	\
		ffindex_apply="apply a program to each FFindex entry";\
		ffindex_build="build file index from files in directories";\
		ffindex_from_fasta="populate index from FASTA file";\
		ffindex_get="retrieve entries from file index";\
		ffindex_modify="modify file index entries";\
		ffindex_unpack="unpack file index entries";\
		ffindex_apply_mpi="apply a program to each FFindex entry (mpi enhanced)";\
		ffindex_from_tsv="populate index from TSV file";

override_dh_installman: $(FFMANPAGES)
	dh_installman

$(FFMANPAGES): %.1 : debian/tmp/usr/bin/%
	unset LD_PRELOAD && export LD_LIBRARY_PATH=debian/tmp/usr/lib && eval '$(BINNAMES)' && help2man --no-info --no-discard-stderr '--help-option= ' -n "$$$*" --version-option="-v" '$<' -o '$@' --include debian/man_notes.nroff

override_dh_clean:
	rm -f $(FFMANPAGES)
	dh_clean

override_dh_install:
	dh_install
	find debian -name ffindex_apply_mpi -exec chrpath --delete \{\} \;

# [Laszlo Kajan <lkajan@rostlab.org>]
# ffindex has an overly large default for FFINDEX_MAX_INDEX_ENTRIES (40000000). In order to require less RAM for testing the package (make check), a more modest value is set below.
override_dh_auto_test:
	dh_auto_test -- FFINDEX_MAX_INDEX_ENTRIES=20000 check

get-orig-source:
	mkdir -p ../tarballs
	uscan --verbose --force-download --destdir=../tarballs

override_dh_installexamples:
	dh_installexamples
	cp -aR test $(sampledir)/;
	cp ./src/test.should $(sampledir)/;
	cp ./src/test-unlink.should $(sampledir)/;
