#!/usr/bin/make -f
%:
	dh $@

CFLAGS  += $(shell dpkg-buildflags --get CFLAGS)
# src/kurtz/mm3src/Makefile and src/kurtz/streesrc/Makefile make a use of CFLAGS that does not allow to override it, hence the following is added:
CFLAGS += -DSTREEHUGE -I$(CURDIR)/src/kurtz/libbasedir -I$(CURDIR)/src/kurtz/streesrc

TMPDIR      = $(CURDIR)/debian/tmp
BIN_DIR     = $(TMPDIR)/usr/bin
AUX_BIN_DIR = $(TMPDIR)/usr/lib/mummer
FINAL_BIN_DIR     = /usr/bin
FINAL_AUX_BIN_DIR = /usr/lib/mummer
FINAL_SCRIPT_DIR  = /usr/share/perl5/

override_dh_auto_build:
	[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
	[ -d $(AUX_BIN_DIR) ] || mkdir -p $(AUX_BIN_DIR)
	$(MAKE) BIN_DIR=$(BIN_DIR) AUX_BIN_DIR=$(AUX_BIN_DIR) \
	        FINAL_BIN_DIR=$(FINAL_BIN_DIR) FINAL_AUX_BIN_DIR=$(FINAL_AUX_BIN_DIR) \
	        FINAL_SCRIPT_DIR=$(FINAL_SCRIPT_DIR) \
	        CFLAGS="$(CFLAGS)"
	$(MAKE) -C docs

override_dh_auto_test:
	$(MAKE) check

override_dh_prep:
# Unfortunately the upstream makefile does not separate the build and install steps.
	dh_prep -X debian/tmp

override_dh_auto_install:
# /usr/bin/annotate renamed /usr/bin/mummer-annotate for namespace and license (Artistic) reasons.
	mv $(BIN_DIR)/annotate $(BIN_DIR)/mummer-annotate

override_dh_compress:
	dh_compress -Xpdf

NAME    = $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
VERSION = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p' | sed 's/~dfsg.*//')
TARBALL = MUMmer$(VERSION).tar.gz

get-orig-source:
	wget http://downloads.sourceforge.net/sourceforge/$(NAME)/$(TARBALL)
	rm -rf tmp
	mkdir tmp
	cd tmp ;\
	tar -xzf ../$(TARBALL) ;\
	rm -vf `find . -maxdepth 4 -name [MX]*.pdf` ;\
	GZIP="--best --no-name" tar -czf ../$(NAME)_$(VERSION)~dfsg.orig.tar.gz *
	rm -rf tmp
