#!/usr/bin/make -f

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

%:
	dh $@

override_dh_auto_configure:
	cmake . -DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_C_FLAGS="$(CFLAGS)" \
		-DCMAKE_LD_FLAGS="-Wl,-z,defs" \
		-DCMAKE_CXX_FLAGS="$(CXXFLAGS)" \
		-DCMAKE_SKIP_RPATH=ON \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DWX_VERSION=$(shell wx-config --release) \
		-DwxWidgets_USE_STATIC=OFF \
		-DWX_STATIC=OFF \
		-DSTATIC_BUILD=OFF

# install extension files for the other PostgreSQL versions
override_dh_link:
	set -ex; \
	version=$$(basename debian/pgagent/usr/share/postgresql/*); \
	for v in $(shell pg_buildext supported-versions); do \
		test $$v = $$version && continue; \
		mkdir -p debian/pgagent/usr/share/postgresql/$$v/extension; \
		(cd debian/pgagent/usr/share/postgresql/$$v/extension && \
			ln -vs ../../$$version/extension/* .); \
	done

override_dh_gencontrol:
	dh_gencontrol -- -VPostgresql:Version="$(shell pg_buildext supported-versions)"

override_dh_auto_clean:
	dh_auto_clean
	# there is no "cmake clean" command
	rm -rf CMakeCache.txt CMakeFiles/ cmake_install.cmake CPack* install_manifest.txt Makefile
	$(MAKE) -C test clean
	rm -f test/pgagent.out
