#!/usr/bin/make -f

export DH_VERBOSE = 1

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

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

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS to fix #1013073
export DEB_CFLAGS_MAINT_APPEND  = -Wno-error=format-truncation= -Wno-error=format-overflow=
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Current upstream tree missed a few man pages for sect 8. It is more convenient
# to regenerate them once and use at build time.
gen-manpages:
	rm -f $(CURDIR)/debian/man/*
	find $(CURDIR) -name '*.8.xml' -exec cp {} $(CURDIR)/debian/man/. \;
	for f in $(CURDIR)/debian/man/*.xml; do xsltproc -o $(CURDIR)/debian/man/`basename $$f .xml` \
		--xinclude --nonet /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl $$f || true; done
	rm -f $(CURDIR)/debian/man/*.xml

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure
	for f in `find $(CURDIR) -name '*.8.xml'`; \
		do d=`dirname $$f`; n=`basename $$f .xml`; [ -f $(CURDIR)/$$d/$$n ] || cp -f $(CURDIR)/debian/man/$$n $$d/.; done 

override_dh_auto_clean:
	dh_auto_clean
	for f in `find $(CURDIR) -name '*.8.xml'|egrep -v "yppasswdd.8|makedbm.8|ypxfrd.8|mknetid.8"`; \
		do d=`dirname $$f`; n=`basename $$f .xml`; rm -f $$d/$$n; done 

override_dh_auto_install:
	dh_auto_install --destdir=$(CURDIR)/debian/tmp

PKG=$(shell dpkg-parsechangelog --format=rfc822|grep Source|cut -d\  -f2)

override_dh_installinit:
	dh_installinit -p$(PKG) --name=$(PKG) $(PKG).init
	dh_installinit -p$(PKG) --name=yppasswdd $(PKG).init
	dh_installinit -p$(PKG) --name=ypxfrd $(PKG).init

override_dh_installsystemd:
	dh_installsystemd -p$(PKG) --name=$(PKG) --no-enable --no-start $(PKG).service
	dh_installsystemd -p$(PKG) --name=yppasswdd --no-enable --no-start yppasswdd.service
	dh_installsystemd -p$(PKG) --name=ypxfr_1perday --no-enable --no-start ypxfr_1perday.service
	dh_installsystemd -p$(PKG) --name=ypxfr_1perhour --no-enable --no-start ypxfr_1perhour.service
	dh_installsystemd -p$(PKG) --name=ypxfr_2perday --no-enable --no-start ypxfr_2perday.service
	dh_installsystemd -p$(PKG) --name=ypxfrd --no-enable --no-start ypxfrd.service
	dh_installsystemd -p$(PKG) --name=ypxfr_1perday --no-enable --no-start ypxfr_1perday.timer
	dh_installsystemd -p$(PKG) --name=ypxfr_1perhour --no-enable --no-start ypxfr_1perhour.timer
	dh_installsystemd -p$(PKG) --name=ypxfr_2perday --no-enable --no-start ypxfr_2perday.timer

.PHONY: gen-manpages
