#!/usr/bin/make -f

# Turn on all hardening flags, as we're a networked daemon.
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

# Vendor and version
CXXFLAGS += -DPACKAGEVERSION='"$(DEB_VERSION).$(DEB_VENDOR)"'

# Disable systemd integration on non-linux archs
ifeq ($(DEB_HOST_ARCH_OS),linux)
CONFIGURE_ARGS += --enable-systemd --with-systemd=/lib/systemd/system
else
CONFIGURE_ARGS += --disable-systemd
endif


%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	rm -f dnslabeltext.cc

override_dh_auto_configure:
	chmod a+x debian/configure-helpers/*
	PATH=debian/configure-helpers/:$$PATH dh_auto_configure -- \
	  --sysconfdir=/etc/dnsdist \
	  --enable-unit-tests \
	  --disable-silent-rules \
	  --enable-dnscrypt \
	  --enable-dns-over-https \
	  --enable-dns-over-tls \
	  --enable-dnstap \
	  --with-ebpf \
	  --with-libsodium \
	  --with-libssl \
	  --with-lua \
	  --with-net-snmp \
	  --with-protobuf \
	  --with-re2 \
	  $(CONFIGURE_ARGS)

override_dh_auto_build-arch:
	dh_auto_build -- V=1

override_dh_install:
	dh_auto_install
	echo Patching uid and git into debian/dnsdist/lib/systemd/system/*.service
	perl -pi -e 's/(^ExecStart=.*)/$$1 -u _dnsdist -g _dnsdist/' debian/dnsdist/lib/systemd/system/*.service
	install -m 0640 debian/config/dnsdist.conf debian/dnsdist/etc/dnsdist/
	install -d debian/dnsdist/usr/share/dnsdist/snmp
	install -m 644 -t debian/dnsdist/usr/share/dnsdist/snmp DNSDIST-MIB.txt

override_dh_installexamples:
	cp dnsdistconf.lua dnsdist.conf
	dh_installexamples
	rm -f dnsdist.conf
