#!/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	

clean::
	rm -fr docs/doxygen/src
	rm -f po/*.gmo
	rm -f po/POTFILES.in
	rm -f po/code_saturne.pot
	rm -f po/stamp-po
	rm -f src/apps/cs_solver
	rm -f src/mei/mei_parser.[ch] src/mei/mei_scanner.c
	# Tango icon theme
	find gui/*/icons/?2x?2 -type l -name \*.png -delete
	# Uncomment when testing two builds in a row
	#echo "abort-on-upstream-changes" >debian/source/local-options

pre-build::
	# See sbin/bootstrap
	ls preprocessor/*/*.c src/*/*.c* | grep -v user_examples > po/POTFILES.in
	# Tango icon theme
	mkdir -p gui/Pages/icons/22x22
	mkdir -p gui/Pages/icons/32x32
	for icon in \
	  actions/add.png \
	  actions/bookmark-new.png \
	  actions/document-new.png \
	  actions/document-open.png \
	  actions/document-properties.png \
	  actions/document-save-as.png \
	  actions/document-save.png \
	  actions/edit-clear.png \
	  actions/edit-find-replace.png \
	  actions/edit-redo.png \
	  actions/edit-undo.png \
	  actions/format-justify-fill.png \
	  actions/process-stop.png \
	  actions/remove.png \
	  actions/system-log-out.png \
	  apps/help-browser.png \
	  apps/preferences-desktop-font.png \
	  apps/preferences-desktop-wallpaper.png \
	  apps/utilities-terminal.png \
	  categories/preferences-system.png \
	  mimetypes/application-certificate.png \
	  mimetypes/x-office-address-book.png \
	  places/network-server.png \
	  status/folder-open.png \
	  status/user-trash-full.png \
	  status/weather-few-clouds.png \
        ; do \
	    ln -sf /usr/share/icons/Tango/22x22/$$icon gui/trackcvg/icons/22x22/; \
	    ln -sf /usr/share/icons/Tango/22x22/$$icon gui/studymanager_gui/icons/22x22/; \
	    ln -sf /usr/share/icons/Tango/22x22/$$icon gui/Pages/icons/22x22/; \
	    ln -sf /usr/share/icons/Tango/22x22/$$icon gui/Base/icons/22x22/; \
        done
	ln -sf /usr/share/icons/Tango/32x32/actions/go-next.png gui/Pages/icons/32x32/
	ln -sf /usr/share/icons/Tango/32x32/actions/go-previous.png gui/Pages/icons/32x32/

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

binary-install/code-saturne-data::
	chmod +x debian/code-saturne-data/usr/share/code_saturne/runcase*
	dh_python2 -pcode-saturne-data

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

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