#!/usr/bin/make -f

# Vendor and version
version := $(shell dpkg-parsechangelog -SVersion).$(shell dpkg-vendor --query Vendor)
CXXFLAGS += -DPACKAGEVERSION='"$(version)"'

# Backends
backends := bind ldap pipe gmysql gpgsql gsqlite3 geo lua lmdb mydns remote

DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# Use new build system
%:
	dh $@ --with autoreconf --parallel

override_dh_auto_configure:
	mv pdns/dnslabeltext.cc debian/dnslabeltext.cc.moved
	./configure \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr \
		--sysconfdir=/etc/powerdns \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--libdir='$${prefix}/lib/$(DEB_HOST_MULTIARCH)' \
		--libexecdir='$${prefix}/lib' \
		--with-dynmodules="$(backends)" \
		--with-modules="" \
		--with-system-polarssl \
		--with-pgsql-includes=`pg_config --includedir` \
		--enable-cryptopp \
		--enable-botan1.10 \
		--enable-tools \
		--enable-unit-tests

# pdns-server has a debug package
override_dh_strip:
	dh_strip --dbg-package=pdns-server-dbg

# Additional permissions
override_dh_fixperms:
	dh_fixperms
	chmod 755 debian/pdns-server/etc/resolvconf/update.d/pdns

# init script needs to be named pdns, not pdns-server
override_dh_installinit:
	dh_systemd_enable --name=pdns
	dh_installinit --name=pdns
	dh_systemd_start --restart-after-upgrade

# Verbose build (shows used compiler/linker and their flags)
override_dh_auto_build-arch:
	dh_auto_build -- V=1

# Verbose tests (shows used compiler/linker and their flags)
override_dh_auto_test:
	echo Skipping make test, as dependencies are missing.
	#dh_auto_test -- V=1

# restore moved files
override_dh_clean:
	test -f debian/dnslabeltext.cc.moved && mv debian/dnslabeltext.cc.moved pdns/dnslabeltext.cc || true
	dh_clean
