Debian Codegraph @

Makefile

raw
1 NEBULA_CMD_PATH = "./cmd/nebula"
2 CGO_ENABLED = 0
3 export CGO_ENABLED
4
5 # Set up OS specific bits
6 ifeq ($(OS),Windows_NT)
7 NEBULA_CMD_SUFFIX = .exe
8 NULL_FILE = nul
9 # RIO on windows does pointer stuff that makes go vet angry
10 VET_FLAGS = -unsafeptr=false
11 else
12 NEBULA_CMD_SUFFIX =
13 NULL_FILE = /dev/null
14 endif
15
16 # Only defined the build number if we haven't already
17 ifndef BUILD_NUMBER
18 ifeq ($(shell git describe --exact-match 2>$(NULL_FILE)),)
19 BUILD_NUMBER = $(shell git describe --abbrev=0 --match "v*" | cut -dv -f2)-$(shell git branch --show-current)-$(shell git describe --long --dirty | cut -d- -f2-)
20 else
21 BUILD_NUMBER = $(shell git describe --exact-match --dirty | cut -dv -f2)
22 endif
23 endif
24
25 DOCKER_IMAGE_REPO ?= nebulaoss/nebula
26 DOCKER_IMAGE_TAG ?= latest
27
28 LDFLAGS = -X main.Build=$(BUILD_NUMBER)
29
30 ALL_LINUX = linux-amd64 \
31 linux-386 \
32 linux-ppc64le \
33 linux-arm-5 \
34 linux-arm-6 \
35 linux-arm-7 \
36 linux-arm64 \
37 linux-mips \
38 linux-mipsle \
39 linux-mips64 \
40 linux-mips64le \
41 linux-mips-softfloat \
42 linux-riscv64 \
43 linux-loong64
44
45 ALL_FREEBSD = freebsd-amd64 \
46 freebsd-arm64
47
48 ALL_OPENBSD = openbsd-amd64 \
49 openbsd-arm64
50
51 ALL_NETBSD = netbsd-amd64 \
52 netbsd-arm64
53
54 ALL = $(ALL_LINUX) \
55 $(ALL_FREEBSD) \
56 $(ALL_OPENBSD) \
57 $(ALL_NETBSD) \
58 darwin-amd64 \
59 darwin-arm64 \
60 windows-amd64 \
61 windows-arm64
62
63 # Cross-build shards used by .github/workflows/test.yml — same as ALL_*
64 # but with the arch that has a native CI runner removed, so the cross-build
65 # job is not duplicating coverage the native test jobs already give.
66 ALL_CROSS_LINUX = $(filter-out linux-amd64,$(ALL_LINUX))
67
68 # ALL_CROSS_LINUX further split into family sub-shards so each can run on
69 # its own CI runner in parallel. Union of the three must equal
70 # ALL_CROSS_LINUX; adding a new linux arch goes into the matching family.
71 ALL_CROSS_LINUX_ARM = linux-arm-5 linux-arm-6 linux-arm-7 linux-arm64
72 ALL_CROSS_LINUX_MIPS = linux-mips linux-mipsle linux-mips64 linux-mips64le linux-mips-softfloat
73 ALL_CROSS_LINUX_OTHER = linux-386 linux-ppc64le linux-riscv64 linux-loong64
74
75 e2e:
76 $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
77
78 e2ev: TEST_FLAGS += -v
79 e2ev: e2e
80
81 e2evv: TEST_ENV += TEST_LOGS=1
82 e2evv: e2ev
83
84 e2evvv: TEST_ENV += TEST_LOGS=2
85 e2evvv: e2ev
86
87 e2evvvv: TEST_ENV += TEST_LOGS=3
88 e2evvvv: e2ev
89
90 e2e-bench: TEST_FLAGS = -bench=. -benchmem -run=^$
91 e2e-bench: e2e
92
93 DOCKER_BIN = build/linux-amd64/nebula build/linux-amd64/nebula-cert
94
95 all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
96
97 all-linux: $(ALL_LINUX:%=build/%/nebula) $(ALL_LINUX:%=build/%/nebula-cert)
98
99 all-freebsd: $(ALL_FREEBSD:%=build/%/nebula) $(ALL_FREEBSD:%=build/%/nebula-cert)
100
101 all-openbsd: $(ALL_OPENBSD:%=build/%/nebula) $(ALL_OPENBSD:%=build/%/nebula-cert)
102
103 all-netbsd: $(ALL_NETBSD:%=build/%/nebula) $(ALL_NETBSD:%=build/%/nebula-cert)
104
105 all-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert build/darwin-arm64/nebula build/darwin-arm64/nebula-cert
106
107 all-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
108
109 # CI cross-build shards. darwin-arm64 is covered by the native macos-latest
110 # job; windows-amd64 is covered by the native windows-latest job; both are
111 # omitted here to avoid building them a second time. darwin-amd64 stays in
112 # all-cross-darwin because intel mac is only a labeled/master-time native
113 # job, so PRs still need cross-build coverage for it.
114 all-cross-linux: $(ALL_CROSS_LINUX:%=build/%/nebula) $(ALL_CROSS_LINUX:%=build/%/nebula-cert)
115
116 all-cross-linux-arm: $(ALL_CROSS_LINUX_ARM:%=build/%/nebula) $(ALL_CROSS_LINUX_ARM:%=build/%/nebula-cert)
117
118 all-cross-linux-mips: $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula) $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula-cert)
119
120 all-cross-linux-other: $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula) $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula-cert)
121
122 all-cross-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
123
124 all-cross-windows: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
125
126 docker: docker/linux-$(shell go env GOARCH)
127
128 release: $(ALL:%=build/nebula-%.tar.gz)
129
130 release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
131
132 release-freebsd: $(ALL_FREEBSD:%=build/nebula-%.tar.gz)
133
134 release-openbsd: $(ALL_OPENBSD:%=build/nebula-%.tar.gz)
135
136 release-netbsd: $(ALL_NETBSD:%=build/nebula-%.tar.gz)
137
138 release-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
139
140 BUILD_ARGS += -trimpath
141
142 bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
143 mv $? .
144
145 bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
146 mv $? .
147
148 bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
149 mv $? .
150
151 bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
152 mv $? .
153
154 bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
155 mv $? .
156
157 bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
158 mv $? .
159
160 bin-pkcs11: BUILD_ARGS += -tags pkcs11
161 bin-pkcs11: CGO_ENABLED = 1
162 bin-pkcs11: bin
163
164 bin:
165 go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
166 go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
167
168 install:
169 go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
170 go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
171
172 build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
173 build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
174
175 # Build an extra small binary for mips-softfloat
176 build/linux-mips-softfloat/%: LDFLAGS += -s -w
177
178 # boringcrypto
179 build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
180 build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
181 build/linux-amd64-boringcrypto/%: LDFLAGS += -checklinkname=0
182 build/linux-arm64-boringcrypto/%: LDFLAGS += -checklinkname=0
183
184 build/%/nebula: .FORCE
185 GOOS=$(firstword $(subst -, , $*)) \
186 GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
187 go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
188
189 build/%/nebula-cert: .FORCE
190 GOOS=$(firstword $(subst -, , $*)) \
191 GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
192 go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
193
194 build/%/nebula.exe: build/%/nebula
195 mv $< $@
196
197 build/%/nebula-cert.exe: build/%/nebula-cert
198 mv $< $@
199
200 build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
201 tar -zcv -C build/$* -f $@ nebula nebula-cert
202
203 build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
204 cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
205
206 docker/%: build/%/nebula build/%/nebula-cert
207 docker build . $(DOCKER_BUILD_ARGS) -f docker/Dockerfile --platform "$(subst -,/,$*)" --tag "${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG}" --tag "${DOCKER_IMAGE_REPO}:$(BUILD_NUMBER)"
208
209 vet:
210 go vet $(VET_FLAGS) -v ./...
211
212 test:
213 go test -v ./...
214
215 test-boringcrypto:
216 GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -ldflags "-checklinkname=0" -v ./...
217
218 test-pkcs11:
219 CGO_ENABLED=1 go test -v -tags pkcs11 ./...
220
221 test-cov-html:
222 go test -coverprofile=coverage.out
223 go tool cover -html=coverage.out
224
225 build-test-mobile:
226 GOARCH=amd64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
227 GOARCH=arm64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
228 GOARCH=amd64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
229 GOARCH=arm64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
230
231 bench:
232 go test -bench=.
233
234 bench-cpu:
235 go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
236 go tool pprof go-audit.test cpu.pprof
237
238 bench-cpu-long:
239 go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
240 go tool pprof go-audit.test cpu.pprof
241
242 proto: nebula.pb.go cert/cert_v1.pb.go
243
244 nebula.pb.go: nebula.proto .FORCE
245 go build github.com/gogo/protobuf/protoc-gen-gogofaster
246 PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
247 rm protoc-gen-gogofaster
248
249 cert/cert.pb.go: cert/cert.proto .FORCE
250 $(MAKE) -C cert cert.pb.go
251
252 service:
253 @echo > $(NULL_FILE)
254 $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
255 ifeq ($(words $(MAKECMDGOALS)),1)
256 @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
257 endif
258
259 bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
260
261 smoke-docker: bin-docker
262 cd .github/workflows/smoke/ && ./build.sh
263 cd .github/workflows/smoke/ && ./smoke.sh
264 cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
265 cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
266
267 smoke-relay-docker: bin-docker
268 cd .github/workflows/smoke/ && ./build-relay.sh
269 cd .github/workflows/smoke/ && ./smoke-relay.sh
270
271 smoke-docker-ipv6: export SMOKE_OVERLAY_IPV6 = 1
272 smoke-docker-ipv6: smoke-docker
273
274 smoke-docker-race: BUILD_ARGS = -race
275 smoke-docker-race: CGO_ENABLED = 1
276 smoke-docker-race: smoke-docker
277
278 smoke-vagrant/%: bin-docker build/%/nebula
279 cd .github/workflows/smoke/ && ./build.sh $*
280 cd .github/workflows/smoke/ && ./smoke-vagrant.sh $*
281
282 .FORCE:
283 .PHONY: all all-linux all-freebsd all-openbsd all-netbsd all-darwin all-windows all-cross-linux all-cross-linux-arm all-cross-linux-mips all-cross-linux-other all-cross-darwin all-cross-windows bench bench-cpu bench-cpu-long bin build-test-mobile e2e e2ev e2evv e2evvv e2evvvv proto release service smoke-docker smoke-docker-race test test-cov-html smoke-vagrant/%
284 .DEFAULT_GOAL := bin