#!/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

pkg := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
ver := $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(\([0-9]\+\):\)\?\(.*\)-.*/\3/p')

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

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- openmp=yes

override_dh_installman:
	mkdir -p $(mandir)

	help2man --no-info --no-discard-stderr --version-string='$(ver)' \
	   --name='quickly group sequences' \
	   $(CURDIR)/cd-hit	| \
	   sed -e 's/^cd-\(hit \\-\)/cd\1/' -e 's/^.B cd-hit/.B cdhit/' \
	   > $(mandir)/cdhit.1

	help2man --no-info --no-discard-stderr --version-string='$(ver)' \
	   --name='quickly group sequences, optimised for 454 data' \
	   $(CURDIR)/cd-hit-454	| \
	   sed -e 's/^cd-\(hit \\-\)/cd\1/' -e 's/^.B cd-hit/.B cdhit/' \
	   > $(mandir)/cdhit-454.1

	help2man --no-info --no-discard-stderr --version-string='$(ver)' \
	   --name='quickly group sequences in db1 or db2 format' \
	   $(CURDIR)/cd-hit-2d	| \
	   sed -e 's/^cd-\(hit-2d \\-\)/cd\1/' -e 's/^.B cd-hit/.B cdhit/' \
	   	> $(mandir)/cdhit-2d.1

	help2man --no-info --no-discard-stderr --version-string='$(ver)' \
	   --name='run CD-HIT algorithm on RNA/DNA sequences' \
	   $(CURDIR)/cd-hit-est	| \
	   sed -e 's/^cd-\(hit-est \\-\)/cd\1/' -e 's/^.B cd-hit/.B cdhit/' \
		> $(mandir)/cdhit-est.1

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

	help2man --no-info --no-discard-stderr --version-string='$(ver)' \
	   --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='$(ver)' \
	   --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

	# psi-cd-hit.pl is throwing some errors which are fixed using sed
	help2man --no-info --no-discard-stderr --version-string='$(ver)' \
	   --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 --no-info --no-discard-stderr --version-string='$(ver)' \
	   --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 --no-info --no-discard-stderr --version-string='$(ver)' \
	   --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
	#   cd-hit-div.pl
	#   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/$(pkg)/usr/lib/cd-hit

override_dh_compress:
	dh_compress --exclude=.pdf
