#!/usr/bin/make -f

ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
export DH_VERBOSE=1
endif
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

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

export PYBUILD_NAME = $(DEB_SOURCE)

dh_auto_configure_opts := --             \
                          --with-xtables \
                          --with-json    \
                          --with-cli=editline
pybuild_opts := --buildsystem=pybuild -- --dir $(CURDIR)/py
pybuild_pkg  := python3-$(PYBUILD_NAME)

ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
dh_auto_configure_opts += --disable-silent-rules
pybuild_opts           += --verbose
else
dh_auto_configure_opts += --enable-silent-rules
pybuild_opts           += --quiet
endif

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
dh_link_opts =
else
dh_link_opts = -Nnftables
endif

%:
	dh $@ --with python3

override_dh_auto_clean: override_dh_auto_cmd

override_dh_auto_configure: override_dh_auto_cmd

override_dh_auto_build: override_dh_auto_cmd

override_dh_auto_test:

override_dh_auto_install: override_dh_auto_cmd

override_dh_auto_cmd:
	$(DH_OVERRIDDEN_COMMAND) -N$(pybuild_pkg) $($(word 1,$(DH_OVERRIDDEN_COMMAND))_opts)
	$(DH_OVERRIDDEN_COMMAND) -p$(pybuild_pkg) $(pybuild_opts)

override_dh_installsystemd:
	$(DH_OVERRIDDEN_COMMAND) --no-enable --no-start --restart-after-upgrade

override_dh_link:
	$(DH_OVERRIDDEN_COMMAND) $(dh_link_opts)

execute_after_dh_fixperms:
	chmod a+x debian/nftables/etc/nftables.conf
