#!/usr/bin/make -f

export DH_VERBOSE=1

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

DESTDIR:=`pwd`/debian/tmp/
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR:=/usr/lib/$(DEB_HOST_MULTIARCH)
AUTOGENERATED:= libcoda-dev.links libcoda14.links libcoda-jni.install

ifneq ($(wildcard /usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial/libhdf5.so),)
  WITH_HDF5:=--with-hdf5=/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial
else
  WITH_HDF5:=--with-hdf5=/usr
endif

override_dh_auto_configure:
	for f in ${AUTOGENERATED} ; do \
                sed -e 's%@TRIPLET@%${DEB_HOST_MULTIARCH}%g' < debian/$$f.in  > debian/$$f ; \
                done
	./configure --prefix=/usr --libdir=$(LIBDIR) \
		--enable-java \
		--enable-python \
		--with-hdf4 \
		$(WITH_HDF5) \
		PYTHON=python3 \
		JAVA_HOME='/usr/lib/jvm/default-java' \
		HDF4_INCLUDE=/usr/include/hdf

override_dh_auto_install:
	dh_auto_install
	find debian -name '*.la' -delete

override_dh_auto_clean:
	rm -f config.log
	rm -f $(patsubst %, debian/%, ${AUTOGENERATED})
	dh_auto_clean

