Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
209 lines (177 loc) · 8.02 KB
/
Copy pathMakefile
File metadata and controls
209 lines (177 loc) · 8.02 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# List of applications to build. The name must match the folder in ./cmd/
BINS := zancudo gen_certs
# Single source of truth for release version (read by both binaries via -ldflags; see cmd/*/main).
VERSION_FILE := VERSION
VERSION := $(shell if test -f '$(VERSION_FILE)'; then head -n1 '$(VERSION_FILE)' | tr -d '\r\n'; fi)
ifeq ($(strip $(VERSION)),)
VERSION := dev
endif
GO_LDFLAGS := -ldflags "-X main.version=$(VERSION)"
# Base output directories
BIN_DIR := bin
DIST_DIR := dist
# Platform-specific output directories
LINUX_AMD64_DIR := $(BIN_DIR)/linux_amd64
WINDOWS_DIR := $(BIN_DIR)/windows_amd64
MACOS_AMD64_DIR := $(BIN_DIR)/darwin_amd64
MACOS_ARM64_DIR := $(BIN_DIR)/darwin_arm64
# Platform names for zip files
LINUX_AMD64_PLATFORM := linux_amd64
WINDOWS_PLATFORM := windows_amd64
MACOS_AMD64_PLATFORM := darwin_amd64
MACOS_ARM64_PLATFORM := darwin_arm64
# Zip file names (release artifacts under dist/)
LINUX_AMD64_ZIP := $(DIST_DIR)/zancudo-$(LINUX_AMD64_PLATFORM).zip
WINDOWS_ZIP := $(DIST_DIR)/zancudo-$(WINDOWS_PLATFORM).zip
MACOS_AMD64_ZIP := $(DIST_DIR)/zancudo-$(MACOS_AMD64_PLATFORM).zip
MACOS_ARM64_ZIP := $(DIST_DIR)/zancudo-$(MACOS_ARM64_PLATFORM).zip
# Define full paths for all target binaries
LINUX_AMD64_BINS := $(addprefix $(LINUX_AMD64_DIR)/, $(BINS))
WINDOWS_BINS := $(addprefix $(WINDOWS_DIR)/, $(addsuffix .exe, $(BINS)))
MACOS_AMD64_BINS := $(addprefix $(MACOS_AMD64_DIR)/, $(BINS))
MACOS_ARM64_BINS := $(addprefix $(MACOS_ARM64_DIR)/, $(BINS))
# Additional files to include in releases
RELEASE_FILES := README.md ZANCUDO.png LICENSE $(VERSION_FILE)
.DEFAULT_GOAL := help
.PHONY: help all clean linux windows macos zips linux-zip windows-zip macos-zip \
ci-tools ci-check ci-fix _ci_binaries update
# ANSI colors: used only by the `help` target (bold cyan title, yellow sections, green commands, dim hints).
help:
@printf '%b\n' '\033[1;36mZancudo Makefile\033[0m' '' \
'\033[2mRunning make with no target shows this help (default).\033[0m' '' \
'\033[1;33mRelease builds\033[0m \033[2m(binaries under bin/, zips under dist/):\033[0m' \
' \033[1;32mmake all\033[0m Same as zips: all platform zips + binaries' \
' \033[1;32mmake zips\033[0m linux-zip, windows-zip, macos-zip' \
' \033[1;32mmake linux\033[0m Linux amd64 binaries only' \
' \033[1;32mmake windows\033[0m Windows amd64 binaries only' \
' \033[1;32mmake macos\033[0m Mac OS amd64 + arm64 binaries only' \
' \033[1;32mmake linux-zip\033[0m Linux zip only (needs linux + README assets)' \
' \033[1;32mmake windows-zip\033[0m Windows zip only' \
' \033[1;32mmake macos-zip\033[0m Mac OS zips only' '' \
'\033[1;33mCode quality\033[0m' \
' \033[1;32mmake ci-tools\033[0m Install goimports, golangci-lint, govulncheck to GOBIN/GOPATH/bin' \
' \033[1;32mmake ci-check\033[0m goimports -l, golangci-lint --enable=gosec, govulncheck per module' \
' \033[1;32mmake ci-fix\033[0m goimports -w, golangci-lint --fix, then govulncheck (vulns: report only)' '' \
'\033[1;33mOther\033[0m' \
' \033[1;32mmake update\033[0m Update Go dependencies' \
' \033[1;32mmake clean\033[0m Remove bin/, dist/, and generated cert files in repo root' ''
# --- CI parity (same checks as .github/workflows/ci.yml) ---
GO_MODULES := $(addprefix cmd/,$(BINS))
GOPATH := $(shell go env GOPATH)
GOBIN := $(shell go env GOBIN)
CI_BIN := $(if $(strip $(GOBIN)),$(GOBIN),$(GOPATH)/bin)
GOIMPORTS := $(CI_BIN)/goimports
GOLANGCI_LINT := $(CI_BIN)/golangci-lint
GOVULNCHECK := $(CI_BIN)/govulncheck
GOIMPORTS_LOCAL := github.com/VerSprite
# golangci-lint must be built with a toolchain >= the `go` line in cmd/zancudo/go.mod.
CI_GO_TOOLCHAIN := go$(shell awk '/^go / { print $$2; exit }' cmd/zancudo/go.mod)
_ci_binaries:
@test -x '$(GOIMPORTS)' && test -x '$(GOLANGCI_LINT)' && test -x '$(GOVULNCHECK)' || \
(echo 'Missing tools; install with: make ci-tools' >&2; exit 1)
ci-tools:
cd cmd/zancudo && GOTOOLCHAIN=$(CI_GO_TOOLCHAIN) go install golang.org/x/tools/cmd/goimports@latest
cd cmd/zancudo && GOTOOLCHAIN=$(CI_GO_TOOLCHAIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
cd cmd/zancudo && GOTOOLCHAIN=$(CI_GO_TOOLCHAIN) go install golang.org/x/vuln/cmd/govulncheck@latest
# Verify: goimports, golangci-lint (incl. gosec), govulncheck per module under cmd/*
ci-check: _ci_binaries
@set -e; \
for m in $(GO_MODULES); do \
echo "== goimports $$m =="; \
out="$$( cd $$m && '$(GOIMPORTS)' -local $(GOIMPORTS_LOCAL) -l . )"; \
if [ -n "$$out" ]; then \
echo 'The following files need goimports (or gofmt):'; \
echo "$$out"; \
exit 1; \
fi; \
done
@set -e; \
for m in $(GO_MODULES); do \
echo "== golangci-lint $$m =="; \
( cd $$m && '$(GOLANGCI_LINT)' run --enable=gosec ); \
done
@set -e; \
for m in $(GO_MODULES); do \
echo "== govulncheck $$m =="; \
( cd $$m && '$(GOVULNCHECK)' ./... ); \
done
@echo 'ci-check: OK'
# Auto-fix: goimports -w and golangci-lint --fix; then govulncheck (check only, no auto-fix)
ci-fix: _ci_binaries
@set -e; \
for m in $(GO_MODULES); do \
echo "== goimports -w $$m =="; \
( cd $$m && '$(GOIMPORTS)' -local $(GOIMPORTS_LOCAL) -w . ); \
done
@set -e; \
for m in $(GO_MODULES); do \
echo "== golangci-lint --fix $$m =="; \
( cd $$m && '$(GOLANGCI_LINT)' run --enable=gosec --fix ); \
done
@set -e; \
for m in $(GO_MODULES); do \
echo "== govulncheck $$m =="; \
( cd $$m && '$(GOVULNCHECK)' ./... ); \
done
@echo 'ci-fix: OK'
# Build all targets and create zip files
all: zips
# Create zip files for all platforms
zips: linux-zip windows-zip macos-zip
# Build for each platform
linux: $(LINUX_AMD64_BINS)
windows: $(WINDOWS_BINS)
macos: $(MACOS_AMD64_BINS) $(MACOS_ARM64_BINS)
# Create zip files for each platform
linux-zip: $(LINUX_AMD64_ZIP)
windows-zip: $(WINDOWS_ZIP)
macos-zip: $(MACOS_AMD64_ZIP) $(MACOS_ARM64_ZIP)
# --- Build Rules ---
# Rule for Linux amd64 binaries
$(LINUX_AMD64_BINS): $(LINUX_AMD64_DIR)/%: | $(LINUX_AMD64_DIR)
@echo "Building Linux amd64 binary for $*..."
(cd ./cmd/$* && GOOS=linux GOARCH=amd64 go build $(GO_LDFLAGS) -o ../../$@ .)
# Rule for Windows binaries
$(WINDOWS_BINS): $(WINDOWS_DIR)/%.exe: | $(WINDOWS_DIR)
@echo "Building Windows binary for $*..."
(cd ./cmd/$* && GOOS=windows GOARCH=amd64 go build $(GO_LDFLAGS) -o ../../$@ .)
# Rule for macOS amd64 binaries
$(MACOS_AMD64_BINS): $(MACOS_AMD64_DIR)/%: | $(MACOS_AMD64_DIR)
@echo "Building macOS amd64 binary for $*..."
(cd ./cmd/$* && GOOS=darwin GOARCH=amd64 go build $(GO_LDFLAGS) -o ../../$@ .)
# Rule for macOS arm64 binaries
$(MACOS_ARM64_BINS): $(MACOS_ARM64_DIR)/%: | $(MACOS_ARM64_DIR)
@echo "Building macOS arm64 binary for $*..."
(cd ./cmd/$* && GOOS=darwin GOARCH=arm64 go build $(GO_LDFLAGS) -o ../../$@ .)
# --- Zip Creation Rules ---
# Rule for Linux amd64 zip
$(LINUX_AMD64_ZIP): $(LINUX_AMD64_BINS) $(RELEASE_FILES) | $(DIST_DIR)
@echo "Creating Linux amd64 release zip $(LINUX_AMD64_ZIP)..."
zip -j $(LINUX_AMD64_ZIP) $(LINUX_AMD64_BINS) $(RELEASE_FILES)
# Rule for Windows zip
$(WINDOWS_ZIP): $(WINDOWS_BINS) $(RELEASE_FILES) | $(DIST_DIR)
@echo "Creating Windows release zip $(WINDOWS_ZIP)..."
zip -j $(WINDOWS_ZIP) $(WINDOWS_BINS) $(RELEASE_FILES)
# Rule for macOS amd64 zip
$(MACOS_AMD64_ZIP): $(MACOS_AMD64_BINS) $(RELEASE_FILES) | $(DIST_DIR)
@echo "Creating macOS amd64 release zip $(MACOS_AMD64_ZIP)..."
zip -j $(MACOS_AMD64_ZIP) $(MACOS_AMD64_BINS) $(RELEASE_FILES)
# Rule for macOS arm64 zip
$(MACOS_ARM64_ZIP): $(MACOS_ARM64_BINS) $(RELEASE_FILES) | $(DIST_DIR)
@echo "Creating macOS arm64 release zip $(MACOS_ARM64_ZIP)..."
zip -j $(MACOS_ARM64_ZIP) $(MACOS_ARM64_BINS) $(RELEASE_FILES)
# Create the output directories
$(LINUX_AMD64_DIR) $(WINDOWS_DIR) $(MACOS_AMD64_DIR) $(MACOS_ARM64_DIR) $(DIST_DIR):
mkdir -p $@
# --- Cleanup ---
clean:
@echo "Cleaning up generated files..."
rm -rf $(BIN_DIR) $(DIST_DIR)
rm -f proxy.crt proxy.key client.crt client.key ca.crt ca.key
@echo "Done."
# --- Maintenance ---
update:
set -e; for d in cmd/*; do ( \
cd "$$d" && echo "Updating: $$d" && \
go mod tidy && go get -u ./... && go mod tidy \
); done