#!/usr/bin/make -f
# -*- makefile -*-

DEB_VERSION := $(shell dpkg-parsechangelog --format rfc822 | grep-dctrl -ensVersion -S .)

%:
	dh  $@

override_dh_auto_clean:
	[ -e "Makefile" ] && make clean || true
	rm -f debian/check_multi.8 plugins/t/testopts.pm

override_dh_auto_configure:
	dh_auto_configure -- \
		--libexecdir=/usr/lib/nagios/plugins \
		--localstatedir=/var/cache/nagios3

override_dh_auto_install:
	make install        DESTDIR=$(CURDIR)/debian/nagios-plugin-check-multi
	make install-config DESTDIR=$(CURDIR)/debian/nagios-plugin-check-multi \
			    CFGDIR=/usr/share/doc/nagios-plugin-check-multi/examples
	find $(CURDIR)/debian/nagios-plugin-check-multi/usr/share/doc/nagios-plugin-check-multi/examples \
	     -type f -print0 | xargs -0 -r chmod 644
	# Make a man page
	help2man --no-info --section=8 --version-string="check_multi $(DEB_VERSION)" \
		-n "nagios plugin to combine multiple service checks in one run" \
		$(CURDIR)/debian/nagios-plugin-check-multi/usr/lib/nagios/plugins/check_multi \
		> $(CURDIR)/debian/check_multi.8
