-
Notifications
You must be signed in to change notification settings - Fork 46
/
Makefile
327 lines (290 loc) · 8.57 KB
/
Makefile
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#
# This Makefile is quite primitive, it's just about enough to build
# everything for CI, but for development we'll want something better
# eventually.
#
# To build everything: type "make"
#
# To run the tests, type "make test"
#
# For development, use "make MODE=dev" for faster, unoptimised builds and
# "make MODE=opt" for slower, optimised builds.
#
# =====
# Modes
# =====
#
# By default, make builds everything via Cabal using standard Cabal directories.
# With MODE=dev|opt, make will use a build directory specific to that mode and
# separate from the default build directories and from other modes. This means
# that the individual modes don't interfere with each other and can be worked
# with without rebuilding everything. Typically, you want MODE=dev for
# development and MODE=opt for benchmarking.
#
# The dev and opt modes also build C++ libraries via make rather than Cabal as
# described below.
#
# =======================
# Cabal and C++ libraries
# =======================
#
# We have two modes of compiling Glean's internal C++ libraries, controlled by
# the CXX_MODE variable. These modes need slightly different glean.cabal files.
# Thus, we generate glean.cabal by running glean.cabal.in through m4 with
# appropriate macro definitions.
#
# The reason for this is that Cabal can't build .cpp files in parallel and also
# doesn't track include dependencies between different libraries with
# cxx-sources. However, Cabal is the only way to get things onto Hackage. Thus,
# we support building C++ libraries via Cabal but for development, building
# via make should be preferred.
#
# Building via make (CXX_MODE=make):
# * Builds C++ libraries outside of Cabal
# * Compiles C++ modules in parallel (about 2:30min faster for full build)
# * Automatically tracks include dependencies
#
# Building via Cabal (otherwise):
# * Might work on Hackage
#
# The C++ libraries are defined in mk/cxx.mk, see the docs there for adding,
# removing or modifying libraries.
#
# ===================
# Auto-generated code
# ===================
#
# Re-running "make" will regenerate a bunch of things. That's because
# the Makefile is dumb and doesn't know much about the dependencies of
# the generated files. To avoid recompiling any code if nothing changed,
# we generally write generated code into $(CODEGEN_DIR) and then
# rsync --checksum it to the actual source directory which preserves timestamps
# for files which haven't changed.
#
CABAL_BIN=cabal
PWD := $(shell /bin/pwd)
# There's a lot of parallelism in the schema-generated code
# If you have >=16G and >=4 cores, trying passing these:
#
# EXTRA_GHC_OPTS = '-j4 +RTS -A128m -n2m -RTS'
#
EXTRA_GHC_OPTS ?=
# Allow developers to locally override things
-include settings.mk
MODE ?= def
ifneq ($(MODE),def)
include mk/mode-$(MODE).mk
endif
CABAL = $(CABAL_BIN) --jobs --ghc-options='$(EXTRA_GHC_OPTS)' \
-vnormal+nowrap --project-file=$(PWD)/cabal.project \
$(CABAL_CONFIG_FLAGS) $(GETDEPS_CABAL_FLAGS)
BUILD_DIR = .build
MODE_DIR = $(BUILD_DIR)/$(MODE)
CODEGEN_DIR = $(MODE_DIR)/codegen
CXX_DIR = $(MODE_DIR)/cxx
BYTECODE_GEN= \
glean/hs/Glean/RTS/Bytecode/Gen/Instruction.hs \
glean/hs/Glean/RTS/Bytecode/Gen/Issue.hs \
glean/hs/Glean/RTS/Bytecode/Gen/Version.hs
BYTECODE_SRCS= \
$(wildcard glean/bytecode/*/Glean/Bytecode/*/*.hs) \
$(wildcard glean/bytecode/Glean/Bytecode/*.hs)
all:: glean.cabal thrift $(BYTECODE_GEN) gen-schema thrift-schema-hs glean
.PHONY: cabal-update
cabal-update:: glean.cabal
$(CABAL) update
# Targets in this file invoke Cabal and hence can't be built in parallel
.NOTPARALLEL:
.PHONY: force
$(BUILD_DIR)/mode: force
@mkdir -p $(@D)
@(echo $(MODE) | cmp -s $@) || (echo $(MODE) > $@)
# We have to regenerate glean.cabal if the mode (and hence the path to defs.m4)
# changes even if the actual files are older.
glean.cabal: glean.cabal.in $(BUILD_DIR)/mode $(CXX_DIR)/defs.m4
rm -f $@
m4 -E -E -P $(CXX_DIR)/defs.m4 glean.cabal.in \
| sed "/-- Copyright/a \\\n-- @""generated from glean.cabal.in\\n-- DO NO EDIT THIS FILE DIRECTLY" \
> $@
chmod guo-w $@
$(CXX_DIR)/defs.m4: force
@$(MAKE) -f mk/cxx.mk --no-print-directory CXX_MODE=$(CXX_MODE) CXX_DIR=$(CXX_DIR) $@
.PHONY: cxx-libraries
cxx-libraries:
@$(MAKE) -f mk/cxx.mk --no-print-directory CXX_MODE=$(CXX_MODE) CXX_DIR=$(CXX_DIR) $@
cxx-test-%: force
@$(MAKE) -f mk/cxx.mk --no-print-directory CXX_MODE=$(CXX_MODE) CXX_DIR=$(CXX_DIR) $@
.PHONY: glean
glean:: glean.cabal cxx-libraries
$(CABAL) build glean glean-server glean-hyperlink
.PHONY: gen-bytecode
gen-bytecode: $(BYTECODE_GEN)
# Note we don't rsync here because we have actual dependencies
$(BYTECODE_GEN) &: $(BYTECODE_SRCS) glean.cabal
$(CABAL) run gen-bytecode-hs -- --install_dir=glean/hs
.PHONY: test
test:: glean.cabal
$(CABAL) test glean:tests
SCHEMAS= \
buck \
builtin \
code \
code_buck \
code_csharp \
code_cxx \
code_dataswarm \
code_erlang \
code_fbthrift \
code_flow \
code_graphql \
code_hack \
code_hs \
code_java \
code_kotlin \
code_lsif \
codemarkup \
codemarkup_buck \
codemarkup_csharp \
codemarkup_cxx \
codemarkup_dataswarm \
codemarkup_erlang \
codemarkup_fbthrift \
codemarkup_flow \
codemarkup_graphql \
codemarkup_hack \
codemarkup_haskell \
codemarkup_java \
codemarkup_lsif \
codemarkup_pp \
codemarkup_python \
codemarkup_scip \
codemarkup_search \
codemarkup_types \
code_pp \
code_python \
code_scip \
csharp \
cxx1 \
dataswarm \
digest \
dyn \
erlang \
flow \
gencode \
glass \
glean_test \
graphql \
hack \
hs \
java_alpha \
javakotlin_alpha \
kotlin_alpha \
lsif \
lsif_types \
pp1 \
python \
scip \
search_code \
search_cxx \
search_erlang \
search_buck \
search_hack \
search_java \
search_kind_cxx \
search_hs \
search_pp \
src \
symbolid_cxx \
symbolid_java \
symbolid_kotlin \
sys \
fbthrift \
.PHONY: thrift
thrift:: thrift-compiler thrift-hs
.PHONY: thrift-hs
thrift-hs:: thrift-hsthrift-hs thrift-glean-hs
.PHONY: thrift-compiler
thrift-compiler::
(cd hsthrift && make CABAL="$(CABAL)" compiler)
$(eval THRIFT_COMPILE := $$(shell $$(CABAL) -v0 list-bin exe:thrift-compiler))
.PHONY: thrift-hsthrift-hs
thrift-hsthrift-hs::
(cd hsthrift && make CABAL="$(CABAL)" thrift-hs)
.PHONY: gen-schema
gen-schema :: glean.cabal cxx-libraries
rm -rf $(CODEGEN_DIR)/$@
mkdir -p $(CODEGEN_DIR)/$@
$(CABAL) run glean:gen-schema -- \
--install_dir $(CODEGEN_DIR)/$@ \
--dir glean/schema/source \
--thrift glean/schema \
--hs glean/schema \
--cpp glean/lang/clang/schema.h
rsync -r --checksum $(CODEGEN_DIR)/$@/ .
THRIFT_GLEAN= \
glean/github/if/fb303.thrift \
glean/github/if/fb303_core.thrift \
glean/if/glean.thrift \
glean/config/recipes/recipes.thrift \
glean/config/recipes/recipes.thrift \
glean/config/server/server_config.thrift \
glean/config/service.thrift \
glean/config/client/client_config.thrift \
thrift/annotation/cpp.thrift \
thrift/annotation/hack.thrift \
thrift/annotation/rust.thrift \
thrift/annotation/scope.thrift \
thrift/annotation/thrift.thrift
.PHONY: thrift-glean-hs
thrift-glean-hs: thrift-compiler
rm -rf $(CODEGEN_DIR)/$@
mkdir -p $(CODEGEN_DIR)/$@
for f in $(THRIFT_GLEAN); do \
$(THRIFT_COMPILE) --hs $$f -o $(CODEGEN_DIR)/$@/$$(dirname $$f); \
done
# internal goes in a subdir, so do it separately
$(THRIFT_COMPILE) --hs glean/if/internal.thrift \
-o $(CODEGEN_DIR)/$@/glean/if/internal
# index goes in a subdir, so do it separately
$(THRIFT_COMPILE) --hs glean/if/index.thrift \
-o $(CODEGEN_DIR)/$@/glean/if/index
# glass goes in a subdir, so do it separately
$(THRIFT_COMPILE) --hs glean/glass/if/glass.thrift \
-o $(CODEGEN_DIR)/$@/glean/glass/if/glass
rsync -r --checksum $(CODEGEN_DIR)/$@/ .
.PHONY: thrift-schema-hs
thrift-schema-hs: thrift-compiler
rm -rf $(CODEGEN_DIR)/$@
mkdir -p $(CODEGEN_DIR)/$@
for s in $(SCHEMAS); do \
$(THRIFT_COMPILE) --hs \
glean/schema/thrift/$$s.thrift \
-o $(CODEGEN_DIR)/$@/glean/schema/thrift; \
done
rsync -r --checksum $(CODEGEN_DIR)/$@/ .
# full build up to glass lib
.PHONY: glass-lib
glass-lib:: thrift gen-schema thrift-schema-hs thrift-glean-hs glean.cabal cxx-libraries
$(CABAL) build glass-lib
# short circuit target to avoid thrift regen
.PHONY: glass
glass::
$(CABAL) build glass-server glass-democlient
.PHONY: glean-clang
glean-clang:: gen-schema glean glean.cabal cxx-libraries
$(CABAL) build glean-clang
.PHONY: glean-hiedb
glean-hiedb:: glean.cabal cxx-libraries
$(CABAL) build hiedb-indexer
define bash_macros
call_cabal() {
$(CABAL) "$$@"
}
endef
$(BUILD_DIR)/current.sh: force
$(file >$@,$(bash_macros))
@:
# Dummy install rule to keep getdeps happy. TODO: actually install things
.PHONY: install
install::
mkdir -p $(PREFIX)