#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

# VERSION: upstream derives the version from "git describe" which reports
#   "unknown-version" when building from the release tarball. Report the Debian
#   package version instead.
# nbdkit: the plugin defaults to "auto" so a missing nbdkit-plugin-dev would
#   silently drop it from the build. Enable it always so configure fails
#   rather than leaving nbdkit-plugin-qdl empty.
# udev_group: the udev rules only tag EDL devices with uaccess, which grants
#   access to the user on the active local seat. Also grant access to the
#   plugdev group so that flashing works from ssh or other non-seat sessions,
#   matching how other Debian packages handle USB devices.
# tests: the unit tests need cmocka, which is not installed for the nocheck
#   profile. Disable them there, as dh_auto_configure would otherwise turn the
#   "auto" feature into a hard requirement and fail configure.
override_dh_auto_configure:
	dh_auto_configure -- \
		-DVERSION=$(DEB_VERSION) \
		-Dnbdkit=enabled \
		-Dtests=$(if $(filter nocheck,$(DEB_BUILD_PROFILES)),disabled,enabled) \
		-Dudev_group=plugdev

# The nbdkit plugin documentation ships in nbdkit-plugin-qdl, so leave it out
# of the upstream documentation installed in qdl.
override_dh_installdocs:
	dh_installdocs -pqdl -Xnbd.md
	dh_installdocs --remaining-packages

# The man page is generated by running the built qdl binary through help2man,
# which upstream skips when cross-building. help2man is not installed for the
# cross and nodoc profiles, so only install the man page without them.
ifeq ($(filter cross nodoc,$(DEB_BUILD_PROFILES)),)
override_dh_installman:
	dh_installman -pqdl debian/tmp/usr/share/man/man1/qdl.1
endif
