#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# allow bashism's in commandlines
SHELL = /bin/bash

# variables to be used in configure invocation. see
# autotools-dev/README.Debian.gz
export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# use autoconf 2.52 or newer
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

## Build BLAST parsing script mcxdeblast and the pipeline script mclblastline
## (sources in src/alien/oxygen).  It encapsulates all the stages of parsing,
## matrix creation, running mcl, and formatting the result
## into a single application.
confflags += --enable-blast

## add --enable-tribe to confflags to add the upstreams supplied tribe tools
## (protein clustering stuff).  This builds and installs the tools
##
##  tribe-families  tribe-matrix  tribemcl  tribe-parse
##
## We're not doing it since tribe-matrix segfaults, and the tools lackproper
## manpages.  Furthermore, the BLAST parsing scripts can be used in place of
## the tribe module.

# confflags += --enable-tribe

## If you really want to suppress the citation reference printed by MCL (the
## one which looks like
##
##  Please cite:
##    Stijn van Dongen, Graph Clustering by Flow Simulation.  PhD thesis,
##    University of Utrecht, May 2000.
##       (  http://www.library.uu.nl/digiarchief/dip/diss/1895620/full.pdf
##       or  http://micans.org/mcl/lit/svdthesis.pdf.gz)
##  OR
##    Stijn van Dongen, A cluster algorithm for graphs. Technical
##    Report INS-R0010, National Research Institute for Mathematics
##    and Computer Science in the Netherlands, Amsterdam, May 2000.
##       (  http://www.cwi.nl/ftp/CWIreports/INS/INS-R0010.ps.Z
##       or  http://micans.org/mcl/lit/INS-R0010.ps.Z)
##
## ), then this is the place to do it.  Of course we honor the choice of
## upstream here, and build as suggested by upsteam.

# confflags += --disable-helpful-reminder

docbackupdir:=$(CURDIR)/debian/doc.bak

%:
	dh $@ --with ocaml

override_dh_clean:
	dh_clean
	find . -name "*.zmr" -delete
	find . -name "*.zmt" -delete
	rm -rf doc/*.1 doc/*.html doc/*-html doc/*.ps
	rm -rf src/alien/oxygen/doc/*.1 src/alien/oxygen/doc/*.html src/alien/oxygen/doc/*.ps

override_dh_auto_build:
	#dh_auto_build
	autoreconf --install
	oasis setup
	ocaml setup.ml -all

override_dh_auto_configure:
	dh_auto_configure -- $(confflags)

override_dh_install:
	mv debian/tmp/usr/local/* debian/tmp/usr
	rm -rf debian/tmp/usr/local
	dh_install
	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

override_dh_missing:
	# Remove duplicated doc (*.html) and doc we do not want (*.ps)
	rm -f debian/tmp/usr/share/doc/mcl/*.html \
	      debian/tmp/usr/share/doc/mcl/*.ps
	dh_missing