#!/usr/bin/make -f

export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
export GOCACHE=/tmp/go-cache
export GOMODCACHE=/tmp/go-modcache
export HOME=/tmp/go-home

MAN_DIR := $(CURDIR)/debian/manpages
PKG     := atomgit.com/hust-open-atom-club/atomgit-cli/internal/version
UPSTREAM_VERSION := $(shell dpkg-parsechangelog -SVersion | sed 's/-[^-]*$$//')

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

override_dh_auto_build:
	go build -ldflags="-s -w \
	  -X $(PKG).Version=v$(UPSTREAM_VERSION) \
	  -X $(PKG).BuildDate=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)" \
	  -o ag-cli ./cmd/ag-cli

override_dh_auto_install:
	install -Dm755 ag-cli $(CURDIR)/debian/atomgit-cli/usr/bin/ag-cli

override_dh_installman:
	mkdir -p $(CURDIR)/debian/atomgit-cli/usr/share/man/man1
	cp $(MAN_DIR)/*.1 $(CURDIR)/debian/atomgit-cli/usr/share/man/man1/
	dh_installman

override_dh_auto_clean:
	dh_auto_clean
	rm -rf debian/atomgit-cli
	rm -f ag-cli

override_dh_auto_test:
	@echo "Skipping tests for build"

override_dh_golang:
	@echo "Skipping dh_golang"