-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
81 lines (63 loc) · 2.9 KB
/
Copy pathMakefile
File metadata and controls
81 lines (63 loc) · 2.9 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
BINARY := nr-tf-util
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -s -w"
CMD := ./cmd
.PHONY: all build clean dist dist-linux dist-mac dist-windows test vet lint help run
# ── Local build ───────────────────────────────────────────────────────────────
## all: build for the current platform
all: build
## build: compile into bin/
build:
@mkdir -p bin
go build $(LDFLAGS) -o bin/$(BINARY) $(CMD)
@echo "Built → bin/$(BINARY)"
## run: build and run (pass args via ARGS="...")
run: build
./bin/$(BINARY) $(ARGS)
# ── Cross-compile ─────────────────────────────────────────────────────────────
## dist: build release binaries for all platforms into dist/
dist: dist-linux dist-mac dist-windows
@echo ""
@echo "Release binaries:"
@ls -lh dist/
## dist-linux: linux/amd64 and linux/arm64
dist-linux:
@mkdir -p dist
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY)-linux-amd64 $(CMD)
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY)-linux-arm64 $(CMD)
@echo "Built linux binaries"
## dist-mac: darwin/amd64 (Intel) and darwin/arm64 (Apple Silicon)
dist-mac:
@mkdir -p dist
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY)-darwin-amd64 $(CMD)
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY)-darwin-arm64 $(CMD)
@echo "Built macOS binaries"
## dist-windows: windows/amd64 and windows/arm64
dist-windows:
@mkdir -p dist
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY)-windows-amd64.exe $(CMD)
GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY)-windows-arm64.exe $(CMD)
@echo "Built Windows binaries"
# ── Quality ───────────────────────────────────────────────────────────────────
## test: run all tests with race detector
test:
go test -race -v ./...
## test-cover: run tests and produce a coverage report
test-cover:
go test -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
## vet: run go vet
vet:
go vet ./...
## lint: run golangci-lint (must be installed separately: https://golangci-lint.run)
lint:
golangci-lint run ./...
# ── Housekeeping ──────────────────────────────────────────────────────────────
## clean: remove build artefacts
clean:
rm -rf bin/ dist/ coverage.out
## help: list available targets
help:
@echo "Usage: make <target>"
@echo ""
@grep -E '^## ' Makefile | sed 's/## / /'