#!/usr/bin/make -f

# Hardening
export DEB_BUILD_MAINT_OPTIONS = hardening=+all reproducible=+all optimize=-lto
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

meson_opts := --wrap-mode=default
meson_opts += --auto-features=enabled
meson_opts += -Ddpdk_cpu=generic

# FRR support can be disabled with DEB_BUILD_OPTIONS=nofrr
ifneq (,$(filter nofrr,$(DEB_BUILD_OPTIONS)))
meson_opts += -Dfrr=disabled
else
meson_opts += -Dfrr=enabled
endif

build = $(CURDIR)/debian/_build
dest = $(CURDIR)/debian/tmp

# Skip grout-frr package when FRR is disabled
ifneq (,$(filter nofrr,$(DEB_BUILD_OPTIONS)))
dh_opts = -Ngrout-frr
endif

%:
	dh $@ --buildsystem=meson --with=bash-completion -B$(build) $(dh_opts)

override_dh_auto_configure:
	dh_auto_configure -- $(meson_opts)

override_dh_auto_install:
	meson install -C $(build) --skip-subprojects --destdir=$(dest)

override_dh_missing:
ifneq (,$(filter nofrr,$(DEB_BUILD_OPTIONS)))
	dh_missing --exclude=grout-frr.7
else
	dh_missing
endif

override_dh_installsystemd:
	dh_installsystemd --no-start --no-stop-on-upgrade
