#!/usr/bin/make -f

#export DH_VERBOSE=1

include /usr/share/debhelper/dh-fortran/fortran-support.mk

export FC_DEFAULT

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
TMPDIR:=$(CURDIR)/debian/tmp
LIBDIR:=/usr/lib/$(DEB_HOST_MULTIARCH)

DO_TEST:=true

# The magic debhelper  rule
%:
	dh $@ --buildsystem=ecbuild --with fortran

BUILD_FLAGS:= -DENABLE_FORTRAN=ON \
			-DENABLE_RPATHS=OFF \

override_dh_auto_configure:
	dh_auto_configure -- \
		      ${BUILD_FLAGS} -DCMAKE_Fortran_COMPILER=$(FC_DEFAULT)

override_dh_auto_test:
	$(DO_TEST) && ( LD_LIBRARY_PATH=$(CURDIR)/debian/build/lib dh_auto_test  ) || true

override_dh_dwz:
	@echo bypass dwz that causes build failures due to patchelf changes

override_dh_auto_install:
	dh_auto_install 
	# Fixup cmake files
	sed -i -e 's%$${_IMPORT_PREFIX}/include%/usr/include/${DEB_HOST_MULTIARCH}%g' $(TMPDIR)/$(LIBDIR)/cmake/odc/odc-targets.cmake
	sed -i -e 's%/include/odc%/usr/include/${DEB_HOST_MULTIARCH}/odc%g' $(TMPDIR)/$(LIBDIR)/cmake/odc/odc-targets.cmake
	sed -i -e 's%libfodc.so%libfodc-${FC_DEFAULT}.so%g'   $(TMPDIR)/$(LIBDIR)/cmake/odc/odc-targets-release.cmake
