#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all abi=+lfs
export DEB_CFLAGS_MAINT_PREPEND = -Wall

include /usr/share/dpkg/default.mk
include /usr/share/dpkg/buildtools.mk

# The following architectures still fail the test suite:
#   m68k
#     (emulated, no proper test results)
#   sh4
#     (emulated, no proper test results)
#   sparc64
#     (19: mremap EINVAL)
#   hppa
#     (19: mremap EINVAL)
#     (17: looping, timeout?)
ifneq (,$(filter $(DEB_HOST_ARCH),m68k sh4 sparc64 hppa))
  TESTS_FLAKY = yes
endif

export CC

%:
	dh $@

override_dh_auto_test:
ifeq ($(TESTS_FLAKY),yes)
	@echo "Notice: Running tests in flaky mode, errors will be ignored."
endif
	$(if $(TESTS_FLAKY),-)$(MAKE) partcheck \
	  CPPFLAGS="$(CPPFLAGS)" \
	  CFLAGS="$(CFLAGS)" \
	  LDFLAGS="$(LDFLAGS)"

override_dh_auto_install:
	dh_auto_install -- \
	  libdir=/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_installchangelogs:
	dh_installchangelogs --no-trim

override_dh_makeshlibs:
	# XXX: Ideally we'd also rename the udeb, but d-i does not really
	# care about file conflicts, and that would take us through NEW
	# in the middle of the time64 transition.
	dh_makeshlibs --add-udeb=libaio1-udeb

execute_before_dh_installdeb-arch:
	set -e; for script in triggers; do \
		sed -e"s/#DEB_HOST_MULTIARCH#/$(DEB_HOST_MULTIARCH)/g" \
		    debian/libaio1t64.$$script.in \
		    > debian/libaio1t64.$$script ; \
	done
