-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
231 lines (188 loc) · 6.17 KB
/
Copy pathMakefile
File metadata and controls
231 lines (188 loc) · 6.17 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# require GNU Make
APP ?= stunmesh-go
GO_FLAGS ?=
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# 32-bit MIPS routers commonly lack an FPU, so default both endians to
# soft-float. Set GOMIPS=hardfloat to override.
ifneq ($(filter mips mipsle,$(GOARCH)),)
GOMIPS ?= softfloat
endif
STRIP ?= 1
TRIMPATH ?= 1
UPX ?= 0
EXTRA_MIN ?= 0
BUILTIN ?= all
# EMBED_CA=1 embeds the Mozilla root bundle (build tag embedca), used only
# when the system has no CA store. For images without ca-certificates.
EMBED_CA ?= 0
# Empty selects the per-platform default from the internal/wg build constraints:
# wgcli on freebsd, wgctrl elsewhere. Set to override.
BACKEND ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
# Android AAR. ANDROID_API is gomobile's minimum API level; MOBILE_VERSION is
# stamped into the library so the app can report which core it is linked
# against, and names the file the way the other release assets are named.
ANDROID_API ?= 26
MOBILE_VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
AAR ?= stunmesh-android-$(MOBILE_VERSION).aar
# Validate BACKEND value. filter-out rejects unknown words, and the word count
# rejects a contradictory 'wgctrl wgcli', which filter alone would accept.
ifneq ($(BACKEND),)
ifneq ($(filter-out wgctrl wgcli,$(BACKEND))$(filter-out 1,$(words $(BACKEND))),)
$(error BACKEND must be 'wgctrl' or 'wgcli', got '$(BACKEND)')
endif
endif
# Platforms whose wgctrl backend requires CGO_ENABLED=1. They default to wgcli,
# so this only applies when wgctrl is explicitly requested.
CGO_REQUIRED_PLATFORMS := freebsd
ifneq ($(EXTRA_MIN),0)
STRIP = 1
TRIMPATH = 1
UPX = 1
endif
LDFLAGS =
ifneq ($(STRIP),0)
LDFLAGS := -s -w
endif
TRIMPATH_FLAGS =
ifneq ($(TRIMPATH),0)
TRIMPATH_FLAGS := -trimpath
endif
# builtin_all: every built-in opts in via `|| builtin_all`, no list to maintain.
# BUILTIN=builtin_<name> picks one, BUILTIN= none.
ifeq ($(BUILTIN),all)
override BUILTIN := builtin_all
endif
CA_TAG =
ifneq ($(EMBED_CA),0)
CA_TAG := embedca
endif
# Combine BUILTIN, BACKEND and EMBED_CA tags. An empty BACKEND adds no tag,
# leaving the backend choice to the build constraints in internal/wg.
ALL_TAGS := $(strip $(BUILTIN) $(BACKEND) $(CA_TAG))
TAGS_FLAGS = $(if $(ALL_TAGS),-tags '$(ALL_TAGS)',)
# mobile/ and internal/mobilebind sit behind the mobile build tag, so every
# mobile target adds it; without the tag those packages are invisible and the
# desktop build never compiles wireguard-go's device stack.
MOBILE_TAGS := $(strip $(BUILTIN) mobile)
MOBILE_PKG := github.com/tjjh89017/stunmesh-go/mobile
UPX_TARGET =
ifneq ($(UPX),0)
UPX_TARGET = upx
endif
# Set CGO_ENABLED: only an explicit wgctrl on CGO_REQUIRED_PLATFORMS needs it,
# so every default build is CGO-free.
ifeq ($(BACKEND),wgctrl)
ifeq ($(GOOS),$(filter $(GOOS),$(CGO_REQUIRED_PLATFORMS)))
CGO_ENABLED = 1
LDFLAGS := ${LDFLAGS} -extldflags="-static"
else
CGO_ENABLED = 0
endif
else
CGO_ENABLED = 0
endif
GO_FLAGS := ${GO_FLAGS} -ldflags '${LDFLAGS}' ${TRIMPATH_FLAGS} ${TAGS_FLAGS}
.PHONY: all
all: clean build $(UPX_TARGET)
.PHONY: build
build:
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} GOMIPS=${GOMIPS} go build ${GO_FLAGS} -v -o ${APP}
.PHONY: upx
upx:
upx --lzma --best ${APP}
.PHONY: clean
clean:
go clean
.PHONY: test
test:
go test -cover -v ${TAGS_FLAGS} ./...
.PHONY: test-race
test-race:
go test -race ${TAGS_FLAGS} ./...
# Payload size (1420) and GOMAXPROCS=4 are pinned inside bench_test.go.
.PHONY: bench
bench:
go test ./internal/wgproxy -bench BenchmarkRelay -benchtime 2s -run '^$$'
.PHONY: bench-floor
bench-floor:
STUNMESH_BENCH_FLOOR=1 go test ./internal/wgproxy -run TestRelayThroughputFloor -count=1
# Android is one consumer of the shared mobile package; an ios target building
# an xcframework from the same package would sit beside this one.
.PHONY: android
android:
@command -v gomobile >/dev/null || { \
echo "gomobile not found: go install golang.org/x/mobile/cmd/gomobile@latest && gomobile init"; \
exit 1; \
}
gomobile bind -target=android -androidapi ${ANDROID_API} -tags '${MOBILE_TAGS}' \
-ldflags "-s -w -X ${MOBILE_PKG}.version=${MOBILE_VERSION} -extldflags=-Wl,-z,max-page-size=16384" \
-o ${AAR} ./mobile
.PHONY: mobile-test
mobile-test:
go test -cover -v -tags '${MOBILE_TAGS}' ./internal/mobilebind/... ./mobile/...
.PHONY: android-clean
android-clean:
rm -f ${AAR} $(patsubst %.aar,%-sources.jar,${AAR})
# The AAR name carries the version, so anything downstream that needs it (CI
# upload, release assets) asks rather than reconstructing it.
.PHONY: print-aar
print-aar:
@echo ${AAR}
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: vet
vet:
go vet ${TAGS_FLAGS} ./...
# golangci-lint only sees the files its GOOS selects, so lint each platform;
# the darwin/bsd STUN code is the most platform-specific in the tree.
LINT_PLATFORMS ?= linux darwin freebsd windows
.PHONY: lint
lint:
@for os in $(LINT_PLATFORMS); do \
echo "Linting GOOS=$$os..."; \
GOOS=$$os golangci-lint run || exit 1; \
done
$(MAKE) lint-mobile
# mobile/ and internal/mobilebind sit behind the mobile tag (see MOBILE_TAGS
# above), so the platform loop above never sees them; lint them separately
# with the same tags mobile-test and the android target use. GOOS=linux
# matches how the AAR is actually built (gomobile runs on a Linux CI host).
.PHONY: lint-mobile
lint-mobile:
GOOS=linux golangci-lint run --build-tags '$(MOBILE_TAGS)' ./mobile/... ./internal/mobilebind/...
.PHONY: install
install: build
install -d $(BINDIR)
install -m 755 $(APP) $(BINDIR)/$(APP)
.PHONY: uninstall
uninstall:
rm -f $(BINDIR)/$(APP)
.PHONY: plugin
plugin:
$(MAKE) -C contrib all
.PHONY: contrib
contrib: plugin
.PHONY: plugin-clean
plugin-clean:
$(MAKE) -C contrib clean
.PHONY: contrib-clean
contrib-clean: plugin-clean
.PHONY: plugin-install
plugin-install:
$(MAKE) -C contrib install PREFIX=$(PREFIX) BINDIR=$(BINDIR)
.PHONY: contrib-install
contrib-install: plugin-install
.PHONY: plugin-uninstall
plugin-uninstall:
$(MAKE) -C contrib uninstall PREFIX=$(PREFIX) BINDIR=$(BINDIR)
.PHONY: contrib-uninstall
contrib-uninstall: plugin-uninstall
.PHONY: plugin-test
plugin-test:
$(MAKE) -C contrib test
.PHONY: contrib-test
contrib-test: plugin-test