#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Allow test programs that use OpenMPI to run
export OMPI_MCA_plm_rsh_agent=/bin/false


%:
	dh $@ --buildsystem=cmake --parallel


# NOTE: the superlu-dist cmake scripts generate a configuration error:
#   CMake Error in SRC/CMakeLists.txt:
#    Found relative path while evaluating include directories of "superlu_dist":
#      "OFF"
# with error code 1, which causes the build to halt.
# But the configuration seems fine (GNUInstallDirs are used to define standard install dirs).
# For now, work around the error by ignoring it (append "|| /bin/true")
override_dh_auto_configure:
	dh_auto_configure -- \
	    -DBUILD_SHARED_LIBS=ON -DCMAKE_SKIP_RPATH=ON \
	    -DCMAKE_C_COMPILER=mpicc -DCMAKE_FORTRAN_COMPILER=mpifort \
	    -DCMAKE_INSTALL_INCLUDEDIR=include/superlu-dist \
	    -Denable_blaslib=OFF -DTPL_BLAS_LIBRARIES=/usr/lib/$(DEB_HOST_MULTIARCH)/libblas.so \
	    -Denable_parmetislib=ON \
	    -DTPL_PARMETIS_INCLUDE_DIRS="/usr/include/scotch;/usr/include/parmetis;/usr/include/metis" \
	    -DTPL_PARMETIS_LIBRARIES="/usr/lib/$(DEB_HOST_MULTIARCH)/libparmetis.so;/usr/lib/$(DEB_HOST_MULTIARCH)/libmetis.so" \
	  || /bin/true


# set LD_LIBRARY_PATH to test against the libsuperlu_dist.so just built
override_dh_auto_test:
	export LD_LIBRARY_PATH=$(CURDIR)/obj-$(DEB_HOST_MULTIARCH)/SRC:$${LD_LIBRARY_PATH}; \
	LD_LIBRARY_PATH=$${LD_LIBRARY_PATH} dh_auto_test || /bin/true
