Linkstamp the binaries when building with make.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 8 Aug 2020 16:51:45 +0000 (12:51 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 8 Aug 2020 16:57:14 +0000 (12:57 -0400)
Makefile
mailpopbox.go

index 6620afd6b11f107b651bb6758c4ca77ee2a54721..65608a721f3d7eefc75acdd4fdc82f7e33f87d9f 100644 (file)
--- 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)
index 50dc504193f8807f172d11395de4b9c83cd9677d..af2c3690d5b0c4f88d2fabb2f94ce435160466ab 100644 (file)
@@ -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)