#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DEB_BUILD_MAINT_OPTIONS = hardening=+all
DEB_CPPFLAGS_MAINT_APPEND = -DNDEBUG
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

# For asm/types.h - duplicates "default" BPF_CFLAGS content from configure.ac
export BPF_CFLAGS=-Wall -Wextra -Wconversion -Werror -I/usr/include/$(DEB_HOST_MULTIARCH)

ifneq (,$(findstring $(DEB_HOST_ARCH_OS), linux))
  WITH_SYSTEMD = --enable-systemd
endif

ifeq (,$(filter $(DEB_HOST_ARCH),alpha hppa hurd-amd64 hurd-i386 m68k mips64el sh4))
  ENABLE_XDP = --enable-xdp
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
	       --with-configdir=/etc/nsd		\
	       --with-nsd_conf_file=/etc/nsd/nsd.conf	\
	       --with-pidfile=/run/nsd/nsd.pid		\
	       --with-dbfile=/var/lib/nsd/nsd.db	\
	       --with-dbdir=/var/lib/nsd		\
	       --with-zonesdir=/etc/nsd			\
	       --with-xfrdfile=/var/lib/nsd/xfrd.state	\
	       --disable-largefile			\
	       --disable-recvmmsg			\
	       --enable-root-server			\
	       --enable-mmap				\
	       $(WITH_SYSTEMD)				\
	       --enable-checking			\
	       --enable-prometheus-metrics		\
	       $(ENABLE_XDP)				\
	       --with-sharedfilesdir=/usr/lib/bpf/nsd	\

execute_after_dh_auto_install:
	rmdir $(CURDIR)/debian/nsd/run/nsd
	rmdir $(CURDIR)/debian/nsd/run
	rmdir $(CURDIR)/debian/nsd/tmp

override_dh_install-arch:
	dh_install -a
	rm -f $(CURDIR)/debian/nsd/etc/nsd/nsd.conf.sample

override_dh_installchangelogs:
	dh_installchangelogs doc/ChangeLog
