#!/usr/bin/make -f

export USE_PGXS=1
PG_VERSION := 17
PG_CONFIG := /usr/lib/postgresql/$(PG_VERSION)/bin/pg_config

%:
	dh $@

override_dh_auto_build:
	$(MAKE) PG_CONFIG=$(PG_CONFIG)

override_dh_auto_test:
	# nothing to do here

override_dh_auto_install:
	$(MAKE) install PG_CONFIG=$(PG_CONFIG) DESTDIR=$(CURDIR)/debian/percona-postgresql-$(PG_VERSION)-pgaudit

override_dh_installdocs:
	dh_installdocs --all README.*

override_dh_auto_clean:
	$(MAKE) clean PG_CONFIG=$(PG_CONFIG) || true

override_dh_builddeb:
	dh_builddeb -- -Zgzip
	# Ubuntu's dh_builddeb renames auto-dbgsym .deb -> .ddeb (so they would be
	# routed to ddebs.ubuntu.com) and records the renamed name in debian/files.
	# OBS's apt-repo publisher only indexes *.deb, so undo both: rename the
	# files on disk AND rewrite debian/files, otherwise dpkg-genbuildinfo /
	# dpkg-genchanges fail to fstat the .ddeb names listed there. No-op on
	# Debian.
	if ls ../*-dbgsym_*.ddeb >/dev/null 2>&1; then \
	  for f in ../*-dbgsym_*.ddeb; do \
	    mv -v "$$f" "$${f%.ddeb}.deb"; \
	  done; \
	  sed -i 's/\(-dbgsym_[^ ]*\)\.ddeb/\1.deb/g' debian/files; \
	fi
