#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

PGVERSIONS = $(shell pg_buildext supported-versions)
COMMA = ,

%:
	dh $@

# install extension files for the other PostgreSQL versions
override_dh_link:
	set -ex; \
	version=$$(basename debian/pgagent/usr/share/postgresql/*); \
	for v in $(PGVERSIONS); do \
		test $$v = $$version && continue; \
		mkdir -p debian/pgagent/usr/share/postgresql/$$v/extension; \
		(cd debian/pgagent/usr/share/postgresql/$$v/extension && \
			ln -vs ../../$$version/extension/* .); \
	done
ifneq ($(DEB_HOST_ARCH), hurd-i386)
ifeq (, $(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	+PATH=$(CURDIR)/debian/pgagent/usr/bin:$(PATH) pg_buildext installcheck . test pgagent
endif
endif


override_dh_gencontrol:
	dh_gencontrol -- \
	  -VPostgresql:Recommends="$(patsubst %,postgresql-% |,$(PGVERSIONS))" \
	  -VPostgresql:Provides="$(patsubst %,postgresql-%-pgagent$(COMMA),$(PGVERSIONS))"

override_dh_auto_clean:
	dh_auto_clean
	# there is no "cmake clean" command
	rm -rf CMakeCache.txt CMakeFiles/ cmake_install.cmake CPack* install_manifest.txt Makefile
	[ ! -f test/Makefile ] || $(MAKE) -C test clean
