1 #**************************************************************************
2 #* *
3 #* OCaml *
4 #* *
5 #* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
6 #* *
7 #* Copyright 1999 Institut National de Recherche en Informatique et *
8 #* en Automatique. *
9 #* *
10 #* All rights reserved. This file is distributed under the terms of *
11 #* the GNU Lesser General Public License version 2.1, with the *
12 #* special exception on linking described in the file LICENSE. *
13 #* *
14 #**************************************************************************
15
16 # The main Makefile
17
18 ROOTDIR = .
19
20 include Makefile.config
21 include Makefile.common
22
23 .PHONY: defaultentry
24 ifeq "$(NATIVE_COMPILER)" "true"
25 defaultentry: world.opt
26 else
27 defaultentry: world
28 endif
29
30 MKDIR=mkdir -p
31 ifeq "$(UNIX_OR_WIN32)" "win32"
32 LN = cp
33 else
34 LN = ln -sf
35 endif
36
37 include stdlib/StdlibModules
38
39 CAMLC=$(BOOT_OCAMLC) -g -nostdlib -I boot -use-prims runtime/primitives
40 CAMLOPT=$(CAMLRUN) ./ocamlopt -g -nostdlib -I stdlib -I otherlibs/dynlink
41 ARCHES=amd64 i386 arm arm64 power s390x
42 INCLUDES=-I utils -I parsing -I typing -I bytecomp -I file_formats \
43 -I lambda -I middle_end -I middle_end/closure \
44 -I middle_end/flambda -I middle_end/flambda/base_types \
45 -I asmcomp -I asmcomp/debug \
46 -I driver -I toplevel
47
48 COMPFLAGS=-strict-sequence -principal -absname -w +a-4-9-40-41-42-44-45-48-66 \
49 -warn-error A \
50 -bin-annot -safe-string -strict-formats $(INCLUDES)
51 ifeq "$(FUNCTION_SECTIONS)" "true"
52 OPTCOMPFLAGS= -function-sections
53 else
54 OPTCOMPFLAGS=
55 endif
56 LINKFLAGS=
57
58 ifeq "$(strip $(NATDYNLINKOPTS))" ""
59 OCAML_NATDYNLINKOPTS=
60 else
61 OCAML_NATDYNLINKOPTS = -ccopt "$(NATDYNLINKOPTS)"
62 endif
63
64 YACCFLAGS=-v --strict
65 CAMLLEX=$(CAMLRUN) boot/ocamllex
66 CAMLDEP=$(CAMLRUN) boot/ocamlc -depend
67 DEPFLAGS=-slash
68 DEPINCLUDES=$(INCLUDES)
69
70 OCAMLDOC_OPT=$(WITH_OCAMLDOC:=.opt)
71
72 UTILS=utils/config.cmo utils/build_path_prefix_map.cmo utils/misc.cmo \
73 utils/identifiable.cmo utils/numbers.cmo utils/arg_helper.cmo \
74 utils/clflags.cmo utils/profile.cmo utils/load_path.cmo \
75 utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \
76 utils/consistbl.cmo utils/strongly_connected_components.cmo \
77 utils/targetint.cmo utils/int_replace_polymorphic_compare.cmo \
78 utils/domainstate.cmo
79
80 PARSING=parsing/location.cmo parsing/longident.cmo \
81 parsing/docstrings.cmo parsing/syntaxerr.cmo \
82 parsing/ast_helper.cmo \
83 parsing/pprintast.cmo \
84 parsing/camlinternalMenhirLib.cmo parsing/parser.cmo \
85 parsing/lexer.cmo parsing/parse.cmo parsing/printast.cmo \
86 parsing/ast_mapper.cmo parsing/ast_iterator.cmo parsing/attr_helper.cmo \
87 parsing/builtin_attributes.cmo parsing/ast_invariants.cmo parsing/depend.cmo
88
89 TYPING=typing/ident.cmo typing/path.cmo \
90 typing/primitive.cmo typing/type_immediacy.cmo typing/types.cmo \
91 typing/btype.cmo typing/oprint.cmo \
92 typing/subst.cmo typing/predef.cmo \
93 typing/datarepr.cmo file_formats/cmi_format.cmo \
94 typing/persistent_env.cmo typing/env.cmo \
95 typing/typedtree.cmo typing/printtyped.cmo typing/ctype.cmo \
96 typing/printtyp.cmo typing/includeclass.cmo \
97 typing/mtype.cmo typing/envaux.cmo typing/includecore.cmo \
98 typing/tast_iterator.cmo typing/tast_mapper.cmo \
99 file_formats/cmt_format.cmo typing/untypeast.cmo \
100 typing/includemod.cmo typing/typetexp.cmo typing/printpat.cmo \
101 typing/parmatch.cmo typing/stypes.cmo \
102 typing/typedecl_properties.cmo typing/typedecl_variance.cmo \
103 typing/typedecl_unboxed.cmo typing/typedecl_immediacy.cmo \
104 typing/typedecl.cmo typing/typeopt.cmo \
105 typing/rec_check.cmo typing/typecore.cmo typing/typeclass.cmo \
106 typing/typemod.cmo
107
108 LAMBDA=lambda/debuginfo.cmo \
109 lambda/lambda.cmo lambda/printlambda.cmo \
110 lambda/switch.cmo lambda/matching.cmo \
111 lambda/translobj.cmo lambda/translattribute.cmo \
112 lambda/translprim.cmo lambda/translcore.cmo \
113 lambda/translclass.cmo lambda/translmod.cmo \
114 lambda/simplif.cmo lambda/runtimedef.cmo
115
116 COMP=\
117 bytecomp/meta.cmo bytecomp/opcodes.cmo \
118 bytecomp/bytesections.cmo bytecomp/dll.cmo \
119 bytecomp/symtable.cmo \
120 driver/pparse.cmo driver/compenv.cmo \
121 driver/main_args.cmo driver/compmisc.cmo \
122 driver/makedepend.cmo \
123 driver/compile_common.cmo
124
125 COMMON=$(UTILS) $(PARSING) $(TYPING) $(LAMBDA) $(COMP)
126
127 BYTECOMP=bytecomp/instruct.cmo bytecomp/bytegen.cmo \
128 bytecomp/printinstr.cmo bytecomp/emitcode.cmo \
129 bytecomp/bytelink.cmo bytecomp/bytelibrarian.cmo bytecomp/bytepackager.cmo \
130 driver/errors.cmo driver/compile.cmo
131
132 ARCH_SPECIFIC =\
133 asmcomp/arch.ml asmcomp/proc.ml asmcomp/CSE.ml asmcomp/selection.ml \
134 asmcomp/scheduling.ml asmcomp/reload.ml
135
136 INTEL_ASM=\
137 asmcomp/x86_proc.cmo \
138 asmcomp/x86_dsl.cmo \
139 asmcomp/x86_gas.cmo \
140 asmcomp/x86_masm.cmo
141
142 ARCH_SPECIFIC_ASMCOMP=
143 ifeq ($(ARCH),i386)
144 ARCH_SPECIFIC_ASMCOMP=$(INTEL_ASM)
145 endif
146 ifeq ($(ARCH),amd64)
147 ARCH_SPECIFIC_ASMCOMP=$(INTEL_ASM)
148 endif
149
150 ASMCOMP=\
151 $(ARCH_SPECIFIC_ASMCOMP) \
152 asmcomp/arch.cmo \
153 asmcomp/cmm.cmo asmcomp/printcmm.cmo \
154 asmcomp/reg.cmo asmcomp/debug/reg_with_debug_info.cmo \
155 asmcomp/debug/reg_availability_set.cmo \
156 asmcomp/mach.cmo asmcomp/proc.cmo \
157 asmcomp/afl_instrument.cmo \
158 asmcomp/strmatch.cmo \
159 asmcomp/cmmgen_state.cmo \
160 asmcomp/cmm_helpers.cmo \
161 asmcomp/cmmgen.cmo \
162 asmcomp/interval.cmo \
163 asmcomp/printmach.cmo asmcomp/selectgen.cmo \
164 asmcomp/spacetime_profiling.cmo asmcomp/selection.cmo \
165 asmcomp/comballoc.cmo \
166 asmcomp/CSEgen.cmo asmcomp/CSE.cmo \
167 asmcomp/liveness.cmo \
168 asmcomp/spill.cmo asmcomp/split.cmo \
169 asmcomp/interf.cmo asmcomp/coloring.cmo \
170 asmcomp/linscan.cmo \
171 asmcomp/reloadgen.cmo asmcomp/reload.cmo \
172 asmcomp/deadcode.cmo \
173 asmcomp/linear.cmo asmcomp/printlinear.cmo asmcomp/linearize.cmo \
174 asmcomp/debug/available_regs.cmo \
175 asmcomp/debug/compute_ranges_intf.cmo \
176 asmcomp/debug/compute_ranges.cmo \
177 asmcomp/schedgen.cmo asmcomp/scheduling.cmo \
178 asmcomp/branch_relaxation_intf.cmo \
179 asmcomp/branch_relaxation.cmo \
180 asmcomp/emitaux.cmo asmcomp/emit.cmo asmcomp/asmgen.cmo \
181 asmcomp/asmlink.cmo asmcomp/asmlibrarian.cmo asmcomp/asmpackager.cmo \
182 driver/opterrors.cmo driver/optcompile.cmo
183
184 # Files under middle_end/ are not to reference files under asmcomp/.
185 # This ensures that the middle end can be linked (e.g. for objinfo) even when
186 # the native code compiler is not present for some particular target.
187
188 MIDDLE_END_CLOSURE=\
189 middle_end/closure/closure.cmo \
190 middle_end/closure/closure_middle_end.cmo
191
192 # Owing to dependencies through [Compilenv], which would be
193 # difficult to remove, some of the lower parts of Flambda (anything that is
194 # saved in a .cmx file) have to be included in the [MIDDLE_END] stanza, below.
195 MIDDLE_END_FLAMBDA=\
196 middle_end/flambda/import_approx.cmo \
197 middle_end/flambda/lift_code.cmo \
198 middle_end/flambda/closure_conversion_aux.cmo \
199 middle_end/flambda/closure_conversion.cmo \
200 middle_end/flambda/initialize_symbol_to_let_symbol.cmo \
201 middle_end/flambda/lift_let_to_initialize_symbol.cmo \
202 middle_end/flambda/find_recursive_functions.cmo \
203 middle_end/flambda/invariant_params.cmo \
204 middle_end/flambda/inconstant_idents.cmo \
205 middle_end/flambda/alias_analysis.cmo \
206 middle_end/flambda/lift_constants.cmo \
207 middle_end/flambda/share_constants.cmo \
208 middle_end/flambda/simplify_common.cmo \
209 middle_end/flambda/remove_unused_arguments.cmo \
210 middle_end/flambda/remove_unused_closure_vars.cmo \
211 middle_end/flambda/remove_unused_program_constructs.cmo \
212 middle_end/flambda/simplify_boxed_integer_ops.cmo \
213 middle_end/flambda/simplify_primitives.cmo \
214 middle_end/flambda/inlining_stats_types.cmo \
215 middle_end/flambda/inlining_stats.cmo \
216 middle_end/flambda/inline_and_simplify_aux.cmo \
217 middle_end/flambda/remove_free_vars_equal_to_args.cmo \
218 middle_end/flambda/extract_projections.cmo \
219 middle_end/flambda/augment_specialised_args.cmo \
220 middle_end/flambda/unbox_free_vars_of_closures.cmo \
221 middle_end/flambda/unbox_specialised_args.cmo \
222 middle_end/flambda/unbox_closures.cmo \
223 middle_end/flambda/inlining_transforms.cmo \
224 middle_end/flambda/inlining_decision.cmo \
225 middle_end/flambda/inline_and_simplify.cmo \
226 middle_end/flambda/ref_to_variables.cmo \
227 middle_end/flambda/flambda_invariants.cmo \
228 middle_end/flambda/traverse_for_exported_symbols.cmo \
229 middle_end/flambda/build_export_info.cmo \
230 middle_end/flambda/closure_offsets.cmo \
231 middle_end/flambda/un_anf.cmo \
232 middle_end/flambda/flambda_to_clambda.cmo \
233 middle_end/flambda/flambda_middle_end.cmo
234
235 MIDDLE_END=\
236 middle_end/internal_variable_names.cmo \
237 middle_end/linkage_name.cmo \
238 middle_end/compilation_unit.cmo \
239 middle_end/variable.cmo \
240 middle_end/flambda/base_types/closure_element.cmo \
241 middle_end/flambda/base_types/closure_id.cmo \
242 middle_end/symbol.cmo \
243 middle_end/backend_var.cmo \
244 middle_end/clambda_primitives.cmo \
245 middle_end/printclambda_primitives.cmo \
246 middle_end/clambda.cmo \
247 middle_end/printclambda.cmo \
248 middle_end/semantics_of_primitives.cmo \
249 middle_end/convert_primitives.cmo \
250 middle_end/flambda/base_types/id_types.cmo \
251 middle_end/flambda/base_types/export_id.cmo \
252 middle_end/flambda/base_types/tag.cmo \
253 middle_end/flambda/base_types/mutable_variable.cmo \
254 middle_end/flambda/base_types/set_of_closures_id.cmo \
255 middle_end/flambda/base_types/set_of_closures_origin.cmo \
256 middle_end/flambda/base_types/closure_origin.cmo \
257 middle_end/flambda/base_types/var_within_closure.cmo \
258 middle_end/flambda/base_types/static_exception.cmo \
259 middle_end/flambda/pass_wrapper.cmo \
260 middle_end/flambda/allocated_const.cmo \
261 middle_end/flambda/parameter.cmo \
262 middle_end/flambda/projection.cmo \
263 middle_end/flambda/flambda.cmo \
264 middle_end/flambda/flambda_iterators.cmo \
265 middle_end/flambda/flambda_utils.cmo \
266 middle_end/flambda/freshening.cmo \
267 middle_end/flambda/effect_analysis.cmo \
268 middle_end/flambda/inlining_cost.cmo \
269 middle_end/flambda/simple_value_approx.cmo \
270 middle_end/flambda/export_info.cmo \
271 middle_end/flambda/export_info_for_pack.cmo \
272 middle_end/compilenv.cmo \
273 $(MIDDLE_END_CLOSURE) \
274 $(MIDDLE_END_FLAMBDA)
275
276 OPTCOMP=$(MIDDLE_END) $(ASMCOMP)
277
278 TOPLEVEL=toplevel/genprintval.cmo toplevel/toploop.cmo \
279 toplevel/trace.cmo toplevel/topdirs.cmo toplevel/topmain.cmo
280
281 OPTTOPLEVEL=toplevel/genprintval.cmo toplevel/opttoploop.cmo \
282 toplevel/opttopdirs.cmo toplevel/opttopmain.cmo
283 BYTESTART=driver/main.cmo
284
285 OPTSTART=driver/optmain.cmo
286
287 TOPLEVELSTART=toplevel/topstart.cmo
288
289 OPTTOPLEVELSTART=toplevel/opttopstart.cmo
290
291 PERVASIVES=$(STDLIB_MODULES) outcometree topdirs toploop
292
293 LIBFILES=stdlib.cma std_exit.cmo *.cmi camlheader
294
295 COMPLIBDIR=$(LIBDIR)/compiler-libs
296
297 TOPINCLUDES=$(addprefix -I otherlibs/,$(filter-out %threads,$(OTHERLIBRARIES)))
298 RUNTOP=./runtime/ocamlrun ./ocaml \
299 -nostdlib -I stdlib \
300 -noinit $(TOPFLAGS) $(TOPINCLUDES)
301 NATRUNTOP=./ocamlnat$(EXE) \
302 -nostdlib -I stdlib \
303 -noinit $(TOPFLAGS) $(TOPINCLUDES)
304 ifeq "$(UNIX_OR_WIN32)" "unix"
305 EXTRAPATH=
306 else
307 EXTRAPATH = PATH="otherlibs/win32unix:$(PATH)"
308 endif
309
310 BOOT_FLEXLINK_CMD=
311
312 ifeq "$(UNIX_OR_WIN32)" "win32"
313 FLEXDLL_SUBMODULE_PRESENT := $(wildcard flexdll/Makefile)
314 ifeq "$(FLEXDLL_SUBMODULE_PRESENT)" ""
315 BOOT_FLEXLINK_CMD =
316 else
317 BOOT_FLEXLINK_CMD = FLEXLINK_CMD="../boot/ocamlrun ../flexdll/flexlink.exe"
318 endif
319 else
320 endif
321
322 # The configuration file
323
324 utils/config.ml: utils/config.mlp Makefile.config utils/Makefile
325 $(MAKE) -C utils config.ml
326
327 .PHONY: reconfigure
328 reconfigure:
329 ac_read_git_config=true ./configure $(CONFIGURE_ARGS)
330
331 utils/domainstate.ml: utils/domainstate.ml.c runtime/caml/domain_state.tbl
332 $(CPP) -I runtime/caml $< > $@
333
334 utils/domainstate.mli: utils/domainstate.mli.c runtime/caml/domain_state.tbl
335 $(CPP) -I runtime/caml $< > $@
336
337 .PHONY: partialclean
338 partialclean::
339 rm -f utils/config.ml utils/domainstate.ml utils/domainstate.mli
340
341 .PHONY: beforedepend
342 beforedepend:: utils/config.ml utils/domainstate.ml utils/domainstate.mli
343
344 # Start up the system from the distribution compiler
345 .PHONY: coldstart
346 coldstart:
347 $(MAKE) -C runtime $(BOOT_FLEXLINK_CMD) all
348 cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
349 $(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) \
350 CAMLC='$$(BOOT_OCAMLC) -use-prims ../runtime/primitives' all
351 cd stdlib; cp $(LIBFILES) ../boot
352 cd boot; $(LN) ../runtime/libcamlrun.$(A) .
353
354 # Recompile the core system using the bootstrap compiler
355 .PHONY: coreall
356 coreall: runtime
357 $(MAKE) ocamlc
358 $(MAKE) ocamllex ocamltools library
359
360 # Build the core system: the minimum needed to make depend and bootstrap
361 .PHONY: core
362 core:
363 $(MAKE) coldstart
364 $(MAKE) coreall
365
366 # Check if fixpoint reached
367 .PHONY: compare
368 compare:
369 @if $(CAMLRUN) tools/cmpbyt boot/ocamlc ocamlc \
370 && $(CAMLRUN) tools/cmpbyt boot/ocamllex lex/ocamllex; \
371 then echo "Fixpoint reached, bootstrap succeeded."; \
372 else \
373 echo "Fixpoint not reached, try one more bootstrapping cycle."; \
374 exit 1; \
375 fi
376
377 # Promote a compiler
378
379 PROMOTE ?= cp
380
381 .PHONY: promote-common
382 promote-common:
383 $(PROMOTE) ocamlc boot/ocamlc
384 $(PROMOTE) lex/ocamllex boot/ocamllex
385 cd stdlib; cp $(LIBFILES) ../boot
386
387 # Promote the newly compiled system to the rank of cross compiler
388 # (Runs on the old runtime, produces code for the new runtime)
389 .PHONY: promote-cross
390 promote-cross: promote-common
391
392 # Promote the newly compiled system to the rank of bootstrap compiler
393 # (Runs on the new runtime, produces code for the new runtime)
394 .PHONY: promote
395 promote: PROMOTE = $(CAMLRUN) tools/stripdebug
396 promote: promote-common
397 cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
398
399 # Compile the native-code compiler
400 .PHONY: opt-core
401 opt-core: runtimeopt
402 $(MAKE) ocamlopt
403 $(MAKE) libraryopt
404
405 .PHONY: opt
406 opt: checknative
407 $(MAKE) runtimeopt
408 $(MAKE) ocamlopt
409 $(MAKE) libraryopt
410 $(MAKE) otherlibrariesopt ocamltoolsopt
411
412 # Native-code versions of the tools
413 .PHONY: opt.opt
414 opt.opt: checknative
415 $(MAKE) checkstack
416 $(MAKE) runtime
417 $(MAKE) core
418 $(MAKE) ocaml
419 $(MAKE) opt-core
420 $(MAKE) ocamlc.opt
421 $(MAKE) otherlibraries $(WITH_DEBUGGER) $(WITH_OCAMLDOC) ocamltest
422 $(MAKE) ocamlopt.opt
423 $(MAKE) otherlibrariesopt
424 $(MAKE) ocamllex.opt ocamltoolsopt ocamltoolsopt.opt $(OCAMLDOC_OPT) \
425 ocamltest.opt
426 ifneq "$(WITH_OCAMLDOC)" ""
427 $(MAKE) manpages
428 endif
429
430 # Core bootstrapping cycle
431 .PHONY: coreboot
432 coreboot:
433 # Promote the new compiler but keep the old runtime
434 # This compiler runs on boot/ocamlrun and produces bytecode for
435 # runtime/ocamlrun
436 $(MAKE) promote-cross
437 # Rebuild ocamlc and ocamllex (run on runtime/ocamlrun)
438 $(MAKE) partialclean
439 $(MAKE) ocamlc ocamllex ocamltools
440 # Rebuild the library (using runtime/ocamlrun ./ocamlc)
441 $(MAKE) library-cross
442 # Promote the new compiler and the new runtime
443 $(MAKE) CAMLRUN=runtime/ocamlrun promote
444 # Rebuild the core system
445 $(MAKE) partialclean
446 $(MAKE) core
447 # Check if fixpoint reached
448 $(MAKE) compare
449
450 # Recompile the system using the bootstrap compiler
451
452 .PHONY: all
453 all: coreall
454 $(MAKE) ocaml
455 $(MAKE) otherlibraries $(WITH_DEBUGGER) $(WITH_OCAMLDOC) ocamltest
456 ifneq "$(WITH_OCAMLDOC)" ""
457 $(MAKE) manpages
458 endif
459
460 # Bootstrap and rebuild the whole system.
461 # The compilation of ocaml will fail if the runtime has changed.
462 # Never mind, just do make bootstrap to reach fixpoint again.
463 .PHONY: bootstrap
464 bootstrap: coreboot
465 $(MAKE) all
466
467 # Compile everything the first time
468
469 .PHONY: world
470 world: coldstart
471 $(MAKE) all
472
473 # Compile also native code compiler and libraries, fast
474 .PHONY: world.opt
475 world.opt: checknative
476 $(MAKE) coldstart
477 $(MAKE) opt.opt
478
479 # FlexDLL sources missing error messages
480 # Different git mechanism displayed depending on whether this source tree came
481 # from a git clone or a source tarball.
482
483 flexdll/Makefile:
484 @echo In order to bootstrap FlexDLL, you need to place the sources in
485 @echo flexdll.
486 @echo This can either be done by downloading a source tarball from
487 @echo \ http://alain.frisch.fr/flexdll.html
488 @if [ -d .git ]; then \
489 echo or by checking out the flexdll submodule with; \
490 echo \ git submodule update --init; \
491 else \
492 echo or by cloning the git repository; \
493 echo \ git clone https://github.com/alainfrisch/flexdll.git; \
494 fi
495 @false
496
497 .PHONY: flexdll
498 flexdll: flexdll/Makefile flexlink
499 $(MAKE) -C flexdll \
500 OCAML_CONFIG_FILE=../Makefile.config \
501 MSVC_DETECT=0 CHAINS=$(FLEXDLL_CHAIN) NATDYNLINK=false support
502
503 # Bootstrapping flexlink - leaves a bytecode image of flexlink.exe in flexdll/
504 .PHONY: flexlink
505 flexlink: flexdll/Makefile
506 $(MAKE) -C runtime BOOTSTRAPPING_FLEXLINK=yes ocamlrun$(EXE)
507 cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
508 $(MAKE) -C stdlib COMPILER=../boot/ocamlc \
509 $(filter-out *.cmi,$(LIBFILES))
510 cd stdlib && cp $(LIBFILES) ../boot/
511 $(MAKE) -C flexdll MSVC_DETECT=0 OCAML_CONFIG_FILE=../Makefile.config \
512 CHAINS=$(FLEXDLL_CHAIN) NATDYNLINK=false \
513 OCAMLOPT="../boot/ocamlrun ../boot/ocamlc -nostdlib -I ../boot" \
514 flexlink.exe
515 $(MAKE) -C runtime clean
516 $(MAKE) partialclean
517
518 .PHONY: flexlink.opt
519 flexlink.opt:
520 cd flexdll && \
521 mv flexlink.exe flexlink && \
522 ($(MAKE) OCAML_FLEXLINK="../boot/ocamlrun ./flexlink" MSVC_DETECT=0 \
523 OCAML_CONFIG_FILE=../Makefile.config \
524 OCAMLOPT="../ocamlopt.opt -nostdlib -I ../stdlib" \
525 flexlink.exe || \
526 (mv flexlink flexlink.exe && false)) && \
527 mv flexlink.exe flexlink.opt && \
528 mv flexlink flexlink.exe
529
530 INSTALL_COMPLIBDIR=$(DESTDIR)$(COMPLIBDIR)
531 INSTALL_FLEXDLLDIR=$(INSTALL_LIBDIR)/flexdll
532
533 .PHONY: install-flexdll
534 install-flexdll:
535 $(INSTALL_PROG) flexdll/flexlink.exe "$(INSTALL_BINDIR)/flexlink$(EXE)"
536 ifneq "$(filter-out mingw,$(TOOLCHAIN))" ""
537 $(INSTALL_DATA) flexdll/default$(filter-out _i386,_$(ARCH)).manifest \
538 "$(INSTALL_BINDIR)/"
539 endif
540 if test -n "$(wildcard flexdll/flexdll_*.$(O))" ; then \
541 $(MKDIR) "$(INSTALL_FLEXDLLDIR)" ; \
542 $(INSTALL_DATA) flexdll/flexdll_*.$(O) "$(INSTALL_FLEXDLLDIR)" ; \
543 fi
544
545 # Installation
546 .PHONY: install
547 install:
548 $(MKDIR) "$(INSTALL_BINDIR)"
549 $(MKDIR) "$(INSTALL_LIBDIR)"
550 $(MKDIR) "$(INSTALL_STUBLIBDIR)"
551 $(MKDIR) "$(INSTALL_COMPLIBDIR)"
552 $(INSTALL_DATA) \
553 VERSION \
554 "$(INSTALL_LIBDIR)"
555 $(MAKE) -C runtime install
556 $(INSTALL_PROG) ocaml "$(INSTALL_BINDIR)/ocaml$(EXE)"
557 ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
558 $(INSTALL_PROG) ocamlc "$(INSTALL_BINDIR)/ocamlc.byte$(EXE)"
559 endif
560 $(MAKE) -C stdlib install
561 ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
562 $(INSTALL_PROG) lex/ocamllex "$(INSTALL_BINDIR)/ocamllex.byte$(EXE)"
563 endif
564 $(INSTALL_PROG) yacc/ocamlyacc$(EXE) "$(INSTALL_BINDIR)/ocamlyacc$(EXE)"
565 $(INSTALL_DATA) \
566 utils/*.cmi \
567 parsing/*.cmi \
568 typing/*.cmi \
569 bytecomp/*.cmi \
570 file_formats/*.cmi \
571 lambda/*.cmi \
572 driver/*.cmi \
573 toplevel/*.cmi \
574 "$(INSTALL_COMPLIBDIR)"
575 ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
576 $(INSTALL_DATA) \
577 utils/*.cmt utils/*.cmti utils/*.mli \
578 parsing/*.cmt parsing/*.cmti parsing/*.mli \
579 typing/*.cmt typing/*.cmti typing/*.mli \
580 file_formats/*.cmt file_formats/*.cmti file_formats/*.mli \
581 lambda/*.cmt lambda/*.cmti lambda/*.mli \
582 bytecomp/*.cmt bytecomp/*.cmti bytecomp/*.mli \
583 driver/*.cmt driver/*.cmti driver/*.mli \
584 toplevel/*.cmt toplevel/*.cmti toplevel/*.mli \
585 "$(INSTALL_COMPLIBDIR)"
586 endif
587 $(INSTALL_DATA) \
588 compilerlibs/*.cma \
589 "$(INSTALL_COMPLIBDIR)"
590 $(INSTALL_DATA) \
591 $(BYTESTART) $(TOPLEVELSTART) \
592 "$(INSTALL_COMPLIBDIR)"
593 $(INSTALL_PROG) expunge "$(INSTALL_LIBDIR)/expunge$(EXE)"
594 $(INSTALL_DATA) \
595 toplevel/topdirs.cmi \
596 "$(INSTALL_LIBDIR)"
597 ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
598 $(INSTALL_DATA) \
599 toplevel/topdirs.cmt toplevel/topdirs.cmti \
600 toplevel/topdirs.mli \
601 "$(INSTALL_LIBDIR)"
602 endif
603 $(MAKE) -C tools install
604 ifeq "$(UNIX_OR_WIN32)" "unix" # Install manual pages only on Unix
605 $(MKDIR) "$(INSTALL_MANDIR)/man$(PROGRAMS_MAN_SECTION)"
606 -$(MAKE) -C man install
607 endif
608 for i in $(OTHERLIBRARIES); do \
609 $(MAKE) -C otherlibs/$$i install || exit $$?; \
610 done
611 # Transitional: findlib 1.7.3 is confused if leftover num.cm? files remain
612 # from an previous installation of OCaml before otherlibs/num was removed.
613 rm -f "$(INSTALL_LIBDIR)"/num.cm?
614 # End transitional
615 ifneq "$(WITH_OCAMLDOC)" ""
616 $(MAKE) -C ocamldoc install
617 endif
618 if test -n "$(WITH_DEBUGGER)"; then \
619 $(MAKE) -C debugger install; \
620 fi
621 ifeq "$(UNIX_OR_WIN32)" "win32"
622 if test -n "$(FLEXDLL_SUBMODULE_PRESENT)"; then \
623 $(MAKE) install-flexdll; \
624 fi
625 endif
626 $(INSTALL_DATA) Makefile.config "$(INSTALL_LIBDIR)/Makefile.config"
627 ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
628 if test -f ocamlopt; then $(MAKE) installopt; else \
629 cd "$(INSTALL_BINDIR)"; \
630 $(LN) ocamlc.byte$(EXE) ocamlc$(EXE); \
631 $(LN) ocamllex.byte$(EXE) ocamllex$(EXE); \
632 fi
633 else
634 if test -f ocamlopt; then $(MAKE) installopt; fi
635 endif
636
637 # Installation of the native-code compiler
638 .PHONY: installopt
639 installopt:
640 $(MAKE) -C runtime installopt
641 ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
642 $(INSTALL_PROG) ocamlopt "$(INSTALL_BINDIR)/ocamlopt.byte$(EXE)"
643 endif
644 $(MAKE) -C stdlib installopt
645 $(INSTALL_DATA) \
646 middle_end/*.cmi \
647 "$(INSTALL_COMPLIBDIR)"
648 $(INSTALL_DATA) \
649 middle_end/closure/*.cmi \
650 "$(INSTALL_COMPLIBDIR)"
651 $(INSTALL_DATA) \
652 middle_end/flambda/*.cmi \
653 "$(INSTALL_COMPLIBDIR)"
654 $(INSTALL_DATA) \
655 middle_end/flambda/base_types/*.cmi \
656 "$(INSTALL_COMPLIBDIR)"
657 $(INSTALL_DATA) \
658 asmcomp/*.cmi \
659 "$(INSTALL_COMPLIBDIR)"
660 $(INSTALL_DATA) \
661 asmcomp/debug/*.cmi \
662 "$(INSTALL_COMPLIBDIR)"
663 ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
664 $(INSTALL_DATA) \
665 middle_end/*.cmt middle_end/*.cmti \
666 middle_end/*.mli \
667 "$(INSTALL_COMPLIBDIR)"
668 $(INSTALL_DATA) \
669 middle_end/closure/*.cmt middle_end/closure/*.cmti \
670 middle_end/closure/*.mli \
671 "$(INSTALL_COMPLIBDIR)"
672 $(INSTALL_DATA) \
673 middle_end/flambda/*.cmt middle_end/flambda/*.cmti \
674 middle_end/flambda/*.mli \
675 "$(INSTALL_COMPLIBDIR)"
676 $(INSTALL_DATA) \
677 middle_end/flambda/base_types/*.cmt \
678 middle_end/flambda/base_types/*.cmti \
679 middle_end/flambda/base_types/*.mli \
680 "$(INSTALL_COMPLIBDIR)"
681 $(INSTALL_DATA) \
682 asmcomp/*.cmt asmcomp/*.cmti \
683 asmcomp/*.mli \
684 "$(INSTALL_COMPLIBDIR)"
685 $(INSTALL_DATA) \
686 asmcomp/debug/*.cmt asmcomp/debug/*.cmti \
687 asmcomp/debug/*.mli \
688 "$(INSTALL_COMPLIBDIR)"
689 endif
690 $(INSTALL_DATA) \
691 $(OPTSTART) \
692 "$(INSTALL_COMPLIBDIR)"
693 ifneq "$(WITH_OCAMLDOC)" ""
694 $(MAKE) -C ocamldoc installopt
695 endif
696 for i in $(OTHERLIBRARIES); do \
697 $(MAKE) -C otherlibs/$$i installopt || exit $$?; \
698 done
699 ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
700 if test -f ocamlopt.opt ; then $(MAKE) installoptopt; else \
701 cd "$(INSTALL_BINDIR)"; \
702 $(LN) ocamlc.byte$(EXE) ocamlc$(EXE); \
703 $(LN) ocamlopt.byte$(EXE) ocamlopt$(EXE); \
704 $(LN) ocamllex.byte$(EXE) ocamllex$(EXE); \
705 fi
706 else
707 if test -f ocamlopt.opt ; then $(MAKE) installoptopt; fi
708 endif
709 $(MAKE) -C tools installopt
710 if test -f ocamlopt.opt -a -f flexdll/flexlink.opt ; then \
711 $(INSTALL_PROG) \
712 flexdll/flexlink.opt "$(INSTALL_BINDIR)/flexlink$(EXE)" ; \
713 fi
714
715 .PHONY: installoptopt
716 installoptopt:
717 $(INSTALL_PROG) ocamlc.opt "$(INSTALL_BINDIR)/ocamlc.opt$(EXE)"
718 $(INSTALL_PROG) ocamlopt.opt "$(INSTALL_BINDIR)/ocamlopt.opt$(EXE)"
719 $(INSTALL_PROG) \
720 lex/ocamllex.opt "$(INSTALL_BINDIR)/ocamllex.opt$(EXE)"
721 cd "$(INSTALL_BINDIR)"; \
722 $(LN) ocamlc.opt$(EXE) ocamlc$(EXE); \
723 $(LN) ocamlopt.opt$(EXE) ocamlopt$(EXE); \
724 $(LN) ocamllex.opt$(EXE) ocamllex$(EXE)
725 $(INSTALL_DATA) \
726 utils/*.cmx parsing/*.cmx typing/*.cmx bytecomp/*.cmx \
727 file_formats/*.cmx \
728 lambda/*.cmx \
729 driver/*.cmx asmcomp/*.cmx middle_end/*.cmx \
730 middle_end/closure/*.cmx \
731 middle_end/flambda/*.cmx \
732 middle_end/flambda/base_types/*.cmx \
733 asmcomp/debug/*.cmx \
734 "$(INSTALL_COMPLIBDIR)"
735 $(INSTALL_DATA) \
736 compilerlibs/*.cmxa compilerlibs/*.$(A) \
737 "$(INSTALL_COMPLIBDIR)"
738 $(INSTALL_DATA) \
739 $(BYTESTART:.cmo=.cmx) $(BYTESTART:.cmo=.$(O)) \
740 $(OPTSTART:.cmo=.cmx) $(OPTSTART:.cmo=.$(O)) \
741 "$(INSTALL_COMPLIBDIR)"
742 if test -f ocamlnat$(EXE) ; then \
743 $(INSTALL_PROG) \
744 ocamlnat$(EXE) "$(INSTALL_BINDIR)/ocamlnat$(EXE)"; \
745 $(INSTALL_DATA) \
746 toplevel/opttopdirs.cmi \
747 "$(INSTALL_LIBDIR)"; \
748 $(INSTALL_DATA) \
749 $(OPTTOPLEVELSTART:.cmo=.cmx) $(OPTTOPLEVELSTART:.cmo=.$(O)) \
750 "$(INSTALL_COMPLIBDIR)"; \
751 fi
752 cd "$(INSTALL_COMPLIBDIR)" && \
753 $(RANLIB) ocamlcommon.$(A) ocamlbytecomp.$(A) ocamloptcomp.$(A)
754
755 # Installation of the *.ml sources of compiler-libs
756 .PHONY: install-compiler-sources
757 install-compiler-sources:
758 ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
759 $(INSTALL_DATA) \
760 utils/*.ml parsing/*.ml typing/*.ml bytecomp/*.ml driver/*.ml \
761 file_formats/*.ml \
762 lambda/*.ml \
763 toplevel/*.ml middle_end/*.ml middle_end/closure/*.ml \
764 middle_end/flambda/*.ml middle_end/flambda/base_types/*.ml \
765 asmcomp/*.ml \
766 asmcmp/debug/*.ml \
767 "$(INSTALL_COMPLIBDIR)"
768 endif
769
770 # Run all tests
771
772 .PHONY: tests
773 tests:
774 $(MAKE) -C testsuite all
775
776 # Make clean in the test suite
777
778 .PHONY: clean
779 clean::
780 $(MAKE) -C testsuite clean
781
782 # Build the manual latex files from the etex source files
783 # (see manual/README.md)
784 .PHONY: manual-pregen
785 manual-pregen: opt.opt
786 cd manual; $(MAKE) clean && $(MAKE) pregen-etex
787
788 # The clean target
789 clean:: partialclean
790
791 # Shared parts of the system
792
793 compilerlibs/ocamlcommon.cma: $(COMMON)
794 $(CAMLC) -a -linkall -o $@ $^
795 partialclean::
796 rm -f compilerlibs/ocamlcommon.cma
797
798 # The bytecode compiler
799
800 compilerlibs/ocamlbytecomp.cma: $(BYTECOMP)
801 $(CAMLC) -a -o $@ $^
802 partialclean::
803 rm -f compilerlibs/ocamlbytecomp.cma
804
805 ocamlc: compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma $(BYTESTART)
806 $(CAMLC) $(LINKFLAGS) -compat-32 -o $@ $^
807
808 partialclean::
809 rm -rf ocamlc
810
811 # The native-code compiler
812
813 compilerlibs/ocamloptcomp.cma: $(OPTCOMP)
814 $(CAMLC) -a -o $@ $^
815
816 partialclean::
817 rm -f compilerlibs/ocamloptcomp.cma
818
819 ocamlopt: compilerlibs/ocamlcommon.cma compilerlibs/ocamloptcomp.cma \
820 $(OPTSTART)
821 $(CAMLC) $(LINKFLAGS) -o $@ $^
822
823 partialclean::
824 rm -f ocamlopt
825
826 # The toplevel
827
828 compilerlibs/ocamltoplevel.cma: $(TOPLEVEL)
829 $(CAMLC) -a -o $@ $^
830 partialclean::
831 rm -f compilerlibs/ocamltoplevel.cma
832
833 ocaml_dependencies := \
834 compilerlibs/ocamlcommon.cma \
835 compilerlibs/ocamlbytecomp.cma \
836 compilerlibs/ocamltoplevel.cma $(TOPLEVELSTART)
837
838 .INTERMEDIATE: ocaml.tmp
839 ocaml.tmp: $(ocaml_dependencies)
840 $(CAMLC) $(LINKFLAGS) -linkall -o $@ $^
841
842 ocaml: expunge ocaml.tmp
843 - $(CAMLRUN) $^ $@ $(PERVASIVES)
844
845 partialclean::
846 rm -f ocaml
847
848 .PHONY: runtop
849 runtop:
850 $(MAKE) coldstart
851 $(MAKE) ocamlc
852 $(MAKE) otherlibraries
853 $(MAKE) ocaml
854 @rlwrap --help 2>/dev/null && $(EXTRAPATH) rlwrap $(RUNTOP) ||\
855 $(EXTRAPATH) $(RUNTOP)
856
857 .PHONY: natruntop
858 natruntop:
859 $(MAKE) core
860 $(MAKE) opt
861 $(MAKE) ocamlnat
862 @rlwrap --help 2>/dev/null && $(EXTRAPATH) rlwrap $(NATRUNTOP) ||\
863 $(EXTRAPATH) $(NATRUNTOP)
864
865 # Native dynlink
866
867 otherlibs/dynlink/dynlink.cmxa: otherlibs/dynlink/native/dynlink.ml
868 $(MAKE) -C otherlibs/dynlink allopt
869
870 # The lexer
871
872 parsing/lexer.ml: parsing/lexer.mll
873 $(CAMLLEX) $(OCAMLLEX_FLAGS) $<
874
875 partialclean::
876 rm -f parsing/lexer.ml
877
878 beforedepend:: parsing/lexer.ml
879
880 # Shared parts of the system compiled with the native-code compiler
881
882 compilerlibs/ocamlcommon.cmxa: $(COMMON:.cmo=.cmx)
883 $(CAMLOPT) -a -linkall -o $@ $^
884 partialclean::
885 rm -f compilerlibs/ocamlcommon.cmxa compilerlibs/ocamlcommon.$(A)
886
887 # The bytecode compiler compiled with the native-code compiler
888
889 compilerlibs/ocamlbytecomp.cmxa: $(BYTECOMP:.cmo=.cmx)
890 $(CAMLOPT) -a $(OCAML_NATDYNLINKOPTS) -o $@ $^
891 partialclean::
892 rm -f compilerlibs/ocamlbytecomp.cmxa compilerlibs/ocamlbytecomp.$(A)
893
894 ocamlc.opt: compilerlibs/ocamlcommon.cmxa compilerlibs/ocamlbytecomp.cmxa \
895 $(BYTESTART:.cmo=.cmx)
896 $(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^ -cclib "$(BYTECCLIBS)"
897
898 partialclean::
899 rm -f ocamlc.opt
900
901 # The native-code compiler compiled with itself
902
903 compilerlibs/ocamloptcomp.cmxa: $(OPTCOMP:.cmo=.cmx)
904 $(CAMLOPT) -a -o $@ $^
905 partialclean::
906 rm -f compilerlibs/ocamloptcomp.cmxa compilerlibs/ocamloptcomp.$(A)
907
908 ocamlopt.opt: compilerlibs/ocamlcommon.cmxa compilerlibs/ocamloptcomp.cmxa \
909 $(OPTSTART:.cmo=.cmx)
910 $(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^
911
912 partialclean::
913 rm -f ocamlopt.opt
914
915 $(COMMON:.cmo=.cmx) $(BYTECOMP:.cmo=.cmx) $(OPTCOMP:.cmo=.cmx): ocamlopt
916
917 # The predefined exceptions and primitives
918
919 runtime/primitives:
920 $(MAKE) -C runtime primitives
921
922 lambda/runtimedef.ml: lambda/generate_runtimedef.sh runtime/caml/fail.h \
923 runtime/primitives
924 $^ > $@
925
926 partialclean::
927 rm -f lambda/runtimedef.ml
928
929 beforedepend:: lambda/runtimedef.ml
930
931 # Choose the right machine-dependent files
932
933 asmcomp/arch.ml: asmcomp/$(ARCH)/arch.ml
934 cd asmcomp; $(LN) $(ARCH)/arch.ml .
935
936 asmcomp/proc.ml: asmcomp/$(ARCH)/proc.ml
937 cd asmcomp; $(LN) $(ARCH)/proc.ml .
938
939 asmcomp/selection.ml: asmcomp/$(ARCH)/selection.ml
940 cd asmcomp; $(LN) $(ARCH)/selection.ml .
941
942 asmcomp/CSE.ml: asmcomp/$(ARCH)/CSE.ml
943 cd asmcomp; $(LN) $(ARCH)/CSE.ml .
944
945 asmcomp/reload.ml: asmcomp/$(ARCH)/reload.ml
946 cd asmcomp; $(LN) $(ARCH)/reload.ml .
947
948 asmcomp/scheduling.ml: asmcomp/$(ARCH)/scheduling.ml
949 cd asmcomp; $(LN) $(ARCH)/scheduling.ml .
950
951 # Preprocess the code emitters
952
953 asmcomp/emit.ml: asmcomp/$(ARCH)/emit.mlp tools/cvt_emit
954 echo \# 1 \"$(ARCH)/emit.mlp\" > $@
955 $(CAMLRUN) tools/cvt_emit < $< >> $@ \
956 || { rm -f $@; exit 2; }
957
958 partialclean::
959 rm -f asmcomp/emit.ml
960
961 beforedepend:: asmcomp/emit.ml
962
963 tools/cvt_emit: tools/cvt_emit.mll
964 $(MAKE) -C tools cvt_emit
965
966 # The "expunge" utility
967
968 expunge: compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma \
969 toplevel/expunge.cmo
970 $(CAMLC) $(LINKFLAGS) -o $@ $^
971
972 partialclean::
973 rm -f expunge
974
975 # The runtime system for the bytecode compiler
976
977 .PHONY: runtime
978 runtime: stdlib/libcamlrun.$(A)
979
980 .PHONY: makeruntime
981 makeruntime:
982 $(MAKE) -C runtime $(BOOT_FLEXLINK_CMD) all
983 runtime/libcamlrun.$(A): makeruntime ;
984 stdlib/libcamlrun.$(A): runtime/libcamlrun.$(A)
985 cd stdlib; $(LN) ../runtime/libcamlrun.$(A) .
986 clean::
987 $(MAKE) -C runtime clean
988 rm -f stdlib/libcamlrun.$(A)
989
990 otherlibs_all := bigarray dynlink raw_spacetime_lib \
991 str systhreads unix win32unix
992 subdirs := debugger lex ocamldoc ocamltest runtime stdlib tools \
993 $(addprefix otherlibs/, $(otherlibs_all)) \
994
995 .PHONY: alldepend
996 ifeq "$(TOOLCHAIN)" "msvc"
997 alldepend:
998 $(error Dependencies cannot be regenerated using the MSVC ports)
999 else
1000 alldepend: depend
1001 for dir in $(subdirs); do \
1002 $(MAKE) -C $$dir depend || exit; \
1003 done
1004 endif
1005
1006 # The runtime system for the native-code compiler
1007
1008 .PHONY: runtimeopt
1009 runtimeopt: stdlib/libasmrun.$(A)
1010
1011 .PHONY: makeruntimeopt
1012 makeruntimeopt:
1013 $(MAKE) -C runtime $(BOOT_FLEXLINK_CMD) allopt
1014 runtime/libasmrun.$(A): makeruntimeopt ;
1015 stdlib/libasmrun.$(A): runtime/libasmrun.$(A)
1016 cp $< $@
1017 clean::
1018 rm -f stdlib/libasmrun.$(A)
1019
1020 # The standard library
1021
1022 .PHONY: library
1023 library: ocamlc
1024 $(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) all
1025
1026 .PHONY: library-cross
1027 library-cross:
1028 $(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) CAMLRUN=../runtime/ocamlrun all
1029
1030 .PHONY: libraryopt
1031 libraryopt:
1032 $(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) allopt
1033
1034 partialclean::
1035 $(MAKE) -C stdlib clean
1036
1037 # The lexer and parser generators
1038
1039 .PHONY: ocamllex
1040 ocamllex: ocamlyacc
1041 $(MAKE) -C lex all
1042
1043 .PHONY: ocamllex.opt
1044 ocamllex.opt: ocamlopt
1045 $(MAKE) -C lex allopt
1046
1047 partialclean::
1048 $(MAKE) -C lex clean
1049
1050 .PHONY: ocamlyacc
1051 ocamlyacc:
1052 $(MAKE) -C yacc $(BOOT_FLEXLINK_CMD) all
1053
1054 clean::
1055 $(MAKE) -C yacc clean
1056
1057 # The Menhir-generated parser
1058
1059 # In order to avoid a build-time dependency on Menhir,
1060 # we store the result of the parser generator (which
1061 # are OCaml source files) and Menhir's runtime libraries
1062 # (that the parser files rely on) in boot/.
1063
1064 # The rules below do not depend on Menhir being available,
1065 # they just build the parser from boot/.
1066
1067 # See Makefile.menhir for the rules to rebuild the parser and update
1068 # boot/, which require Menhir. The targets in Makefile.menhir
1069 # (also included here for convenience) must be used after any
1070 # modification of parser.mly.
1071 include Makefile.menhir
1072
1073 # To avoid module-name conflicts with compiler-lib users that link
1074 # with their code with their own MenhirLib module (possibly with
1075 # a different Menhir version), we rename MenhirLib into
1076 # CamlinternalMenhirlib -- and replace the module occurrences in the
1077 # generated parser.ml.
1078
1079 parsing/camlinternalMenhirLib.ml: boot/menhir/menhirLib.ml
1080 cp $< $@
1081 parsing/camlinternalMenhirLib.mli: boot/menhir/menhirLib.mli
1082 echo '[@@@ocaml.warning "-67"]' > $@
1083 cat $< >> $@
1084
1085 # Copy parsing/parser.ml from boot/
1086
1087 parsing/parser.ml: boot/menhir/parser.ml parsing/parser.mly \
1088 tools/check-parser-uptodate-or-warn.sh
1089 @-tools/check-parser-uptodate-or-warn.sh
1090 sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@
1091 parsing/parser.mli: boot/menhir/parser.mli
1092 sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@
1093
1094 beforedepend:: parsing/camlinternalMenhirLib.ml \
1095 parsing/camlinternalMenhirLib.mli \
1096 parsing/parser.ml parsing/parser.mli
1097
1098 partialclean:: partialclean-menhir
1099
1100
1101 # OCamldoc
1102
1103 .PHONY: ocamldoc
1104 ocamldoc: ocamlc ocamlyacc ocamllex otherlibraries
1105 $(MAKE) -C ocamldoc all
1106
1107 .PHONY: ocamldoc.opt
1108 ocamldoc.opt: ocamlc.opt ocamlyacc ocamllex
1109 $(MAKE) -C ocamldoc opt.opt
1110
1111 # OCamltest
1112 ocamltest: ocamlc ocamlyacc ocamllex
1113 $(MAKE) -C ocamltest all
1114
1115 ocamltest.opt: ocamlc.opt ocamlyacc ocamllex
1116 $(MAKE) -C ocamltest allopt
1117
1118 partialclean::
1119 $(MAKE) -C ocamltest clean
1120
1121 # Documentation
1122
1123 .PHONY: html_doc
1124 html_doc: ocamldoc
1125 $(MAKE) -C ocamldoc $@
1126 @echo "documentation is in ./ocamldoc/stdlib_html/"
1127
1128 .PHONY: manpages
1129 manpages:
1130 $(MAKE) -C ocamldoc $@
1131
1132 partialclean::
1133 $(MAKE) -C ocamldoc clean
1134
1135 # The extra libraries
1136
1137 .PHONY: otherlibraries
1138 otherlibraries: ocamltools
1139 $(MAKE) -C otherlibs all
1140
1141 .PHONY: otherlibrariesopt
1142 otherlibrariesopt:
1143 $(MAKE) -C otherlibs allopt
1144
1145 partialclean::
1146 $(MAKE) -C otherlibs partialclean
1147
1148 clean::
1149 $(MAKE) -C otherlibs clean
1150
1151 # The replay debugger
1152
1153 .PHONY: ocamldebugger
1154 ocamldebugger: ocamlc ocamlyacc ocamllex otherlibraries
1155 $(MAKE) -C debugger all
1156
1157 partialclean::
1158 $(MAKE) -C debugger clean
1159
1160 # Check that the native-code compiler is supported
1161 .PHONY: checknative
1162 checknative:
1163 ifeq "$(ARCH)" "none"
1164 checknative:
1165 $(error The native-code compiler is not supported on this platform)
1166 else
1167 @
1168 endif
1169
1170 # Check that the stack limit is reasonable (Unix-only)
1171 .PHONY: checkstack
1172 checkstack:
1173 ifeq "$(UNIX_OR_WIN32)" "unix"
1174 if $(MKEXE) $(OUTPUTEXE)tools/checkstack$(EXE) tools/checkstack.c; \
1175 then tools/checkstack$(EXE); \
1176 fi
1177 rm -f tools/checkstack$(EXE)
1178 else
1179 @
1180 endif
1181
1182 # Lint @since and @deprecated annotations
1183
1184 VERSIONS=$(shell git tag|grep '^[0-9]*.[0-9]*.[0-9]*$$'|grep -v '^[12].')
1185 .PHONY: lintapidiff
1186 lintapidiff:
1187 $(MAKE) -C tools lintapidiff.opt
1188 git ls-files -- 'otherlibs/*/*.mli' 'stdlib/*.mli' |\
1189 grep -Ev internal\|obj\|spacetime\|stdLabels\|moreLabels |\
1190 tools/lintapidiff.opt $(VERSIONS)
1191
1192 # The middle end.
1193
1194 compilerlibs/ocamlmiddleend.cma: $(MIDDLE_END)
1195 $(CAMLC) -a -o $@ $^
1196 compilerlibs/ocamlmiddleend.cmxa: $(MIDDLE_END:%.cmo=%.cmx)
1197 $(CAMLOPT) -a -o $@ $^
1198 partialclean::
1199 rm -f compilerlibs/ocamlmiddleend.cma \
1200 compilerlibs/ocamlmiddleend.cmxa \
1201 compilerlibs/ocamlmiddleend.$(A)
1202
1203 # Tools
1204
1205 .PHONY: ocamltools
1206 ocamltools: ocamlc ocamllex compilerlibs/ocamlmiddleend.cma
1207 $(MAKE) -C tools all
1208
1209 .PHONY: ocamltoolsopt
1210 ocamltoolsopt: ocamlopt
1211 $(MAKE) -C tools opt
1212
1213 .PHONY: ocamltoolsopt.opt
1214 ocamltoolsopt.opt: ocamlc.opt ocamllex.opt compilerlibs/ocamlmiddleend.cmxa
1215 $(MAKE) -C tools opt.opt
1216
1217 partialclean::
1218 $(MAKE) -C tools clean
1219
1220 ## Test compilation of backend-specific parts
1221
1222 partialclean::
1223 rm -f $(ARCH_SPECIFIC)
1224
1225 beforedepend:: $(ARCH_SPECIFIC)
1226
1227 # This rule provides a quick way to check that machine-dependent
1228 # files compiles fine for a foreign architecture (passed as ARCH=xxx).
1229
1230 .PHONY: check_arch
1231 check_arch:
1232 @echo "========= CHECKING asmcomp/$(ARCH) =============="
1233 @rm -f $(ARCH_SPECIFIC) asmcomp/emit.ml asmcomp/*.cm*
1234 @$(MAKE) compilerlibs/ocamloptcomp.cma \
1235 >/dev/null
1236 @rm -f $(ARCH_SPECIFIC) asmcomp/emit.ml asmcomp/*.cm*
1237
1238 .PHONY: check_all_arches
1239 check_all_arches:
1240 ifeq ($(ARCH64),true)
1241 @STATUS=0; \
1242 for i in $(ARCHES); do \
1243 $(MAKE) --no-print-directory check_arch ARCH=$$i || STATUS=1; \
1244 done; \
1245 exit $$STATUS
1246 else
1247 @echo "Architecture tests are disabled on 32-bit platforms."
1248 endif
1249
1250 # The native toplevel
1251
1252 compilerlibs/ocamlopttoplevel.cmxa: $(OPTTOPLEVEL:.cmo=.cmx)
1253 $(CAMLOPT) -a -o $@ $^
1254 partialclean::
1255 rm -f compilerlibs/ocamlopttoplevel.cmxa
1256
1257 # When the native toplevel executable has an extension (e.g. ".exe"),
1258 # provide a phony 'ocamlnat' synonym
1259
1260 ifneq ($(EXE),)
1261 .PHONY: ocamlnat
1262 ocamlnat: ocamlnat$(EXE)
1263 endif
1264
1265 ocamlnat$(EXE): compilerlibs/ocamlcommon.cmxa compilerlibs/ocamloptcomp.cmxa \
1266 compilerlibs/ocamlbytecomp.cmxa \
1267 otherlibs/dynlink/dynlink.cmxa \
1268 compilerlibs/ocamlopttoplevel.cmxa \
1269 $(OPTTOPLEVELSTART:.cmo=.cmx)
1270 $(CAMLOPT_CMD) $(LINKFLAGS) -linkall -o $@ $^
1271
1272 partialclean::
1273 rm -f ocamlnat$(EXE)
1274
1275 toplevel/opttoploop.cmx: otherlibs/dynlink/dynlink.cmxa
1276
1277 # The numeric opcodes
1278
1279 bytecomp/opcodes.ml: runtime/caml/instruct.h tools/make_opcodes
1280 runtime/ocamlrun tools/make_opcodes -opcodes < $< > $@
1281
1282 bytecomp/opcodes.mli: bytecomp/opcodes.ml
1283 $(CAMLC) -i $< > $@
1284
1285 tools/make_opcodes: tools/make_opcodes.mll
1286 $(MAKE) -C tools make_opcodes
1287
1288 partialclean::
1289 rm -f bytecomp/opcodes.ml
1290 rm -f bytecomp/opcodes.mli
1291
1292 beforedepend:: bytecomp/opcodes.ml bytecomp/opcodes.mli
1293
1294 ifneq "$(wildcard .git)" ""
1295 include Makefile.dev
1296 endif
1297
1298 # Default rules
1299
1300 .SUFFIXES: .ml .mli .cmo .cmi .cmx
1301
1302 .ml.cmo:
1303 $(CAMLC) $(COMPFLAGS) -c $<
1304
1305 .mli.cmi:
1306 $(CAMLC) $(COMPFLAGS) -c $<
1307
1308 .ml.cmx:
1309 $(CAMLOPT) $(COMPFLAGS) $(OPTCOMPFLAGS) -c $<
1310
1311 partialclean::
1312 for d in utils parsing typing bytecomp asmcomp middle_end file_formats \
1313 lambda middle_end/closure middle_end/flambda \
1314 middle_end/flambda/base_types asmcomp/debug \
1315 driver toplevel tools; do \
1316 rm -f $$d/*.cm[ioxt] $$d/*.cmti $$d/*.annot $$d/*.$(S) \
1317 $$d/*.$(O) $$d/*.$(SO); \
1318 done
1319
1320 .PHONY: depend
1321 depend: beforedepend
1322 (for d in utils parsing typing bytecomp asmcomp middle_end \
1323 lambda file_formats middle_end/closure middle_end/flambda \
1324 middle_end/flambda/base_types asmcomp/debug \
1325 driver toplevel; \
1326 do $(CAMLDEP) $(DEPFLAGS) $(DEPINCLUDES) $$d/*.mli $$d/*.ml || exit; \
1327 done) > .depend
1328
1329 .PHONY: distclean
1330 distclean: clean
1331 rm -f boot/ocamlrun boot/ocamlrun$(EXE) boot/camlheader \
1332 boot/*.cm* boot/libcamlrun.$(A) boot/ocamlc.opt
1333 rm -f Makefile.config runtime/caml/m.h runtime/caml/s.h
1334 rm -f tools/*.bak
1335 rm -f ocaml ocamlc
1336 rm -f testsuite/_log*
1337
1338 include .depend
1339
1340 Makefile.config Makefile.common:
1341 @echo "Please refer to the installation instructions:"
1342 @echo "- In file INSTALL for Unix systems."
1343 @echo "- In file README.win32.adoc for Windows systems."
1344 @echo "On Unix systems, if you've just unpacked the distribution,"
1345 @echo "something like"
1346 @echo " ./configure"
1347 @echo " make"
1348 @echo " make install"
1349 @echo "should work."
1350 @false
1351