#!/usr/bin/make -f
# -*- makefile -*-
# gerris debian/rules using debhelper. Adapted from dh_make v0.50.
#
# 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

# it's not appropriate to run all the tests in the test subdir as part of 
# the build process, since they assume gerris is already installed,
# calling gfsview-batch2D, etc.  So invoke nocheck (relevant to dh_auto_test)
export DEB_BUILD_OPTIONS=nocheck

BUILDDIR=debian/build
BUILDDIR_MPI=debian/build-mpi

# uses generic debhelper build
%:
	dh --with quilt  $@

override_dh_auto_configure:
	dh_auto_configure --builddirectory=$(BUILDDIR) -- --disable-mpi
	dh_auto_configure --builddirectory=$(BUILDDIR_MPI) -- --enable-mpi

# some autogenerated files get left behind by upstream autotools clean
# so remove them here
override_dh_auto_clean:
	dh_auto_clean --builddirectory=$(BUILDDIR)
	dh_auto_clean --builddirectory=$(BUILDDIR_MPI)
	for bdir in $(BUILDDIR) $(BUILDDIR_MPI); do    \
	   rm $$bdir/doc/examples/gerris.dic  || true;    \
	   rm $$bdir/doc/examples/gfs.lang    || true;    \
	   rm $$bdir/src/modules.c            || true;    \
	   rm $$bdir/src/modules.h            || true;    \
	done
	-rm doc/examples/gfs2tex.pyc

override_dh_auto_build:
	dh_auto_build --builddirectory=$(BUILDDIR)
	dh_auto_build --builddirectory=$(BUILDDIR_MPI)

override_dh_auto_install:
	dh_auto_install --builddirectory=$(BUILDDIR) --dest=debian/tmp
	dh_auto_install --builddirectory=$(BUILDDIR_MPI) --dest=debian/tmp-mpi

# don't need to install darcs2dist or gfs2doc
# see bug#436240 for my opinion on the sensibleness of this
override_dh_install:
	dh_install -pgerris --exclude=darcs2dist
	dh_install -plibgfs-1.3-2
	dh_install -plibgfs-dev
# dh_install can't figure out the mpi install dirs on its own, so use --sourcedir
	dh_install -pgerris-mpi --sourcedir=debian/tmp-mpi --exclude=darcs2dist
	dh_install -plibgfs-mpi-1.3-2 --sourcedir=debian/tmp-mpi
	dh_install -plibgfs-mpi-dev   --sourcedir=debian/tmp-mpi

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

override_dh_strip:
	dh_strip --dbg-package=libgfs-dbg

# gerris will pick up a dependency on libgfs-mpi-1.3-2
# unless we specific -Llibgfs-1.3-2 here
override_dh_shlibdeps:
	dh_shlibdeps -pgerris -Llibgfs-1.3-2
	dh_shlibdeps -plibgfs-1.3-2
	dh_shlibdeps -plibgfs-dev
	dh_shlibdeps -pgerris-mpi -Llibgfs-mpi-1.3-2
	dh_shlibdeps -plibgfs-mpi-1.3-2
	dh_shlibdeps -plibgfs-mpi-dev
	dh_shlibdeps -plibgfs-dbg

