Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (43 loc) · 2.01 KB
/
Copy pathMakefile
File metadata and controls
60 lines (43 loc) · 2.01 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
BINARY := ntpcl
BINDIR := builds
# Static binaries only. Go version comes from go.mod / local toolchain — not set here.
# Version is owned by the app (main.go); no -X ldflags injection.
export CGO_ENABLED := 0
LDFLAGS := -s -w
.DEFAULT_GOAL := build
.PHONY: help build all clean linux windows darwin-arm64 test fmt lint tidy run
help: ## Show available targets
@echo "Usage: make [target]"
@echo ""
@echo "All build targets produce static binaries (CGO_ENABLED=0)."
@echo "Go version is read from go.mod. App version is set in main.go."
@echo ""
@grep -E '^[a-zA-Z0-9_-]+:.*?##' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-16s %s\n", $$1, $$2}'
build: ## Static build for the current platform (-> ./ntpcl)
@echo "Static build: native -> ./$(BINARY)"
go build -ldflags="$(LDFLAGS)" -o $(BINARY) .
all: linux windows darwin-arm64 ## Static release builds: linux/amd64, windows/amd64, darwin/arm64
@echo "Static release builds complete in $(BINDIR)/"
$(BINDIR):
mkdir -p $(BINDIR)
linux: $(BINDIR) ## Static linux/amd64 (-> builds/ntpcl)
@echo "Static build: linux/amd64 -> $(BINDIR)/$(BINARY)"
GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BINDIR)/$(BINARY) .
windows: $(BINDIR) ## Static windows/amd64 (-> builds/ntpcl.exe)
@echo "Static build: windows/amd64 -> $(BINDIR)/$(BINARY).exe"
GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BINDIR)/$(BINARY).exe .
darwin-arm64: $(BINDIR) ## Static darwin/arm64 (-> builds/ntpcl_darwin)
@echo "Static build: darwin/arm64 -> $(BINDIR)/$(BINARY)_darwin"
GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(BINDIR)/$(BINARY)_darwin .
test: ## Run tests with race detector (CGO enabled for -race only)
CGO_ENABLED=1 go test -race ./...
fmt: ## Format Go source
go fmt ./...
lint: ## Run golangci-lint
golangci-lint run ./...
tidy: ## Run go mod tidy
go mod tidy
run: build ## Build and run ./ntpcl
./$(BINARY)
clean: ## Remove build artifacts
rm -rf $(BINDIR) $(BINARY) $(BINARY).exe $(BINARY)_darwin ntpcl-darwin