#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for cd-hit
# Andreas Tille <tille@debian.org>
# GPL

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/default.mk

mandir=$(CURDIR)/debian/$(DEB_SOURCE)/usr/share/man/man1/

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- openmp=yes CC='$$(CXX)'

override_dh_installman:
	mkdir -p $(mandir)

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='quickly group sequences' \
	   $(CURDIR)/cd-hit > $(mandir)/cd-hit.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='quickly group sequences, optimised for 454 data' \
	   $(CURDIR)/cd-hit-454 > $(mandir)/cd-hit-454.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='quickly group sequences in db1 or db2 format' \
	   $(CURDIR)/cd-hit-2d > $(mandir)/cd-hit-2d.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='run CD-HIT algorithm on RNA/DNA sequences' \
	   $(CURDIR)/cd-hit-est > $(mandir)/cd-hit-est.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='run CD-HIT algorithm on RNA/DNA sequences in db1 or db2 format' \
	   $(CURDIR)/cd-hit-est-2d > $(mandir)/cd-hit-est-2d.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='divide a big clustering job into pieces to run cd-hit-2d or cd-hit-est-2d jobs' \
	   $(CURDIR)/cd-hit-2d-para.pl	> $(mandir)/cd-hit-2d-para.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	   --name='divide a big clustering job into pieces to run cd-hit or cd-hit-est jobs' \
	    $(CURDIR)/cd-hit-para.pl	> $(mandir)/cd-hit-para.1

	help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
           --name='divide a FASTA file into pieces' \
            $(CURDIR)/cd-hit-div.pl    > $(mandir)/cd-hit-div.1

	# psi-cd-hit.pl is throwing some errors which are fixed using sed
	# ... at least in versions <= 4.6.4 - now help2man does not work at all
	#help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	#   --name='runs similar algorithm like CD-HIT but using BLAST to calculate similarities' \
	#   $(CURDIR)/psi-cd-hit.pl	| \
	#   sed -e '/^Name "main::.*" used only once:/d' \
	#	> $(mandir)/psi-cd-hit.1

	# help2man does not work at all since version 4.6.4
	#help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	#   --name='runs similar algorithm like CD-HIT but using BLAST to calculate similarities in db1 or db2 format' \
	#      $(CURDIR)/psi-cd-hit-2d.pl	> $(mandir)/psi-cd-hit-2d.1

	# FIXME: what is the difference between psi-cd-hit-2d.pl and psi-cd-hit-2d-g1.pl ?
	# help2man does not work at all since version 4.6.4
	#help2man --no-info --no-discard-stderr --version-string='$(DEB_VERSION_UPSTREAM)' \
	#   --name='runs similar algorithm like CD-HIT but using BLAST to calculate similarities in db1 or db2 format' \
	#      $(CURDIR)/psi-cd-hit-2d-g1.pl	> $(mandir)/psi-cd-hit-2d-g1.1

	# No help output from
	#   clstr2tree.pl
	#   clstr_merge.pl
	#   clstr_merge_noorder.pl
	#   clstr_reduce.pl
	#   clstr_renumber.pl
	#   clstr_rev.pl
	#   clstr_sort_by.pl
	#   clstr_sort_prot_by
	#   make_multi_seq
	#   psi-cd-hit-local.pl    -> even throws several "used only once: possible typo" errors

override_dh_auto_install:
	dh_auto_install -- PREFIX=debian/$(DEB_SOURCE)/usr/lib/cd-hit

override_dh_compress:
	dh_compress --exclude=.pdf
