#!/usr/bin/make -f

CLINAME := $(lastword $(shell grep "Package: pg-auto-failover-cli" debian/control))

include /usr/share/dpkg/pkg-info.mk
include /usr/share/postgresql-common/pgxs_debian_control.mk

export USE_SECURITY_FLAGS := 1

clean: debian/control

.PHONY: debian/control

override_dh_auto_build:
	echo "#define GIT_VERSION \"$(DEB_VERSION)\"" > src/bin/pg_autoctl/git-version.h
	+make -C $(shell pwd)/src/bin/pg_autoctl
	+pg_buildext build $(shell pwd)/src/monitor build-%v
	+make man

override_dh_auto_clean:
	+make -C $(shell pwd)/src/bin/pg_autoctl clean
	+pg_buildext clean $(shell pwd)/src/monitor build-%v

override_dh_auto_test:
	# nothing to do here, see debian/tests/* instead

override_dh_auto_install:
	+make -C $(shell pwd)/src/bin/pg_autoctl install \
		DESTDIR=$(CURDIR)/debian/${CLINAME} \
		BINDIR=/usr/bin
	+pg_buildext install $(shell pwd)/src/monitor build-%v postgresql-%v-auto-failover
	dh_installman docs/_build/man/*

%:
	dh $@
