-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
53 lines (40 loc) · 1.53 KB
/
Copy pathMakefile
File metadata and controls
53 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# go-cli-template — shared build conventions for the m-cli Go toolchain.
# Every toolchain Go repo inherits this: static (CGO_ENABLED=0), -trimpath,
# version stamped via -ldflags, cross-compile matrix, lint, test, schema.
BIN ?= hello # demo binary name (rename per repo)
PKG := github.com/vista-cloud-dev/go-cli-template
LDPKG := $(PKG)/clikit
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-%d)
LDFLAGS := -s -w -X $(LDPKG).Version=$(VERSION) -X $(LDPKG).Commit=$(COMMIT) -X $(LDPKG).Date=$(DATE)
# Static, no-libc, reproducible (spec §10).
GOFLAGS := -trimpath
export CGO_ENABLED := 0
PLATFORMS := linux/amd64 linux/arm64 darwin/arm64 windows/amd64
.PHONY: all build run lint test tidy schema dist clean
all: lint test build
build:
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o dist/$(BIN) .
run: build
./dist/$(BIN) $(ARGS)
lint:
golangci-lint run ./...
test:
go test $(GOFLAGS) -race -cover ./...
tidy:
go mod tidy
# Emit the machine schema (the §5.5 contract) — also a CI conformance artifact.
schema: build
./dist/$(BIN) schema
# Cross-compile the pinned matrix into dist/.
dist:
@mkdir -p dist
@for p in $(PLATFORMS); do \
os=$${p%/*}; arch=$${p#*/}; ext=""; [ "$$os" = "windows" ] && ext=".exe"; \
echo " $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch go build $(GOFLAGS) -ldflags "$(LDFLAGS)" \
-o dist/$(BIN)-$$os-$$arch$$ext . ; \
done
clean:
rm -rf dist