#!/usr/bin/make -f

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

# The magic rule for debhelper
%:
	dh $@ --with autoreconf

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)
DESTDIR=$(CURDIR)/debian/tmp

# 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:
	SHELL=/bin/bash  dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS) SHELL=/bin/bash
	# Needed for the pthreads tests
	cp  samples/simple.txt testdrivers/threads

override_dh_auto_test:
	@echo "Tests disabled in this version - known ok failures"
	#LD_LIBRARY_PATH=$(DESTDIR)/$(LIBDIR) dh_auto_test

override_dh_auto_install:
	dh_auto_install
	chrpath -d debian/tmp/${LIBDIR}/libhe5_hdfeos.so.0.0.0
	mkdir -p debian/libhe5-hdfeos-dev/${LIBDIR}/pkgconfig debian/libhe5-hdfeos0/${LIBDIR}
	mv hdf-eos5.pc debian/libhe5-hdfeos-dev/${LIBDIR}/pkgconfig
	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/*
	dh_link -p libhe5-hdfeos-dev ${LIBDIR}/libhe5_hdfeos.so.0.0.0 ${LIBDIR}/libhe5_hdfeos.so
	dh_link -p libhe5-hdfeos0   ${LIBDIR}/libhe5_hdfeos.so.0.0.0 ${LIBDIR}/libhe5_hdfeos.so.0
