#!/usr/bin/make -f

# Include test fixtures.
export DH_GOLANG_INSTALL_EXTRA := testdata/

METAPKG := github.com/prometheus/common

DEBVERS    ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION    ?= $(shell echo '$(DEBVERS)' | sed 's/^[[:digit:]]*://; s/[-].*//')
DEBPKGNAME ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Source: //p')

REV        := $(DEBVERS)
BRANCH     := debian/sid
USER       := pkg-go-maintainers@lists.alioth.debian.org
HOSTNAME   := debian
BUILD_DATE := $(shell date --utc --date='$(DEBDATE)' +%Y%m%d-%H:%M:%S)
GO_VERSION := $(shell go version | sed 's/go version \(\S*\).*/\1/')
BUILDFLAGS := -ldflags \
  " -X $(METAPKG)/version.Version=$(VERSION)\
    -X $(METAPKG)/version.Revision=$(REV)\
    -X $(METAPKG)/version.Branch=$(BRANCH)\
    -X $(METAPKG)/version.BuildUser=$(USER)\
    -X $(METAPKG)/version.BuildDate=$(BUILD_DATE)\
    -X $(METAPKG)/version.GoVersion=$(GO_VERSION)"

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

override_dh_auto_build:
	dh_auto_build -O--buildsystem=golang -- $(BUILDFLAGS)

override_dh_auto_install:
	dh_auto_install
	# we don't want the golang source (yet?)
	rm -r debian/$(DEBPKGNAME)/usr/share/gocode
	# Rename the binary to match the debian package.
	mv -v debian/$(DEBPKGNAME)/usr/bin/blackbox_exporter \
            debian/$(DEBPKGNAME)/usr/bin/$(DEBPKGNAME)
	install -m 644 -D -v blackbox.yml debian/$(DEBPKGNAME)/etc/prometheus/blackbox.yml
