Add --version / version with baked-in git commit

ldflags inject version, commit, and build date; a version subcommand
also reports go version and platform. Ends the which-binary-is-this
guessing after deploys.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Levi Woodard
2026-07-01 19:47:44 -05:00
parent eb05c48db8
commit 477246d574
3 changed files with 34 additions and 1 deletions

View File

@@ -1,7 +1,15 @@
BINARY := rtsp-streamer
PKG := ./cmd/rtsp-streamer
BINDIR := bin
LDFLAGS := -s -w
# Build metadata baked into the binary (see `rtsp-streamer version`).
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(DATE)
# Install location. Override with `make install PREFIX=/opt`.
PREFIX ?= /usr/local