-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (106 loc) · 3.19 KB
/
Copy pathMakefile
File metadata and controls
124 lines (106 loc) · 3.19 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Makefile for plus3.
#
# Thin wrappers over the Go toolchain and the existing build.sh / release.sh
# scripts, so there is a single source of truth for each operation. The version
# is read from the VERSION file and injected at build time, matching build.sh.
PROJECT_NAME := plus3
MODULE := github.com/ha1tch/plus3
VERSION := $(shell tr -d ' \t\r\n' < VERSION)
LDFLAGS := -X $(MODULE)/internal/version.Version=$(VERSION)
BIN := plus3
DISTDIR := dist
# Cross-compile targets (mirrors .github/workflows/release.yml).
PLATFORMS := \
linux/amd64 linux/arm64 \
darwin/amd64 darwin/arm64 \
windows/amd64 \
freebsd/amd64 freebsd/arm64 \
openbsd/amd64 openbsd/arm64 \
netbsd/amd64
.DEFAULT_GOAL := build
# Build the CLI binary into the current directory, with the version injected.
.PHONY: build
build:
@echo "Building $(PROJECT_NAME) $(VERSION)..."
go build -ldflags "$(LDFLAGS)" -o $(BIN) ./cmd
# Run the CLI (default help output).
.PHONY: run
run: build
./$(BIN)
# Run the CLI with arguments: make run-with-args ARGS='list disk.dsk'
.PHONY: run-with-args
run-with-args: build
./$(BIN) $(ARGS)
# Run the test suite.
.PHONY: test
test:
go test ./... -count=1
# Run go vet.
.PHONY: vet
vet:
go vet ./...
# Vet and test together (the CI quality gate).
.PHONY: check
check: vet test
# Format all Go source (gofmt, matching the rest of the project).
.PHONY: fmt
fmt:
gofmt -w .
# Verify module checksums (catches an incomplete go.sum).
.PHONY: verify
verify:
go mod download
go mod verify
# Tidy module dependencies.
.PHONY: tidy
tidy:
go mod tidy
# Cross-compile binaries for all release platforms into dist/.
.PHONY: cross
cross:
@mkdir -p $(DISTDIR)
@for platform in $(PLATFORMS); do \
os=$${platform%/*}; arch=$${platform#*/}; \
ext=""; [ "$$os" = "windows" ] && ext=".exe"; \
out="$(DISTDIR)/$(BIN)-$$os-$$arch$$ext"; \
echo " building $$out"; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch \
go build -ldflags "$(LDFLAGS)" -o "$$out" ./cmd || exit 1; \
done
# Run the full release pipeline (validate -> build -> verify -> package).
.PHONY: release
release:
sh release.sh $(VERSION)
# Remove build artefacts.
.PHONY: clean
clean:
@echo "Cleaning up..."
rm -f $(BIN)
rm -rf $(DISTDIR)
rm -f plus3-v*.zip
# Clean and tidy the environment.
.PHONY: reset
reset: clean tidy
# Print the current version.
.PHONY: version
version:
@echo $(VERSION)
# Help.
.PHONY: help
help:
@echo "Makefile for $(PROJECT_NAME)"
@echo "Targets:"
@echo " build - Build the binary (version injected) into ./$(BIN)"
@echo " run - Build and run (help output)"
@echo " run-with-args - Build and run with ARGS='<args>'"
@echo " test - Run the test suite"
@echo " vet - Run go vet"
@echo " check - Vet and test (CI quality gate)"
@echo " fmt - Format source with gofmt"
@echo " verify - Verify module checksums"
@echo " tidy - Tidy module dependencies"
@echo " cross - Cross-compile all release platforms into dist/"
@echo " release - Run the full release pipeline"
@echo " clean - Remove build artefacts"
@echo " reset - Clean and tidy"
@echo " version - Print the current version"