#! /usr/bin/make -f

# export DH_VERBOSE=1

MAKEOPTS = INSTALLDIRS=vendor
LAST_CHANGE=$(shell dpkg-parsechangelog -S Date)
BUILD_DATE=$(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")

%:
	dh $@ --with systemd

override_dh_auto_build:
	# ./getversion reads RELEASE if it exists
	dpkg-parsechangelog | sed -n 's/^Version: //p' > RELEASE
	dh_auto_build -- $(MAKEOPTS)
	make -C doc html man SPHINXOPTS="-D today=\"$(BUILD_DATE)\""

override_dh_auto_install:
	dh_auto_install
	rm -rfv debian/tmp/usr/share/man/man1
	mv debian/tmp/etc/munin/munin-node.conf.sample debian/tmp/etc/munin/munin-node.conf
	sed -i -e '/^log_file/clog_file Sys::Syslog' debian/tmp/etc/munin/munin-node.conf
	sed -i -e '/^pid_file/cpid_file /run/munin-node.pid' debian/tmp/etc/munin/munin-node.conf
	mv debian/tmp/etc/munin/munin.conf.sample debian/tmp/etc/munin/munin.conf

override_dh_install:
	dh_install --fail-missing

# Override to add several init scripts
override_dh_installinit:
	dh_installinit -a
	dh_installinit --name=munin-httpd

override_dh_installdocs:
	dh_installdocs --link-doc=munin-common
	@ # Use the packaged javascript libraries
	if [ -d debian/munin-doc ]; then \
		rm -f debian/munin-doc/usr/share/doc/munin-doc/html/_static/jquery.js; \
		ln -s /usr/share/javascript/jquery/jquery.js \
			debian/munin-doc/usr/share/doc/munin-doc/html/_static/jquery.js; \
		rm -f debian/munin-doc/usr/share/doc/munin-doc/html/_static/underscore.js; \
		ln -s /usr/share/javascript/underscore/underscore.js \
			debian/munin-doc/usr/share/doc/munin-doc/html/_static/underscore.js; \
	fi
