#!/usr/bin/make -f

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

export deb_systemdsystemunitdir = $(shell pkg-config --variable=systemdsystemunitdir systemd | sed s,^/,,)

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

# Avoid test failure in docker.
export PDNS_TEST_NO_IPV6=1

%:
	dh $@ --buildsystem=meson

override_dh_auto_clean:
	dh_auto_clean
	rm -f dnslabeltext.cc

override_dh_auto_configure:
	dh_auto_configure -- \
		--sysconfdir=/etc/powerdns \
		-Dreproducible=true \
		-Dlua=auto \
		-Dsystemd-service=enabled \
		-Dsystemd-service-user=pdns \
		-Dsystemd-service-group=pdns \
		-Dsigners-libsodium=enabled \
		-Dsigners-libcrypto=enabled \
		-Ddns-over-tls=enabled \
		-Dtools=true \
		-Dtools-ixfrdist=true \
		-Dlua-records=true \
		-Dmodule-bind=dynamic \
		-Dmodule-ldap=dynamic \
		-Dmodule-lmdb=dynamic \
		-Dmodule-lua2=dynamic \
		-Dmodule-pipe=dynamic \
		-Dmodule-gmysql=dynamic \
		-Dmodule-godbc=dynamic \
		-Dmodule-gpgsql=dynamic \
		-Dmodule-gsqlite3=dynamic \
		-Dmodule-geoip=dynamic \
		-Dmodule-remote=dynamic \
		-Dmodule-tinydns=dynamic \
		-Dunit-tests=true \
		-Dexperimental-pkcs11=enabled

execute_after_dh_auto_install:
	find debian/tmp
	rm debian/tmp/etc/powerdns/ixfrdist.example.yml debian/tmp/etc/powerdns/pdns.conf-dist

override_dh_installsystemd:
	dh_installsystemd --no-start -ppdns-server --name=pdns
	dh_installsystemd --no-start -ppdns-ixfrdist --name=ixfrdist

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	./debian/tests-source/run
	dh_auto_test
endif

execute_after_dh_fixperms:
	# these files often contain passwords.
	chmod 0640 debian/pdns-server/etc/powerdns/pdns.conf
