#!/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"

override_dh_auto_fixperms:
	dh_fixperms
	#mkdir -p debian/libhe5-hdfeos-dev/${LIBDIR}/pkgconfig debian/libhe5-hdfeos0/${LIBDIR}
	#mv hdf-eos5.pc debian/libhe5-hdfeos-dev/${LIBDIR}/pkgconfig
	chrpath -d debian/tmp/${LIBDIR}/libhe5_hdfeos.so.0.0.0
	#mv debian/tmp/${LIBDIR}/libhe5_hdfeos.so.0.0.0  debian/libhe5-hdfeos0/${LIBDIR}
	#cp debian/tmp/usr/lib/*/*.a debian/libhe5-hdfeos-dev/${LIBDIR}
	# cp -a samples/* debian/libhe5-hdfeos-dev/usr/share/doc/libhe5-hdfeos-dev/examples
	chmod -x debian/libhe5-hdfeos-dev/usr/share/doc/libhe5-hdfeos-dev/examples/*

