#!/usr/bin/make -f

export DH_VERBOSE=1
export DH_GOPKG := github.com/prometheus/pushgateway

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')
BUILDDIR := $(shell perl -w -MDebian::Debhelper::Buildsystem::golang -e \
	'print Debian::Debhelper::Buildsystem::golang->new()->get_builddir()')
REV	:= $(DEBVERS)
BRANCH     := debian/sid
USER       := pkg-go-maintainers@lists.alioth.debian.org
HOSTNAME   := $(shell hostname -f)
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
BUILDFLAGS := -ldflags \
  " -X main.buildVersion $(VERSION)\
    -X main.buildRev $(REV)\
    -X main.buildBranch $(BRANCH)\
    -X main.buildUser $(USER)\
    -X main.buildDate $(BUILD_DATE)"

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

override_dh_auto_configure:
	dh_auto_configure -O--buildsystem=golang

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/pushgateway \
	    debian/$(DEBPKGNAME)/usr/bin/$(DEBPKGNAME)
	cp -va resources/* debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/web
	dh_link usr/share/javascript/bootstrap \
	    usr/share/$(DEBPKGNAME)/web/static/bootstrap


gen-orig-tgz:
	if [ ! -f ../$(DEBPKGNAME)_$(VERSION).orig.tar.gz ] ; then \
	    git archive --format=tar.gz --prefix=$(DEBPKGNAME)-$(VERSION)/ \
		upstream/$(VERSION) >../$(DEBPKGNAME)_$(VERSION).orig.tar.gz; \
	fi
