#!/usr/bin/make -f
#
# Copyright (C) 2008 Francesco Paolo Lovergine <frankie@debian.org>
# Released under GPL. See /usr/share/common-licenses/GPL for
# more information about the license.
#

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

UPSTREAM_VERSION = $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/\+.*//')

export DEB_CPPFLAGS_MAINT_APPEND = -I/usr/include/tirpc/
export DEB_LDFLAGS_MAINT_APPEND = -ltirpc

ifneq (,$(filter $(DEB_HOST_ARCH),armhf))
# Suggested by Emanuele Rocca in https://lists.debian.org/debian-arm/2026/03/msg00003.html
export DEB_CFLAGS_MAINT_APPEND += -std=c17
endif

ifneq (,$(findstring verbose,$(DEB_BUILD_OPTIONS)))
   DH_VERBOSE=1
   export DH_VERBOSE
endif

%:
	dh $@

override_dh_auto_configure:
	# configure the netcdf compatible flavor, without fortran functions.
	dh_auto_configure -- -DHDF4_USE_GNU_DIRS=ON \
	                     -DHDF4_INSTALL_INCLUDE_DIR=include/hdf \
	                     -DHDF4_INSTALL_LIB_DIR=lib/$(DEB_HOST_MULTIARCH) \
	                     -DHDF4_BUILD_UTILS=ON \
	                     -DHDF4_ENABLE_SZIP_SUPPORT=ON

override_dh_auto_test:
ifneq (,$(filter $(DEB_BUILD_ARCH),ppc64el s390x sparc64))
	dh_auto_test --no-parallel || echo "Ignoring test failures"
else
	dh_auto_test --no-parallel
endif

execute_after_dh_auto_install:
	# strip rpath from binaries
	-find $(CURDIR)/debian/tmp/usr/bin -type f -not -name h4cc -not -name h4redeploy -exec chrpath --delete {} \;

	# strip rpath from libraries
	-find $(CURDIR)/debian/tmp/usr/lib -name "*.so*" -type f -exec chrpath --delete {} \;

override_dh_makeshlibs:
	dh_makeshlibs -- -v$(UPSTREAM_VERSION)
