-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGNUmakefile
200 lines (165 loc) · 4.92 KB
/
GNUmakefile
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
LN_S := ln -sf
RM_F := rm -rf
MKDIR_P := mkdir -p
# We use use various bash-isms in the rules.
SHELL := bash
.DEFAULT_GOAL := help
export CC := clang
export CXX := clang++
export GOPATH
export GOBIN
export HOME
Clang_Format := clang-format
Clang_Tidy := clang-tidy
Clang_Apply_Replacements := clang-apply-replacements-12
Buildifier := buildifier
Buildozer := buildozer
OS := $(shell uname -s)
Linux_Distribution := $(shell . /etc/os-release 2>/dev/null && echo $$NAME)
Envoy_Repository := $(HOME)/upstream/envoy
Install_Pkg_Fedora := dnf install -y
Packages_Fedora := \
aspell \
aspell-en \
autoconf \
automake \
clang \
cmake \
curl \
libcxxabi-devel \
libcxxabi-static \
libcxx-static \
libtool \
lld \
make \
ninja-build \
patch \
python3-pip \
unzip
Install_Pkg_Ubuntu := apt install -y
Packages_Ubuntu := \
autoconf \
automake \
clang \
clangd \
clang-format \
clang-tidy \
cmake \
curl \
libtool \
lld \
llvm \
make \
ninja-build \
patch \
python3-pip \
unzip
Packages_Darwin := \
aspell \
autoconf \
automake \
bazelisk \
buildifier \
clang-format \
cmake \
coreutils \
libtool \
ninja \
wget
# On Linux we want to use `--config-clang` to force the build to use Clang,
# but that breaks macOS because it adds `-fuse-ld=lld` which isn't supported
# on macOS.
Bazel_Build_Darwin :=
Bazel_Build_Linux := --config=clang
Bazel_Build_Args ?=
export CC := $(shell which clang)
export CXX := $(shell which clang++)
include llama.mk
.PHONY: envoy
envoy: ## Build envoy
bazel build $(Bazel_Build_$(OS)) @envoy//source/exe:envoy-static
[[ -L envoy-static ]] || ln -s bazel-bin/external/envoy/source/exe/envoy-static
.PHONY: check
check: ## Run envoy unit tests
bazel test $(Bazel_Build_$(OS)) @envoy//test/...
.PHONY: fetch
fetch: ## Fetch envoy build dependencies
bazel fetch @envoy//source/exe:envoy-static
bazel fetch @envoy//test/...
# NOTE: buildifier and buildozer are disabled since it's hard to
# match the version that Envoy CI uses.
.PHONY: format
format: ## Run envoy source format tooling
cd $(Envoy_Repository) && \
CLANG_FORMAT=$${CLANG_FORMAT:-$(Clang_Format)} \
BUILDIFIER_BIN=$${BUILDIFIER_BIN:-$(Buildifier)} \
BUILDOZER_BIN=$${BUILDOZER_BIN:-$(Buildozer)} \
$(Envoy_Repository)/tools/code_format/check_format.py fix
.PHONY: tidy
tidy: ## Run envoy clang-tidy tooling
cd $(Envoy_Repository) && \
RUN_FULL_CLANG_TIDY=1 \
APPLY_CLANG_TIDY_FIXES=1 \
COMP_DB_TARGETS=//source/exe:envoy-static \
CLANG_TIDY=$${CLANG_TIDY:-$(Clang_Tidy)} \
CLANG_APPLY_REPLACEMENTS=$${CLANG_APPLY_REPLACEMENTS:-$(Clang_Apply_Replacements)} \
$(Envoy_Repository)/ci/run_clang_tidy.sh
.PHONY: symbols
symbols: ## Build compilation database
@cd $(Envoy_Repository) && ./tools/gen_compilation_database.py \
--vscode --include_headers --include_genfiles --include_external
Generated_Setup_Files := .bazelrc .bazelversion bazel/get_workspace_status WORKSPACE
.PHONY: setup
setup: ## Do initial workspace setup
setup: $(Generated_Setup_Files)
# Set up .bazelrc. If the platform is building with clang, generate the clang
# configuration and import it into the bazelrc.
.bazelrc: .bazelversion WORKSPACE
@echo "import $(Envoy_Repository)/.bazelrc" > $@
@case "$(Bazel_Build_$(OS))" in \
*config=clang*) \
$(Envoy_Repository)/bazel/setup_clang.sh; \
echo "try-import %workspace%/clang.bazelrc" >> $@ ; \
;; \
esac
.bazelversion:
$(LN_S) $(Envoy_Repository)/.bazelversion
bazel/get_workspace_status: bazel/get_workspace_status.in
@sed '-es^$$Envoy_Repository^$(Envoy_Repository)^g' < $< > $@
@chmod 755 $@
WORKSPACE: WORKSPACE.in
@sed '-es^$$Envoy_Repository^$(Envoy_Repository)^g' < $< > $@
.PHONY: container
container: ## Package the envoy-static binary into a container image
source /etc/os-release && [[ "$$NAME" == Fedora ]] # enforce that we have a Fedora build
test -L envoy-static # ensure we have a envoy build
$(RM_F) envoy
cp $$(realpath envoy-static) envoy
sudo docker build -t jpeach/envoy-devel:$$(date +%s) .
$(RM_F) envoy
.PHONY: distclean
distclean:: ## Deep clean of all final and intermediate artifacts
@-bazel clean
$(RM_F) $(Generated_Setup_Files)
$(RM_F) clang.bazelrc
$(RM_F) envoy-static
$(RM_F) envoy
$(RM_F) bazel-bin bazel-envoy bazel-out bazel-testlogs
.PHONY: install-deps
install-deps: install-deps-$(OS) ## Install build dependencies
.PHONY: install-deps-Linux
install-deps-Linux:
sudo $(Install_Pkg_$(Linux_Distribution)) $(Packages_$(Linux_Distribution))
if ! `command -v python >/dev/null 2>&1`; then \
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1000; \
fi
.PHONY: install-deps-Darwin
install-deps-Darwin:
brew install $(Packages_$(OS))
.PHONY: help
help: ## Show this help
@echo Targets:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9._-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
@echo
@echo LLama targets:
@awk 'BEGIN {FS = ":.*?## "} /^llama\/[a-zA-Z0-9._-/]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort