#!/usr/bin/make -f

include /usr/share/postgresql-common/pgxs_debian_control.mk

%:
	dh $@ --buildsystem=meson

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

override_dh_auto_configure:
	dh_auto_configure -- -Dpg_config=/usr/lib/postgresql/18/bin/pg_config

override_dh_auto_install:
	dh_auto_install
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/postgresql/18/lib/pgxs/src/test/perl/PostgreSQL/Test
	install -m 644 ci_scripts/perl/PostgreSQL/Test/TdeCluster.pm $(CURDIR)/debian/tmp/usr/lib/postgresql/18/lib/pgxs/src/test/perl/PostgreSQL/Test/

override_dh_auto_test:

override_dh_installdocs:
	dh_installdocs --all README.*
