-
Notifications
You must be signed in to change notification settings - Fork 76
/
Makefile.common-jst
433 lines (390 loc) · 17.6 KB
/
Makefile.common-jst
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#
# Build rules common to ocaml-jst and flambda-backend
#
ws_boot = --root=. --workspace=duneconf/boot.ws
ws_runstd = --root=. --workspace=duneconf/runtime_stdlib.ws
ws_main = --root=. --workspace=duneconf/main.ws
ifeq ($(coverage),yes)
coverage_dune_flags=--instrument-with bisect_ppx
ocaml_subdirs_to_ignore=otherlibs
else
coverage_dune_flags=
ocaml_subdirs_to_ignore=
endif
define dune_boot_context
(lang dune 2.8)
; We need to call the boot context "default" so that dune selects it for merlin
(context (default
(name default)
(profile dev)
(env (_
(flags (:standard -warn-error +A))
(env-vars ("OCAMLPARAM" ""))))))
endef
define dune_runtime_stdlib_context
(lang dune 2.8)
(context (default
(name runtime_stdlib)
(profile main)
(paths
(PATH ("$(CURDIR)/_build/_bootinstall/bin" :standard))
(OCAMLLIB ("$(CURDIR)/_build/_bootinstall/lib/ocaml")))
(env (_
(flags (:standard -warn-error +A))
(env-vars ("OCAMLPARAM" "$(BUILD_OCAMLPARAM)"))))))
endef
define dune_main_context
(lang dune 2.8)
(context (default
(name main)
(profile $(main_build_profile))
(paths
(PATH ("$(CURDIR)/_build/_bootinstall/bin" :standard))
(OCAMLLIB ("$(CURDIR)/_build/runtime_stdlib_install/lib/ocaml_runtime_stdlib")))
(env (_
(flags (:standard -warn-error +A))
(env-vars ("OCAMLPARAM" "$(BUILD_OCAMLPARAM)"))))))
endef
.DEFAULT_GOAL := compiler
.PHONY: boot-compiler boot-runtest runtime-stdlib compiler runtest
boot_targets = \
$(boot_ocamlc) \
$(boot_ocamlopt) \
$(boot_ocamlmklib) \
$(boot_ocamldep) \
$(boot_ocamlobjinfo) \
ocamltest/ocamltest.native
boot-compiler: _build/_bootinstall
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build $(ws_boot) $(coverage_dune_flags) $(boot_targets)
boot-runtest: boot-compiler
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) runtest $(ws_boot) $(coverage_dune_flags) --force
runtime-stdlib: boot-compiler
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build $(ws_runstd) --only-package=ocaml_runtime_stdlib @install
rm -rf _build/runtime_stdlib_install
# Dune 3.11+ clears `_build/install` before building, move the runtime stdlib
# to a separate directory.
$(cpl) -R _build/install/runtime_stdlib _build/runtime_stdlib_install
# Dune does not believe the compiler can make .cmxs unless the following file exists.
@touch _build/runtime_stdlib_install/lib/ocaml_runtime_stdlib/dynlink.cmxa
compiler: runtime-stdlib
RUNTIME_DIR=$(RUNTIME_DIR) SYSTEM=$(SYSTEM) MODEL=$(MODEL) \
ASPP="$(ASPP)" ASPPFLAGS="$(ASPPFLAGS)" \
$(dune) build $(ws_main) \
--only-package=ocaml @install \
flambda-backend/testsuite/tools/expect.exe \
flambda-backend/testsuite/tools/codegen_main.exe \
flambda-backend/testsuite/tools/asmgen_$(ARCH).o \
testsuite/lib/lib.cm{,x}a \
testsuite/lib/testing.cm{,x}a \
$(ocamldir)/tools/dumpobj.bc
runtest: compiler
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) runtest $(ws_main)
# This Makefile supports old versions that don't have $(file), so we're using
# environment var trickery to get a multiline string into a file
duneconf/boot.ws: export contents = $(dune_boot_context)
duneconf/runtime_stdlib.ws: export contents = $(dune_runtime_stdlib_context)
duneconf/main.ws: export contents = $(dune_main_context)
duneconf/%.ws:
echo "$$contents" > $@
# We need to disable ocaml/otherlibs when compiling with coverage, because we
# need to compile against the user's opam instead. Unfortunately, Dune gives us
# no nicer way of declaring data_only_dirs differently in different workspaces,
# so we have to output a file to be included in ocaml/dune.
#
# Also, Dune only allows one (data_only_dirs) declaration per file, so here we
# have to account for the declaration that would already have been in
# ocaml/dune.
$(ocamldir)/duneconf/dirs-to-ignore.inc:
echo "(data_only_dirs yacc $(ocaml_subdirs_to_ignore))" > $@
# Targets that should be prerequisites to any target that runs Dune
dune_config_targets = \
duneconf/boot.ws \
duneconf/runtime_stdlib.ws \
duneconf/main.ws \
$(ocamldir)/duneconf/dirs-to-ignore.inc \
$(ocamldir)/duneconf/jst-extra.inc \
dune-project \
$(ocamldir)/dune.runtime_selection \
$(ocamldir)/otherlibs/dune
$(ocamldir)/otherlibs/dune:
if [ "$(RUNTIME_DIR)" = "runtime4" ]; then \
echo "(dirs (:standard \ systhreads runtime_events))" > $@; \
else \
echo "(dirs (:standard \ systhreads4))" > $@; \
fi
$(ocamldir)/dune.runtime_selection:
if [ "$(RUNTIME_DIR)" = "runtime4" ]; then \
echo "(dirs (:standard \ runtime debugger))" > $@; \
else \
echo "(dirs (:standard \ runtime4 debugger4))" > $@; \
fi
_build/_bootinstall: Makefile.config $(dune_config_targets)
echo -n '$(NATDYNLINKOPTS)' > $(ocamldir)/otherlibs/dynlink/natdynlinkops
# flags.sexp
echo '(:standard $(if $(filter true,$(FUNCTION_SECTIONS)),-function-sections,))' > ocamlopt_flags.sexp
echo '( $(OC_CFLAGS) )' > oc_cflags.sexp
echo '( $(OC_CPPFLAGS) )' > oc_cppflags.sexp
echo '( $(SHAREDLIB_CFLAGS) )' > sharedlib_cflags.sexp
# _build/_bootinstall: a minimal install directory for the boot compiler,
# which is placed on PATH for subsequent builds
rm -rf _build/_bootinstall
mkdir -p _build/_bootinstall/{bin,lib/ocaml}
cp $^ _build/_bootinstall/lib/ocaml
ln -sf ../../default/$(boot_ocamlopt) _build/_bootinstall/bin/ocamlopt.opt
ln -sf ../../default/$(boot_ocamlc) _build/_bootinstall/bin/ocamlc.opt
ln -sf ../../default/$(boot_ocamlmklib) _build/_bootinstall/bin/ocamlmklib.opt
ln -sf ../../default/$(boot_ocamldep) _build/_bootinstall/bin/ocamldep.opt
ln -sf ../../default/$(boot_ocamlobjinfo) _build/_bootinstall/bin/ocamlobjinfo.opt
ln -sf "`which ocamllex`" _build/_bootinstall/bin/ocamllex.opt
for prog in ocamlopt ocamlc ocamllex ocamldep ocamlmklib; do \
ln -sf "$$prog.opt" "_build/_bootinstall/bin/$$prog"; \
done
# save a bit of disk space in build trees by using cp -l on Linux
# (not available on e.g. OS X)
cpl=$(if $(filter linux,$(SYSTEM)),cp -l,cp -L)
# Assemble the contents of the install directory in _install
# This is needed to run the upstream testsuite (see runtest-upstream below)
# We use a local directory rather than the final install path, since
# the final install path may be on a different filesystem (and hence be
# slow and/or unable to make hardlinks)
.PHONY: _install install install_for_opam
_install: compiler
rm -rf _install
mkdir -p _install/{bin,lib/ocaml}
$(cpl) _build/runtime_stdlib_install/bin/* _install/bin/
$(cpl) _build/install/main/bin/* _install/bin/
( cd _install/bin; for i in *.opt; do ln -s $$i $${i%.opt}; done )
$(cpl) -R _build/runtime_stdlib_install/lib/ocaml_runtime_stdlib/* _install/lib/ocaml/
rm -f _install/lib/ocaml/{META,dune-package,Makefile.config,dynlink.cmxa}
$(cpl) -R _build/install/main/lib/ocaml/* _install/lib/ocaml/
if [ "x$(legacy_layout)" == "xyes" ] ; \
then \
for libdir in unix str dynlink bigarray ; do \
mv _install/lib/ocaml/$${libdir}/* _install/lib/ocaml/ ; \
rmdir _install/lib/ocaml/$${libdir} ; \
done \
fi
rm -f _install/lib/ocaml/{META,dune-package}
rm -f _install/lib/ocaml/compiler-libs/*.cmo
$(cpl) {_build/install/main,_install}/lib/ocaml/compiler-libs/topstart.cmo
for file in $(toplevels_installed); do \
cp -f _install/lib/ocaml/compiler-libs/$${file}dirs.{cmi,mli,cmt,cmti} _install/lib/ocaml; \
done
mkdir _install/lib/stublibs
cp _build/main/parser.cmly _install/lib/ocaml/compiler-libs/
find _build/main/ \( -name "flambda2*.cmi" \
-or -name "flambda2*.cmti" -or -name "flambda2*.cmt" \) \
-exec cp -f {} _install/lib/ocaml/compiler-libs \;
# Copy _install to the final install directory (no-op if they are the same)
install: _install
mkdir -p '$(prefix)'
rsync --chmod=u+rw,go+r -rl _install/ '$(prefix)'
# Same as above, but relies on a successfull earlier _install
install_for_opam:
mkdir -p '$(prefix)'
rsync --chmod=u+rw,go+r -rl _install/ '$(prefix)'
main_prefix = _build/install/main
main_build = _build/main
boot_build = _build/default
# The following horror will be removed when work to allow the testsuite to
# run on an installed tree (led by David Allsopp) is completed.
.PHONY: runtest-upstream test install_for_test
install_for_test: _install
rm -rf _runtest
mkdir _runtest
ln -s ../_install _runtest/_install
$(cpl) -a $(ocamldir)/testsuite _runtest/testsuite
# replace backend-specific testsuite/tools with their new versions
rm -f _runtest/testsuite/tools/*
cp -a flambda-backend/testsuite/tools/* _runtest/testsuite/tools/
cp $(main_build)/flambda-backend/testsuite/tools/expect.exe _runtest/testsuite/tools/expect
chmod 755 _runtest/testsuite/tools/expect
cp $(main_build)/flambda-backend/testsuite/tools/codegen_main.exe \
_runtest/testsuite/tools/codegen
chmod 755 _runtest/testsuite/tools/codegen
cp $(main_build)/flambda-backend/testsuite/tools/asmgen_*.o \
_runtest/testsuite/tools/
cp $(main_build)/testsuite/lib/lib.{a,cmxa,cma} \
_runtest/testsuite/lib/
cp $(main_build)/testsuite/lib/.lib.objs/byte/lib.cm* \
_runtest/testsuite/lib/
cp $(main_build)/testsuite/lib/.lib.objs/native/lib.cm* \
_runtest/testsuite/lib/
cp $(main_build)/testsuite/lib/testing.{a,cmxa,cma} \
_runtest/testsuite/lib/
cp $(main_build)/testsuite/lib/.testing.objs/byte/testing.cm* \
_runtest/testsuite/lib/
cp $(main_build)/testsuite/lib/.testing.objs/native/testing.cm* \
_runtest/testsuite/lib/
# replace backend-specific testsuite/tests/asmcomp with their new versions
rm _runtest/testsuite/tests/asmcomp/*
cp -a flambda-backend/testsuite/tests/asmcomp/* _runtest/testsuite/tests/asmcomp/
# replace backend-specific testsuite/tests/asmgen with their new versions
rm _runtest/testsuite/tests/asmgen/*
cp -a flambda-backend/testsuite/tests/asmgen/* _runtest/testsuite/tests/asmgen/
# replace backend-specific testsuite/tests/unboxed-primitive-args with their new versions
rm _runtest/testsuite/tests/unboxed-primitive-args/*
cp -a flambda-backend/testsuite/tests/unboxed-primitive-args/* _runtest/testsuite/tests/unboxed-primitive-args/
# add extension library tests that are not supported by the upstream compiler
rm _runtest/testsuite/tests/lib-extensions/*
cp -a flambda-backend/testsuite/tests/lib-extensions/* _runtest/testsuite/tests/lib-extensions
cp $(ocamldir)/Makefile.* _runtest/
# Create an OCaml directory laid out like the testsuite expects,
# by copying and symlinking in bits from the install/build directory
(cd _runtest; \
for exe in _install/bin/*; do ln -s $$exe; done; \
ln -s . boot; \
for exe in ocamlc ocamlopt ocamllex; do \
rm -f $$exe; ln -s $$exe.byte $$exe; \
touch ocamlc.opt ocamlopt.opt; \
done; \
ln -s _install/lib/ocaml stdlib; \
mkdir $(RUNTIME_DIR); \
for f in ocamlrun* stdlib/caml stdlib/stublibs/* $(RUNTIME_DIR)/caml/threads.h; do \
ln -s ../$$f $(RUNTIME_DIR)/`basename $$f`; \
done; \
ln -s . lex; ln -s . yacc; \
ln -s _install/lib/ocaml/compiler-libs compilerlibs; \
mkdir -p otherlibs/{unix,dynlink/native,str,bigarray,runtime_events}; \
ln -s ../stdlib/threads otherlibs/systhreads$(RUNTIME_SUFFIX); \
$(cpl) stdlib/unix/{lib,}unix* otherlibs/unix; \
$(cpl) stdlib/dynlink/dynlink* otherlibs/dynlink; \
$(cpl) stdlib/str/{lib,}str* otherlibs/str; \
for universe in upstream_compatible stable beta alpha ; do \
mkdir -p otherlibs/{stdlib_,}$${universe}; \
$(cpl) stdlib/stdlib_$${universe}/* otherlibs/stdlib_$${universe}; \
$(cpl) stdlib/$${universe}/* otherlibs/$${universe}; \
done; \
if [[ x"$(RUNTIME_DIR)" = x"runtime" ]]; then \
$(cpl) stdlib/runtime_events/{lib,}runtime_events* otherlibs/runtime_events; \
fi; \
ln -s ../_build/main/$(ocamldir)/toplevel/byte/.ocamltoplevel.objs/byte toplevel; \
)
# Various directories are put on the -I paths by tools/Makefile;
# utils/ is one such, so we just dump the .cm* files in there for
# various things.
mkdir _runtest/utils
cp _install/lib/ocaml/compiler-libs/*.{cmi,cmx} _runtest/utils
cp $(main_build)/$(ocamldir)/.ocamlcommon.objs/byte/*.cmo _runtest/utils
rm -f _runtest/utils/{topdirs,opttopdirs}.cmi
cp _install/lib/ocaml/*.{cmi,cma,a,cmxa} _runtest/utils
cp _install/lib/ocaml/{unix,str,dynlink}/*.{cmi,cma,a,cmxa} _runtest/utils
cp $(main_build)/$(ocamldir)/.ocamlcommon.objs/native/config.o _runtest/utils
# Needed for tests/warnings
cp $(ocamldir)/utils/warnings.ml _runtest/utils
# Suppress linker errors about -I directories not existing.
for dir in asmcomp bytecomp driver file_formats lambda middle_end \
parsing typing; do ln -s utils _runtest/$$dir; done
# stublibs
mkdir -p _runtest/lib/ocaml/stublibs/
cp $(main_prefix)/lib/ocaml/stublibs/*.so _runtest/lib/ocaml/stublibs
# ocamldebug
mkdir _runtest/debugger$(RUNTIME_SUFFIX)
ln -s ../ocamldebug _runtest/debugger$(RUNTIME_SUFFIX)
cp $(main_build)/$(ocamldir)/debugger$(RUNTIME_SUFFIX)/.ocamldebug.objs/byte/*.cm* \
_runtest/debugger$(RUNTIME_SUFFIX)
# The ast_invariants test needs VERSION to be present. In fact ideally
# we should have all the source files in _runtest too for this test,
# but for the moment we accept it being a weaker check. We're not
# working on parts of the compiler that deal with the AST anyway in
# this repo.
touch _runtest/VERSION
# tools
mkdir _runtest/tools
ln -s ../_install/bin/ocamlmklib.byte _runtest/tools/ocamlmklib
ln -s ../_install/bin/ocamlobjinfo.byte _runtest/tools/ocamlobjinfo
ln -s ../_install/bin/dumpobj.byte _runtest/tools/dumpobj
# ocamldoc
# rm _runtest/ocamldoc
# mkdir _runtest/ocamldoc
# ln -s ../../_install/bin/ocamldoc.byte _runtest/ocamldoc/ocamldoc
# cp $(main_build)/$(ocamldir)/ocamldoc/.odoc_lib.objs/byte/*.cm* _runtest/ocamldoc
# ocamltest itself
mkdir _runtest/ocamltest
cp $(boot_build)/ocamltest/ocamltest.native _runtest/ocamltest/ocamltest
test: install_for_test
if [ "$(middle_end)" = "flambda2" ]; then \
for dir in `cd testsuite; ls -1 -d tests/*`; do \
if ! grep -q "^ $$dir " flambda-backend/testsuite/flambda2-test-list; then \
echo " $$dir"; \
fi; \
done > _runtest/flambda2-test-list; \
fi
(export OCAMLSRCDIR=$$(pwd)/_runtest; \
export CAML_LD_LIBRARY_PATH=$$(pwd)/_runtest/lib/ocaml/stublibs; \
if $$(which gfortran > /dev/null 2>&1); then \
export LIBRARY_PATH=$$(dirname $$(gfortran -print-file-name=libgfortran.a)); \
fi; \
cd _runtest/testsuite \
&& if $$(which parallel > /dev/null 2>&1); \
then \
echo "Running testsuite in parallel (nproc=$$(nproc))"; \
if [ "$(middle_end)" = "flambda2" ]; then \
make --no-print-directory list-parallel FILE=$$(pwd)/../flambda2-test-list; \
else \
make --no-print-directory parallel; \
fi \
else \
echo "Running testsuite sequentially"; \
if [ "$(middle_end)" = "flambda2" ]; then \
make --no-print-directory list FILE=$$(pwd)/../flambda2-test-list; \
else \
make --no-print-directory all; \
fi \
fi)
promote-failed:
(export OCAMLSRCDIR=$$(pwd)/_runtest; \
export CAML_LD_LIBRARY_PATH=$$(pwd)/_runtest/lib/ocaml/stublibs; \
if $$(which gfortran > /dev/null 2>&1); then \
export LIBRARY_PATH=$$(dirname $$(gfortran -print-file-name=libgfortran.a)); \
fi; \
cd _runtest/testsuite && make promote-failed)
runtest-upstream: test
test-one: install_for_test
$(MAKE) test-one-no-rebuild
# If the TEST argument is passed as `testsuite/tests/foo` (as is invited by
# tab completion) then look for it in `tests/foo`. Otherwise, if it's passed as
# just `foo`, then look for it in `tests/foo` for backward compatibility.
locate_test = \
$(shell \
test=$(shell echo "$1" | sed 's|^testsuite/tests/||g'); \
echo "tests/$${test}"; \
)
test-one-no-rebuild:
(export OCAMLSRCDIR=$$(pwd)/_runtest; \
export CAML_LD_LIBRARY_PATH=$$(pwd)/_runtest/lib/ocaml/stublibs; \
if $$(which gfortran > /dev/null 2>&1); then \
export LIBRARY_PATH=$$(dirname $$(gfortran -print-file-name=libgfortran.a)); \
fi; \
cd _runtest/testsuite && make one $(if $(TEST),TEST=$(call locate_test,$(TEST))) $(if $(DIR),DIR=$(call locate_test,$(DIR))))
promote-one: install_for_test
$(MAKE) promote-one-no-rebuild
promote-one-no-rebuild:
(export OCAMLSRCDIR=$$(pwd)/_runtest; \
export CAML_LD_LIBRARY_PATH=$$(pwd)/_runtest/lib/ocaml/stublibs; \
if $$(which gfortran > /dev/null 2>&1); then \
export LIBRARY_PATH=$$(dirname $$(gfortran -print-file-name=libgfortran.a)); \
fi; \
cd _runtest/testsuite && make promote $(if $(TEST),TEST=$(call locate_test,$(TEST))) $(if $(DIR),DIR=$(call locate_test,$(DIR))))
# This target is like a polling version of upstream "make ocamlopt"
.PHONY: hacking
hacking: _build/_bootinstall
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build $(ws_boot) -w $(boot_targets)
# The `hacking-emacs-poller` and `hacking-emacs-builder` targets make it
# possible to run the polling build with Emacs's `M-x compile`. You should run
# `make hacking-emacs-poller` in your terminal from the root directory of the
# repo, and set Emacs's `compile-command` to `make hacking-emacs-builder` (from
# the appropriate directory).
.PHONY: hacking-emacs-poller
hacking-emacs-poller: _build/_bootinstall
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build $(ws_boot) --passive-watch-mode
.PHONY: hacking-emacs-builder
hacking-emacs-builder: _build/_bootinstall
$(dune) rpc build $(ws_boot) -w $(boot_targets)
$(dune) diagnostics
.PHONY: debug-printers
debug-printers: runtime-stdlib # required for $(ws_main) to work
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build $(ws_main) $(ocamldir)/tools/debug_printers
@echo
@echo To load into ocamldebug, use:
@echo source \"$$(realpath _build/main/$(ocamldir)/tools/debug_printers)\"