#!/usr/bin/make -f

PACKAGE := $(shell dh_listpackages)
PGVERSION = $(patsubst postgresql-%-plproxy,%,$(PACKAGE))

PG_CONFIG = /usr/lib/postgresql/$(PGVERSION)/bin/pg_config
# Server include must come before client include, because there could
# be mismatching libpq-dev and postgresql-server-dev installed.
PG_INC := -I$(shell $(PG_CONFIG) --includedir-server) -I$(shell $(PG_CONFIG) --includedir)


build: build-stamp
build-stamp:
	dh_testdir
	$(MAKE) PG_CONFIG=$(PG_CONFIG) PG_CPPFLAGS='$(PG_INC)'
	touch build-stamp


clean:
	dh_testdir
	dh_testroot
	$(MAKE) distclean PG_CONFIG=$(PG_CONFIG)
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) install PG_CONFIG=$(PG_CONFIG) DESTDIR=$(CURDIR)/debian/postgresql-$(PGVERSION)-plproxy
	rm -rf debian/postgresql-$(PGVERSION)-plproxy/usr/share/postgresql


binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs -a NEWS AUTHORS
	dh_install -a
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a


binary: binary-arch binary-indep


.PHONY: build clean binary-indep binary-arch binary
