#!/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

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

UPSTREAM_VERSION=$(shell echo ${DEB_VERSION_UPSTREAM} | sed -e 's/\+.*//')

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

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

%:
	dh $@

override_dh_clean:
	dh_clean debian/man/*.1

override_dh_auto_clean:
	dh_auto_clean || echo "Ignoring clean failure"

override_dh_auto_build-arch:
	# Create man pages 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

	dh_auto_build

override_dh_auto_install:
	dh_auto_install

	install -d $(CURDIR)/debian/tmp/usr/share/routino/www
	cp -r web/www/routino/* $(CURDIR)/debian/tmp/usr/share/routino/www

	install -d $(CURDIR)/debian/tmp/etc/routino-www
	install -m 644 debian/apache.conf $(CURDIR)/debian/tmp/etc/routino-www/apache.conf
	install -m 644 debian/avahi.conf $(CURDIR)/debian/tmp/etc/routino-www/routino-www.service
	install -m 644 debian/routino-www.desktop $(CURDIR)/debian/tmp/etc/routino-www/

	# Strip RPATH
	chrpath --delete debian/*/usr/bin/*

	# Remove upstream install documentation
	rm -f debian/*/usr/share/doc/routino/INSTALL.txt*
	rm -f debian/*/usr/share/doc/routino/INSTALL-MS-WIN.txt*

override_dh_makeshlibs:
	dh_makeshlibs -- -v$(UPSTREAM_VERSION)