#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

#include /usr/share/dpatch/dpatch.make

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

Makefile:
	dh_testdir
	cp -a Makefile.in Makefile

configure: configure-stamp
#configure-stamp: patch-stamp Makefile.deborig
configure-stamp: Makefile
	dh_testdir
	yorick -batch ./config.i\
	 --with-regex --with-regex-defs='-DHAVE_REGEX=1'\
	 --with-fftw --with-fftw-libs="-lrfftw -lfftw"\
	 --with-tiff --with-tiff-libs="-ltiff"\
	 --with-gsl --with-gsl-libs="-lgsl -lgslcblas" --with-gsl-defs='-I/usr/include/gsl'
	touch configure-stamp

check:
	dh_testdir
ifeq (,$(filter nocheck, $(DEB_BUILD_OPTIONS)))
	yorick -batch debian/check.i
endif


build: build-stamp

build-stamp: configure-stamp 
	$(MAKE) -C yeti_fftw
	$(MAKE) -C yeti_gsl
	$(MAKE) -C yeti
	$(MAKE) -C yeti_regex
	$(MAKE) -C yeti_tiff
	touch build-stamp

#clean: configure-stamp clean-patched unpatch
clean: configure-stamp Makefile
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(MAKE) clean
	rm -f  config.h configure-stamp Makefile
	dh_clean  --exclude ./yeti_regex/glibc/regcomp.c.orig --exclude ./yeti_regex/glibc/regexec.c.orig

install-arch: install-check 

install-check:
	dh_testdir
	dh_testroot
	dh_clean -k -s  --exclude ./yeti_regex/glibc/regcomp.c.orig --exclude ./yeti_regex/glibc/regexec.c.orig

# Must not depend on anything. This is to be called by
# binary-arch/binary-indep
# in another 'make' thread.
binary-common:
	dh_testdir
	dh_testroot
	dh_installyorick
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
#binary-indep: build-indep install-indep
# leave this alone, I'll re-introduce *-doc later.
binary-indep:
#	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

#binary-indep:

# Build architecture dependant packages using the common target.
binary-arch: build check install-arch
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

binary: binary-arch binary-indep
.PHONY: build clean binary-indep binary-arch binary install install-indep install-arch configure install-check
