#!/usr/bin/make -f

# DH_VERBOSE := 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/default.mk

# Upstream's top-level Makefile is only a developer convenience wrapper around
# meson; force debhelper to use the meson buildsystem, so that the makefile
# buildsystem is not autoselected (it has priority in debhelper's list)
BUILDDIR := obj-$(DEB_HOST_GNU_TYPE)

%:
	dh $@ --buildsystem=meson+ninja

override_dh_auto_configure:
	# harden=false: upstream adds -D_FORTIFY_SOURCE=3 on top of the
	#   -D_FORTIFY_SOURCE=2 set by dpkg-buildflags; a fatal redefinition
	# uv=disabled: run the regression test runner using the system python3
	#   instead of letting uv download dependencies (uv is not in Debian;
	#   the only requirement, fastjsonschema, is python3-fastjsonschema)
	dh_auto_configure -- -Dharden=false -Duv=disabled

override_dh_auto_build:
	dh_auto_build
	meson compile -C $(BUILDDIR) man

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	meson compile -C $(BUILDDIR) run-unit-tests run-regression-tests
endif

override_dh_installchangelogs:
	dh_installchangelogs CHANGES.md
