#!/usr/bin/make -f

export LC_ALL=C.UTF-8
export LANG=C.UTF-8

export DH_GOLANG_EXCLUDES := iphlpapi

export UPSTREAM_VERSION=$(shell dpkg-parsechangelog --show-field Version | sed s/-.*//)

%:
	dh $@ --buildsystem=golang --with=golang

override_dh_auto_install:
	dh_auto_install -- --no-source
	install -m 644 pg_exporter.yml $(CURDIR)/debian/pg-exporter/etc/pg_exporter/
	install -m 644 config/* $(CURDIR)/debian/pg-exporter/usr/share/pg_exporter/
	install -m 640 package/pg_exporter.default $(CURDIR)/debian/pg-exporter/etc/default/pg_exporter
	install -m 644 package/pg_exporter.service $(CURDIR)/debian/pg-exporter/lib/systemd/system/
	help2man $(CURDIR)/debian/pg-exporter/usr/bin/pg_exporter --no-discard-stderr --no-info --version-string=$(UPSTREAM_VERSION) -i debian/pg_exporter.h2m | sed -e s/DESCRIPTION/SYNOPSIS/ -e s/SS.*/SH\ OPTIONS/ > debian/pg_exporter.1

override_dh_auto_test:
	# Go tests expect those data files in the obj-source directory
	cp -a pg_exporter.yml config legacy $(CURDIR)/obj-*/src/github.com/pgsty/pg_exporter/
	dh_auto_test
