#!/usr/bin/make -f

BUILDDIR_PETSC = $(CURDIR)/debian/build/petsc
BUILDDIR_SPARSKIT = $(CURDIR)/debian/build/sparskit

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_CXXFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export OMPI_MCA_plm_rsh_agent=/bin/false                #workaround to start MPI-applications in chroot

%:
	dh $@

GETDP_CONFIGURE_COMMON =    -DENABLE_MPI:BOOL=ON \
			    -DCMAKE_SKIP_RPATH:BOOL=ON \
			    -DBLAS_LAPACK=ON -DBLAS_LAPACK_LIBRARIES="-llapack -lblas"

override_dh_auto_configure:
	dh_auto_configure --builddirectory=$(BUILDDIR_PETSC) -O--parallel    -- $(GETDP_CONFIGURE_COMMON) -DENABLE_PETSC=1 -DENABLE_SPARSKIT=0
	dh_auto_configure --builddirectory=$(BUILDDIR_SPARSKIT) -O--parallel -- $(GETDP_CONFIGURE_COMMON) -DENABLE_PETSC=0 -DENABLE_SPARSKIT=1
	sed -i 's/-lpthread/-lgfortran -lpthread/' debian/build/*/CMakeFiles/getdp.dir/link.txt

override_dh_auto_build:
	dh_auto_build -O--parallel --builddirectory=$(BUILDDIR_PETSC)
	dh_auto_build -O--parallel --builddirectory=$(BUILDDIR_SPARSKIT)
	mv $(BUILDDIR_SPARSKIT)/getdp $(BUILDDIR_SPARSKIT)/getdp-sparskit
	cd debian/build/petsc && make doc

override_dh_auto_install:
	dh_auto_install -O--parallel --builddirectory=$(BUILDDIR_PETSC)
	tar xzf debian/build/petsc/getdp*-doc.tgz -C debian/tmp/usr/share/doc/getdp/
	sed "s|image src=\"|image src=\"/usr/share/doc/getdp/html/|" -i debian/tmp/usr/share/doc/getdp/doc/texinfo/getdp.info
	sed "s|href=\"http://getdp.info/getdp.css|href=\"getdp.css|" -i debian/tmp/usr/share/doc/getdp/doc/texinfo/getdp.html

override_dh_auto_clean:
	dh_auto_clean
	rm -rf $(BUILDDIR_PETSC) $(BUILDDIR_SPARSKIT)
