#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# To enable all, uncomment following line
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

DEB_HOST_ARCH        ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),hurd-i386))
  RECVMMSG:=--enable-recvmmsg=no
else
  RECVMMSG:=--enable-recvmmsg=yes
endif

%:
	dh $@ --with autotools-dev,systemd,autoreconf --parallel

override_dh_auto_configure:
	dh_auto_configure -- \
	  --sysconfdir=/etc \
	  --localstatedir=/var/lib \
	  --libexecdir=/usr/lib/knot \
	  --with-rundir=/run/knot \
	  --with-storage=/var/lib/knot \
	  --enable-systemd=auto \
	  $(RECVMMSG) \
	  --disable-silent-rules

override_dh_auto_build-arch:
	dh_auto_build -- all

override_dh_auto_build-indep:
	dh_auto_build -- info pdf html

override_dh_auto_install-arch:
	dh_auto_install

override_dh_auto_install-indep:
	dh_auto_install -- install-info install-pdf install-html

override_dh_auto_test:
	-dh_auto_test

override_dh_strip:
	dh_strip --dbg-package=knot-dbg

override_dh_install-arch:
	# Install sample conf as /etc/knot/knot.conf
	mv $(CURDIR)/debian/tmp/etc/knot/knot.sample.conf $(CURDIR)/debian/tmp/etc/knot/knot.conf
	# Remove useless example zone from /etc/knot
	rm $(CURDIR)/debian/tmp/etc/knot/example.com.zone
	# Install custom script which creates RUNDIR and chowns it according to conffile settings
	install -m 755 -d $(CURDIR)/debian/tmp/usr/lib/knot/
	install -m 755 $(CURDIR)/debian/prepare-environment $(CURDIR)/debian/tmp/usr/lib/knot/

	# Remove .la and .so
	rm $(CURDIR)/debian/tmp/usr/lib/*/*.la $(CURDIR)/debian/tmp/usr/lib/*/*.so

	dh_install -Nknot-doc --list-missing

	install -m 755 -d $(CURDIR)/debian/knot/etc/ufw/applications.d/
	install -m 644 $(CURDIR)/debian/knot.ufw $(CURDIR)/debian/knot/etc/ufw/applications.d/knot

override_dh_install-indep:
	dh_install -pknot-doc --list-missing

override_dh_installchangelogs:
	dh_installchangelogs NEWS
