#!/usr/bin/make -f
# -*- makefile -*-
#
# The package layout follows the official Debian/Ubuntu packaging of
# libsmi (libsmi2t64, libsmi2-dev, libsmi2-common, smitools, smistrip),
# so that these packages cleanly upgrade the distribution packages.

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- SH=/bin/sh

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) check || { cat test/test-suite.log; exit 1; }
endif

# smistrip is shipped in its own package (as in Debian)
override_dh_install-arch:
	dh_install -a
	rm -f debian/smitools/usr/bin/smistrip
	rm -f debian/smitools/usr/share/man/man1/smistrip.1*

# Allow to invoke manual pages by function names (as in Debian)
override_dh_installman-arch:
	dh_installman -a
	cd debian/libsmi2-dev/usr/share/man/man3 ; \
	for i in *.3; do for j in `cat $$i | \
		awk 'BEGIN { output=0 } ($$NF == "COPIES") { output=1-output ; next } (output == 1 && $$1 ~ /^smi/) { print $$0 }' | \
		sed 's/,$$//'`; do \
		[ -e $$j.3 ] || ln -s $$i $$j.3 ; \
	done ; done

# xz instead of zstd: the module package is large and zstd needs a lot
# of memory at its default level in constrained build environments.
override_dh_builddeb:
	dh_builddeb -- -Zxz
