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

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

PKGNAME = monitoring-plugins-contrib
PLUGINS := $(shell find $(CURDIR) -mindepth 1 -maxdepth 1 -name .git -prune -o -name redhat -prune -o -name .pc -prune -o -name debian -prune -o -type d -printf '%f\n' | sort)

override_dh_auto_build:
	dh_auto_build
	$(PACKAGING_HELPER) --generate-readme

PACKAGING_HELPER = /usr/bin/python3 $(CURDIR)/debian/packaging-helper.py


clean: debian/copyright debian/control debian/tests/control
	dh $@ --with quilt
	rm -f debian/README.Debian.plugins

CONTROL_FILES := $(shell for p in $(PLUGINS); do echo $$p/control; done)
COPYRIGHT_FILES := $(shell for p in $(PLUGINS); do echo $$p/copyright; done)
TESTS_FILES := $(wildcard */tests)
debian/copyright: debian/copyright.in debian/packaging-helper.py $(CONTROL_FILES) $(COPYRIGHT_FILES)
	$(PACKAGING_HELPER) --copyright
	-if [ -d .git ]; then git add $@; git commit -m 'Auto update of $@' $@; fi

debian/control: debian/control.in debian/packaging-helper.py $(CONTROL_FILES)
	$(PACKAGING_HELPER) --control
	-if [ -d .git ]; then git add $@; git commit -m 'Auto update of $@' $@; fi

debian/tests/control: debian/packaging-helper.py $(TESTS_FILES)
	$(PACKAGING_HELPER) --tests
	-if [ -d .git ]; then git add $@; git commit -m 'Auto update of $@' $@; fi


%:
	dh $@ --with quilt


watch:
	@$(PACKAGING_HELPER) --watch

.PHONY: watch
