#!/usr/bin/make -f

# Rebuild debian/control from debian/control.in
include /usr/share/postgresql-common/pgxs_debian_control.mk

SUPPORTED_VERSIONS = $(shell pg_buildext supported-versions)

%:
	dh $@ --with autoreconf

override_dh_auto_configure: configure
	set -e; for v in $(SUPPORTED_VERSIONS); do \
	  dh_auto_configure --builddirectory=debian/build-$$v -- \
	    --enable-extension \
	    PG_CONFIG=/usr/lib/postgresql/$$v/bin/pg_config; \
          for file in debian/*PGVERSION*; do \
	    sed -e "s:PGVERSION:$$v:g" "$$file" > "$$(echo "$$file" | sed -e "s:PGVERSION:$$v:g")"; \
	  done; \
	done

override_dh_auto_build:
	set -e; for v in $(SUPPORTED_VERSIONS); do \
	  $(MAKE) -C debian/build-$$v all; \
	done

override_dh_auto_clean:
	set -e; for v in $(SUPPORTED_VERSIONS); do \
	  dh_auto_clean --builddirectory=debian/build-$$v; \
	  rm -rf debian/install-$$v; \
	done
	rm -f debian/postgresql-*.*-debversion.*
	$(MAKE) -C test clean

override_dh_auto_install:
	set -e; for v in $(SUPPORTED_VERSIONS); do \
	  $(MAKE) -C debian/build-$$v DESTDIR=$(CURDIR)/debian/install-$$v install; \
	done

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_installdocs:
	dh_installdocs --all README.md
