#!/usr/bin/make -f

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

DEB_BUILD_MAINT_OPTIONS = hardening=+all
DEB_CFLAGS_MAINT_APPEND = -Wall -Wextra
DEB_CPPFLAGS_MAINT_APPEND = -D_XOPEN_SOURCE=600
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

srcpkg = $(shell dpkg-parsechangelog | sed -ne 's/Source: *//p')
srcver = $(shell dpkg-parsechangelog | sed -ne 's/Version: *\(.*:\)\?\(.*\)-[0-9.]*$$/\2/p')
#{{{ generic rules

../$(srcpkg)_$(srcver).orig.tar.gz:
	@! git rev-parse --git-dir >/dev/null 2>&1 || pristine-tar checkout $@

check-tarball: ../$(srcpkg)_$(srcver).orig.tar.gz

.PHONY: check-tarball

#}}}

binary binary-arch binary-indep build build-arch build-indep clean install install-arch install-indep:
	dh $@

override_dh_auto_configure:
	-test \! -f debian/config.h.in && mv config.h.in debian/config.h.in
	-test \! -f debian/configure && mv configure debian/configure
	autoreconf -fi
	dh_auto_configure -- \
	       --with-configdir=/etc/nsd3                     \
	       --with-nsd_conf_file=/etc/nsd3/nsd.conf        \
	       --with-pidfile=/var/run/nsd3/nsd.pid           \
	       --with-dbfile=/var/lib/nsd3/nsd.db             \
	       --with-zonesdir=/etc/nsd3                      \
	       --with-difffile=/var/lib/nsd3/ixfr.db          \
	       --with-xfrdfile=/var/lib/nsd3/xfrd.state       \
	       --disable-largefile                            \
	       --enable-root-server                           \
	       --enable-mmap				      \
	       --enable-ratelimit

override_dh_auto_clean:
	dh_auto_clean
	-test -f debian/config.h.in && mv debian/config.h.in config.h.in
	-test -f debian/configure && mv debian/configure configure

override_dh_auto_install:
	dh_auto_install -- DESTDIR=$(CURDIR)/debian/nsd3
	rmdir $(CURDIR)/debian/nsd3/var/run/nsd3
	rmdir $(CURDIR)/debian/nsd3/var/run

override_dh_installchangelogs:
	dh_installchangelogs doc/ChangeLog
