#!/usr/bin/make -f
# Copyright 2009 Sylvestre Ledru <sylvestre@debian.org>

# Exclude cs_config.py from package code-saturne-data:
# It should go into code-saturne-include.
# Exclude extra license file COPYING as well.
binary-install/code-saturne-data:: DEB_DH_INSTALL_ARGS := -Xcs_config.py -XCOPYING

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/autoreconf.mk

# Which MPI implementation?
# set ARCH_DEFAULT_MPI_IMPL
include /usr/share/mpi-default-dev/debian_defaults

DEB_CONFIGURE_USER_FLAGS := --with-mpi --libexecdir=/usr/lib/

ifneq ($(wildcard /usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/$(ARCH_DEFAULT_MPI_IMPL)/libhdf5.so),)
  DEB_CONFIGURE_USER_FLAGS += \
	--with-hdf5-include=/usr/include/hdf5/$(ARCH_DEFAULT_MPI_IMPL) \
	--with-hdf5-lib=/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/$(ARCH_DEFAULT_MPI_IMPL)
endif

#--libdir=/usr/lib/code-saturne
DEB_MAKE_CLEAN_TARGET    := distclean
DEB_MAKE_BUILD_TARGET    := all
DEB_MAKE_INSTALL_TARGET  := install DESTDIR=`pwd`/debian/tmp
DEB_COMPRESS_EXCLUDE := .pdf .xml .des .f90 .c

# Enable parallel build when available
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif	

DEB_DH_AUTORECONF_ARGS := sbin/bootstrap

clean::
	rm -f src/apps/cs_solver
	cd libple/po && rm -f *.gmo *.pot stamp-po
	cd po && rm -f *.gmo *.pot stamp-po
	rm -f src/base/cdomod.mod
	rm -f src/user_examples/user_module.mod
	rm -fr libple/build-aux
	# Uncomment when testing two builds in a row
	#echo "abort-on-upstream-changes" >debian/source/local-options

install/code-saturne-bin::
	chrpath -d debian/tmp/usr/lib/lib*.so* debian/tmp/usr/lib/code_saturne/cs*

binary-install/code-saturne-data::
	chmod +x debian/code-saturne-data/usr/share/code_saturne/runcase*
	find debian/code-saturne-data -type f \( -name \*.pyc -o -name \*.pyo \) -delete
	dh_python2 -pcode-saturne-data

binary-install/code-saturne-include::
	dh_python2 -pcode-saturne-include

build/code-saturne-doc::
	$(MAKE) html
	$(MAKE) pdf
