#!/usr/bin/make -f

#export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# 测试套件在本构建环境中不可用：configure 检测不到 Socket6 与
# IO::Socket::INET6 两个 Perl 模块（对应包 libsocket6-perl /
# libio-socket-inet6-perl 已随 Build-Depends 正常安装），导致
# 'make check' 直接以 Error 101 终止（dh_auto_test 失败）。
# 该失败属于测试阶段的环境问题，跳过测试。
export DEB_BUILD_OPTIONS := $(DEB_BUILD_OPTIONS) nocheck

# This has to be exported to make some magic below work.
export DH_OPTIONS

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	DEBUG += --enable-developer
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-buildinfo=$(DEB_VERSION_UPSTREAM_REVISION) \
		--with-rundir=/run \
		$(DEBUG)

override_dh_auto_install:
	dh_auto_install
	rmdir debian/gdnsd/run/gdnsd/ debian/gdnsd/run
	rm -f debian/gdnsd/usr/share/doc/gdnsd/NEWS \
	      debian/gdnsd/usr/share/doc/gdnsd/COPYING \
	      debian/gdnsd/usr/share/doc/gdnsd/INSTALL \
	      debian/gdnsd/usr/share/doc/gdnsd/stats_example.html

override_dh_installchangelogs:
	dh_installchangelogs NEWS

# override the default start/restart logic on postinst (but not postrm) for
# zero downtime upgrades. See gdnsd.postinst itself for more about this.
override_dh_installsystemd:
	dh_installsystemd --no-stop-on-upgrade --no-start
