From dfb5ee3dd41c1c4749d4e297f5187a5843ab65e3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 8 Aug 2020 12:51:45 -0400 Subject: [PATCH] Linkstamp the binaries when building with make. --- Makefile | 9 +++++++-- mailpopbox.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6620afd..65608a7 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,17 @@ .PHONY: all: coverage mac linux +DIRTY=$(shell [[ -z `git status --untracked-files=no --porcelain` ]] || echo "-dirty") +GITHASH=$(shell git log --pretty='%H' -1) + +LDFLAG=-ldflags "-X 'main.versionGit=$(GITHASH)$(DIRTY)'" + coverage: go test -coverprofile ./cover.out ./... go tool cover -html=cover.out -o cover.html mac: - GOOS=darwin GOARCH=amd64 go build -o mailpopbox-mac-amd64 + GOOS=darwin GOARCH=amd64 go build -o mailpopbox-mac-amd64 $(LDFLAG) linux: - GOOS=linux GOARCH=amd64 go build -o mailpopbox-linux-amd64 + GOOS=linux GOARCH=amd64 go build -o mailpopbox-linux-amd64 $(LDFLAG) diff --git a/mailpopbox.go b/mailpopbox.go index 50dc504..af2c369 100644 --- a/mailpopbox.go +++ b/mailpopbox.go @@ -14,12 +14,23 @@ import ( "go.uber.org/zap" ) +var ( + versionGit = "development" + versionNumber = "2.0.0" + versionString = "mailpopbox " + versionNumber + " (" + versionGit + ")\n" +) + func main() { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Usage: %s config.json\n", os.Args[0]) os.Exit(1) } + if os.Args[1] == "version" { + fmt.Print(versionString) + os.Exit(0) + } + configFile, err := os.Open(os.Args[1]) if err != nil { fmt.Fprintf(os.Stderr, "config file: %s\n", err) -- 2.22.5