#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic -fno-omit-frame-pointer
# package maintainers to append LDFLAGS
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk
include /usr/share/dpkg/buildflags.mk

export GOPATH = /usr/share/gocode

export ARCH=$(DEB_HOST_GNU_CPU)

# main packaging script based on dh7 syntax
%:
	dh $@ --with systemd --with golang

override_dh_auto_build:
	dh_auto_build -- ARCH=$(DEB_HOST_GNU_CPU) V=1

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp -- ARCH=$(DEB_HOST_GNU_CPU)
	# make the modules non-executable
	chmod -x debian/tmp/usr/lib/knot-resolver/*.lua
	chmod -x debian/tmp/usr/lib/knot-resolver/*.so
	if [ -d debian/tmp/usr/lib/knot-resolver/tinyweb/ ]; then \
	  chmod -x debian/tmp/usr/lib/knot-resolver/tinyweb/*; \
	  rm debian/tmp/usr/lib/knot-resolver/tinyweb/LICENSE; \
	  rm debian/tmp/usr/lib/knot-resolver/tinyweb/jquery.js; \
	  ln -s /usr/share/javascript/jquery/jquery.min.js debian/tmp/usr/lib/knot-resolver/tinyweb/jquery.js; \
	  rm debian/tmp/usr/lib/knot-resolver/tinyweb/d3.js; \
	  ln -s /usr/share/javascript/d3/d3.min.js debian/tmp/usr/lib/knot-resolver/tinyweb/d3.js; \
	fi
	# install custom config file
	install -d -m 755 debian/tmp/etc/knot-resolver/
	install -m 644 debian/kresd.conf debian/tmp/etc/knot-resolver/
	install -d -m 755 debian/tmp/usr/lib/knot-resolver/
	install -m 755 debian/init-d-script debian/tmp/usr/lib/knot-resolver/

override_dh_auto_test:
	:

override_dh_install:
	dh_install --fail-missing

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