From ce2faa39ebbedce19b67490ef9e96675c9d2b0f2 Mon Sep 17 00:00:00 2001 From: "Stephen McQuay (smcquay)" Date: Thu, 8 Mar 2018 16:09:51 -0800 Subject: [PATCH] Add automatic version to build output --- Makefile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0022abc..87f622b 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,22 @@ .PHONY: default default: bin/hw bin/hwc bin/hwl +VERSION := $(shell git describe --tags 2> /dev/null || echo "unreleased") +V_DIRTY := $(shell git describe --exact-match HEAD 2> /dev/null > /dev/null || echo "-unreleased") bin/hw: cmd/hw/main.go bin - GOOS=linux go build -v -o bin/hw ./cmd/hw + @GOOS=linux go build -ldflags \ + "-X mcquay.me/hw.Version=$(VERSION)$(V_DIRTY)" \ + -v -o bin/hw ./cmd/hw bin/hwc: cmd/hwc/main.go bin - GOOS=linux go build -v -o bin/hwc ./cmd/hwc + @GOOS=linux go build -ldflags \ + "-X mcquay.me/hw.Version=$(VERSION)$(V_DIRTY)" \ + -v -o bin/hwc ./cmd/hwc bin/hwl: cmd/hwl/main.go bin - GOOS=linux go build -v -o bin/hwl ./cmd/hwl + @GOOS=linux go build -ldflags \ + "-X mcquay.me/hw.Version=$(VERSION)$(V_DIRTY)" \ + -v -o bin/hwl ./cmd/hwl bin: mkdir bin