#!/usr/bin/make -f

#export DH_VERBOSE=1

export DH_GOLANG_BUILDPKG=github.com/icinga/icingadb/cmd/icingadb \
                          github.com/icinga/icingadb/cmd/icingadb-migrate

export GO111MODULE=on

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

BUILD_DATE=$(shell LC_ALL=C date -u "+%d %B %Y" -d "@$(SOURCE_DATE_EPOCH)")

MANPAGES := $(wildcard debian/man/*.*.xml)

%:
	dh $@ --builddirectory=_build --buildsystem=golang

execute_after_dh_auto_configure:
	(mkdir -p _build/pkg && cd _build/pkg && ln -s ../../dependencies/pkg/* .)

execute_before_dh_auto_build:
	# Create man page from DocBook XML
	for x in $(MANPAGES) ; do \
	    docbook2x-man --string-param header-3="$(BUILD_DATE)" $$x ; \
	    mv `basename $$x | sed 's/.xml$$//'` `dirname $$x` ; \
	done

override_dh_auto_build:
	DH_VERBOSE=1 dh_auto_build

override_dh_auto_install:
	dh_auto_install -- --no-source

	mv debian/icingadb/usr/bin debian/icingadb/usr/sbin

override_dh_installsystemd:
	dh_installsystemd --no-enable --no-start

override_dh_compress:
	dh_compress -X.md