#!/usr/bin/make -f
%:
	dh $@ --with python2 --parallel --with autoreconf

#=====================================================================
# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif

export CFLAGS := -Wall $(shell dpkg-buildflags --get CFLAGS)
export CXXFLAGS := -Wall $(shell dpkg-buildflags --get CXXFLAGS)
export CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)

export LD_LIBRARY_PATH :=$(LD_LIBRARY_PATH):$(CURDIR)/./src/.libs/

configure_flags= $(CROSS) --prefix=/usr \
		--enable-boost --enable-shared --with-pic \
		--enable-python \
		--disable-matlab --disable-superlu --enable-scilab\
		CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CXXFLAGS)" \
		CPPFLAGS="$(CPPFLAGS)" \
		LDFLAGS="$(LDFLAGS)" 

disable_scilab_archs   = mips kfreebsd-amd64 kfreebsd-i386 s390x hurd-i386
ifneq (,$(filter $(DEB_HOST_ARCH), $(disable_scilab_archs)))
	configure_flags += --disable-scilab
else
	configure_flags += --enable-scilab --with-scilab-toolbox-dir=$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/scilab-getfem++/
endif

disable_muparser_archs = hurd-i386
ifneq (,$(filter $(DEB_HOST_ARCH), $(disable_muparser_archs)))
	configure_flags += --disable-muparser
else
	configure_flags += --enable-muparser 
endif

disable_mumps_archs = s390x
ifneq (,$(filter $(DEB_HOST_ARCH), $(disable_mumps_archs)))
	configure_flags += --disable-mumps
else
	configure_flags += --enable-mumps --with-mumps="-lsmumps_seq -ldmumps_seq -lcmumps_seq -lzmumps_seq -lpord_seq"  
endif


# shared library versions, option 1
version=4.2
major=5
#=====================================================================

override_dh_auto_configure:
	dh_auto_configure --	$(configure_flags)

override_dh_auto_build:
	dh_auto_build
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/scilab-getfem++/

override_dh_auto_install:
	dh_auto_install -- DESTDIR=$(CURDIR)/debian/tmp 
	# Workaround for the other archs without scilab getfem++
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/scilab-getfem++/
	mkdir -p $(CURDIR)/debian/scilab-getfem++/usr/share/scilab/contrib/
	cd $(CURDIR)/debian/scilab-getfem++/usr/share/scilab/contrib/; \
	rm -f scilab-getfem++; \
	ln -s ../../../lib/$(DEB_HOST_MULTIARCH)/scilab-getfem++/ getfem++

override_dh_install:
	dh_install --list-missing
	dh_numpy

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

override_dh_strip-arch:
	dh_strip -a --dbg-package=libgetfem++-dbg

override_dh_auto_test:
	PYTHONPATH=$(CURDIR)/interface/src/python/ dh_auto_test

override_dh_python2:
	dh_python2 --no-guessing-versions
