#!/usr/bin/make -f

# Comment out this line for debugging
export DH_VERBOSE:=1

# The magic rule for debhelper
%:
	dh $@

export HDF5_USE_SHLIB=yes
export CC=/usr/bin/h5cc

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

# Enforce shared lib linking# Enforce shared lib linking# Enforce shared lib linking# Enforce shared lib linking
export HDF5_USE_SHLIB=yes

# Disable checks: known bad test case ignored this release
DEB_CONFIGURE_EXTRA_FLAGS :=  --enable-shared --with-pic --with-szlib=/usr/include,$(LIBDIR)

ifneq ($(wildcard /usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial/libhdf5.so),)
  DEB_CONFIGURE_EXTRA_FLAGS += --with-hdf5=/usr/include/hdf5/serial,/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial
endif

export DEB_CFLAGS_MAINT_APPEND=-D_HDFEOS5_THREADSAFE -Df2cFortran
export DEB_LDFLAGS_MAINT_APPEND=-lpthread

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)
	# Needed for the pthreads tests
	cp  samples/simple.txt testdrivers/threads

override_dh_auto_test:
	dh_auto_test || echo "Ignoring test failures"
	find debian/ -name core -delete

execute_after_dh_fixperms:
	rm -f debian/libhe5-hdfeos-dev/usr/share/doc/libhe5-hdfeos-dev/examples/*.o
	chmod -x debian/libhe5-hdfeos-dev/usr/share/doc/libhe5-hdfeos-dev/examples/*
	chrpath -d debian/libhe5-hdfeos0t64/${LIBDIR}/libhe5_hdfeos.so.0.0.0


