#!/usr/bin/make -f

# verbose build output (antimake.mk)
export V=1

PG_CONFIG=pg_config
PGBINDIR=$(shell $(PG_CONFIG) --bindir)

%:
	dh $@

override_dh_auto_clean:
	[ ! -f config.mak ] || $(MAKE) distclean
	rm -f doc/pgbouncer.?

override_dh_autoreconf:
	dh_autoreconf ./autogen.sh

override_dh_auto_configure:
	dh_auto_configure -- \
		--bindir=/usr/sbin \
		--with-cares=yes \
		--with-pam

# "make check" broken in 1.12: https://github.com/pgbouncer/pgbouncer/issues/431
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C test check PATH=$(PGBINDIR):$(PATH)
endif

override_dh_auto_install:
	dh_auto_install --destdir=debian/pgbouncer
	rm -f $(addprefix $(CURDIR)/debian/pgbouncer/usr/share/doc/pgbouncer/,pgbouncer.ini userlist.txt)
	mkdir -p $(CURDIR)/debian/pgbouncer/etc/pgbouncer
	touch $(CURDIR)/debian/pgbouncer/etc/pgbouncer/userlist.txt

override_dh_installinit:
	dh_installinit -R
