#!/usr/bin/make -f
#export DH_VERBOSE = 1

# 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 = -W

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- -DMFEM_USE_MPI=YES \
	    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
	    -DMFEM_SOURCE_DIR=. \
	    -DBUILD_SHARED_LIBS=1 \
	    -DHYPRE_INCLUDE_DIR=/usr/include/hypre \
	    -DMFEM_ENABLE_TESTING=OFF \
	    -DINSTALL_LIB_DIR=lib/x86_64-linux-gnu \
	    -DCMAKE_INSTALL_PREFIX=$(pwd)/usr \
#	    -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=OFF
# maybe enable at some point later
#-DMFEM_USE_ADIOS2=ON libadios-dev
#-DMFEM_USE_MPFR=ON libmpfr-dev
#-DMFEM_USE_LIBUNWIND=ON libunwind-dev
#-DMFEM_USE_MUMPS=ON libmumps-dev
#-DMFEM_USE_SUNDIALS=ON libsundials-dev
#-DMFEM_USE_SUPERLU                 OFF or MFEM_USE_SUPERLU5                OFF libsuperlu-dev
#-DMFEM_USE_SIMD=ON libsimde-dev
# libscotch-dev
#
#	$(MAKE) config MFEM_USE_METIS=YES MFEM_USE_METIS_5=YES MFEM_DEBUG=YES MFEM_USE_LIBUNWIND=YES
# MFEM_USE_LAPACK = YES MFEM_USE_OPENMP = YES
# recommended MFEM_USE_MEMALLOC = YES
# MFEM_USE_MPFR = YES
# MFEM_USE_ADIOS2 = YES
# MFEM_USE_ZLIB = YES
# MFEM_USE_MPI = YES hypre

#override_dh_auto_build:
#	$(MAKE) all

override_dh_auto_install:
	@echo NOT SKIPPING AUTO INSTALL
	dh_auto_install

override_dh_missing:
	@echo NO DH MISSING

override_dh_fixperms:
	dh_fixperms
	chrpath -d debian/libmfem4*/usr/lib/*-*/libmfem.so*
# one day this will also work on non x86_64-linux-gnu
# debian/libmfem-dev/usr/lib/cmake/mfem/*.cmake are with absolute wrong/build paths
	sed -i "s,/.*/lib/.*/libmfem.so.4.5.2,/usr/lib/x86_64-linux-gnu/libmfem.so.4.5.2,g" debian/libmfem-dev/usr/lib/cmake/mfem/MFEMTargets-*.cmake
# one day someone will fix the -ffile-prefix-map
	sed -i "s,/.*/lib/.*x86_64-linux-gnu,/usr/lib/x86_64-linux-gnu,g" debian/libmfem-dev/usr/lib/cmake/mfem/MFEMConfig.cmake

override_dh_auto_test:
	@echo skipping test
