#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk

# Include test fixtures.
export DH_GOLANG_INSTALL_EXTRA := config/testdata

METAPKG := github.com/prometheus/common

BRANCH     := debian/sid
USER       := pkg-go-maintainers@lists.alioth.debian.org
BUILD_DATE := $(shell date --utc --date='@$(SOURCE_DATE_EPOCH)' \
    +%Y%m%d-%H:%M:%S)
GO_VERSION := $(shell go version | sed 's/go version \(\S*\).*/\1/')
BUILDFLAGS := -ldflags \
  " -X $(METAPKG)/version.Version=$(DEB_VERSION_UPSTREAM)\
    -X $(METAPKG)/version.Revision=$(DEB_VERSION)\
    -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

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

override_dh_auto_install:
	dh_auto_install -- --no-source
	# Rename the binary to match the debian package.
	mv -v debian/$(DEB_SOURCE)/usr/bin/blackbox_exporter \
            debian/$(DEB_SOURCE)/usr/bin/$(DEB_SOURCE)
	install -m 644 -D -v blackbox.yml \
	    debian/$(DEB_SOURCE)/etc/prometheus/blackbox.yml
