#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Conditionals for libsystemd and libcap
include /usr/share/dpkg/architecture.mk
ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
with_systemd = --without-systemd
with_libcap = --without-libcap
enable_mrdisc = --disable-mrdisc
else
with_systemd = --with-systemd
with_libcap = --with-libcap
enable_mrdisc = --enable-mrdisc
endif

# See dpkg-buildflags(1) manpage
export DEB_CFLAGS_MAINT_APPEND = -Werror -ggdb
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Upstream version of the package
DEB_UPSTREAM_VERSION := $(shell dpkg-parsechangelog -S Version|cut -d- -f1)

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		--bindir=/usr/sbin \
		$(with_systemd) \
		$(with_libcap) \
		$(enable_mrdisc)

execute_after_dh_auto_build:
	help2man --name=smcroute \
		--section=8 \
		--no-info \
		--help-option=-h \
		--version-string=$(DEB_UPSTREAM_VERSION) \
		--output=smcroute.8 \
		./smcroute

override_dh_auto_install:
	dh_auto_install
	# delete smcroute.conf from /usr/share/doc/smcroute/ as this is also
	# installed by dh_installexamples to the proper examples/ subdirectory
	find debian/ -name smcroute.conf -type f -delete -printf "Removing %p\n"
	# delete duplicate license file /usr/share/doc/smcroute/COPYING
	rm -v debian/smcroute/usr/share/doc/smcroute/COPYING

ifeq ($(with_systemd),--with-systemd)
override_dh_installsystemd:
	dh_installsystemd
	dh_installsystemd --name=smcroute-helper
endif
