forked from let-def/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
1659 lines (1343 loc) · 47.5 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
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#**************************************************************************
#* *
#* OCaml *
#* *
#* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
#* *
#* Copyright 1999 Institut National de Recherche en Informatique et *
#* en Automatique. *
#* *
#* All rights reserved. This file is distributed under the terms of *
#* the GNU Lesser General Public License version 2.1, with the *
#* special exception on linking described in the file LICENSE. *
#* *
#**************************************************************************
# The main Makefile
ROOTDIR = .
# NOTE: it is important that the OCAMLDEP and OCAMLLEX variables
# are defined *before* Makefile.common gets included, so that
# their local definitions here take precedence over their
# general shared definitions in Makefile.common.
OCAMLDEP ?= $(BOOT_OCAMLDEP)
OCAMLLEX ?= $(BOOT_OCAMLLEX)
include Makefile.common
.PHONY: defaultentry
ifeq "$(NATIVE_COMPILER)" "true"
defaultentry: world.opt
else
defaultentry: world
endif
ifeq "$(UNIX_OR_WIN32)" "win32"
LN = cp
else
LN = ln -sf
endif
include stdlib/StdlibModules
CAMLC = $(BOOT_OCAMLC) $(BOOT_STDLIBFLAGS) -g -use-prims runtime/primitives
CAMLOPT=$(OCAMLRUN) ./ocamlopt$(EXE) $(STDLIBFLAGS) -g -I otherlibs/dynlink
ARCHES=amd64 i386 arm arm64 power s390x riscv
DIRS = utils parsing typing bytecomp file_formats lambda middle_end \
middle_end/closure middle_end/flambda middle_end/flambda/base_types \
asmcomp driver toplevel
INCLUDES = $(addprefix -I ,$(DIRS))
COMPFLAGS=-strict-sequence -principal -absname \
-w +a-4-9-40-41-42-44-45-48-66-70 \
-warn-error +a \
-bin-annot -safe-string -strict-formats $(INCLUDES)
LINKFLAGS=
ifeq "$(strip $(NATDYNLINKOPTS))" ""
OCAML_NATDYNLINKOPTS=
else
OCAML_NATDYNLINKOPTS = -ccopt "$(NATDYNLINKOPTS)"
endif
OC_OCAMLDEPDIRS = $(DIRS)
OCAMLDOC_OPT=$(WITH_OCAMLDOC:=.opt)
OCAMLTEST_OPT=$(WITH_OCAMLTEST:=.opt)
BYTESTART=driver/main.cmo
OPTSTART=driver/optmain.cmo
TOPLEVELSTART=toplevel/topstart.cmo
TOPLEVELINIT=toplevel/toploop.cmo
# This list is passed to expunge, which accepts both uncapitalized and
# capitalized module names.
PERVASIVES=$(STDLIB_MODULES) outcometree topdirs toploop
LIBFILES=stdlib.cma std_exit.cmo *.cmi camlheader
COMPLIBDIR=$(LIBDIR)/compiler-libs
TOPINCLUDES=$(addprefix -I otherlibs/,$(filter-out %threads,$(OTHERLIBRARIES)))
ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
COLDSTART_DEPS =
else
COLDSTART_DEPS = boot/ocamlruns$(EXE)
endif
expunge := expunge$(EXE)
# targets for the compilerlibs/*.{cma,cmxa} archives
include compilerlibs/Makefile.compilerlibs
# The configuration file
CONFIG_MODULE_DEPENDENCIES = \
utils/config.common.ml Makefile.config utils/Makefile
utils/config.ml: utils/config_main.ml utils/config_boot.ml
$(MAKE) -C utils config.ml
utils/config_main.ml: utils/config.mlp $(CONFIG_MODULE_DEPENDENCIES)
$(MAKE) -C utils config_main.ml
utils/config_boot.ml: utils/config.fixed.ml $(CONFIG_MODULE_DEPENDENCIES)
$(MAKE) -C utils config_boot.ml
.PHONY: reconfigure
reconfigure:
ac_read_git_config=true ./configure $(CONFIGURE_ARGS)
utils/domainstate.ml: utils/domainstate.ml.c runtime/caml/domain_state.tbl
$(CPP) -I runtime/caml $< > $@
utils/domainstate.mli: utils/domainstate.mli.c runtime/caml/domain_state.tbl
$(CPP) -I runtime/caml $< > $@
configure: configure.ac aclocal.m4 build-aux/ocaml_version.m4 tools/autogen
tools/autogen
.PHONY: partialclean
partialclean::
rm -f utils/config.ml utils/config_main.ml utils/config_main.mli \
utils/config_boot.ml utils/config_boot.mli \
utils/domainstate.ml utils/domainstate.mli
.PHONY: beforedepend
beforedepend:: utils/config.ml utils/domainstate.ml utils/domainstate.mli
ocamlyacc_PROGRAM = yacc/ocamlyacc
PROGRAMS = expunge ocaml ocamlc ocamlc.opt ocamlnat ocamlopt ocamlopt.opt \
$(ocamlyacc_PROGRAM)
$(foreach PROGRAM, $(PROGRAMS), $(eval $(call PROGRAM_SYNONYM,$(PROGRAM))))
USE_RUNTIME_PRIMS = -use-prims ../runtime/primitives
USE_STDLIB = -nostdlib -I ../stdlib
FLEXDLL_OBJECTS = \
flexdll_$(FLEXDLL_CHAIN).$(O) flexdll_initer_$(FLEXDLL_CHAIN).$(O)
FLEXLINK_BUILD_ENV = \
MSVC_DETECT=0 OCAML_CONFIG_FILE=../Makefile.config \
CHAINS=$(FLEXDLL_CHAIN) ROOTDIR=..
FLEXDLL_SOURCE_FILES = \
$(wildcard $(FLEXDLL_SOURCES)/*.c) $(wildcard $(FLEXDLL_SOURCES)/*.h) \
$(wildcard $(FLEXDLL_SOURCES)/*.ml)
boot/ocamlruns$(EXE): runtime/ocamlruns$(EXE)
cp $< $@
boot/flexlink.byte$(EXE): $(FLEXDLL_SOURCE_FILES)
$(MAKE) -C $(FLEXDLL_SOURCES) $(FLEXLINK_BUILD_ENV) \
OCAMLRUN='$$(ROOTDIR)/boot/ocamlruns$(EXE)' NATDYNLINK=false \
OCAMLOPT='$(value BOOT_OCAMLC) $(USE_RUNTIME_PRIMS) $(USE_STDLIB)' \
-B flexlink.exe support
cp $(FLEXDLL_SOURCES)/flexlink.exe boot/flexlink.byte$(EXE)
cp $(addprefix $(FLEXDLL_SOURCES)/, $(FLEXDLL_OBJECTS)) boot/
# Start up the system from the distribution compiler
# The process depends on whether FlexDLL is also being bootstrapped.
# Normal procedure:
# - Build the runtime
# - Build the standard library using runtime/ocamlrun
# FlexDLL procedure:
# - Build ocamlruns
# - Build the standard library using boot/ocamlruns
# - Build flexlink and FlexDLL support objects
# - Build the runtime
# runtime/ocamlrun is then installed to boot/ocamlrun and the stdlib artefacts
# are copied to boot/
.PHONY: coldstart
coldstart: $(COLDSTART_DEPS)
ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
$(MAKE) runtime-all
$(MAKE) -C stdlib \
OCAMLRUN='$$(ROOTDIR)/runtime/ocamlrun$(EXE)' \
CAMLC='$$(BOOT_OCAMLC) $(USE_RUNTIME_PRIMS)' all
else
$(MAKE) -C stdlib OCAMLRUN='$$(ROOTDIR)/boot/ocamlruns$(EXE)' \
CAMLC='$$(BOOT_OCAMLC)' all
$(MAKE) boot/flexlink.byte$(EXE)
$(MAKE) runtime-all
endif # ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
cd boot; rm -f $(LIBFILES)
cd stdlib; cp $(LIBFILES) ../boot
cd boot; $(LN) ../runtime/libcamlrun.$(A) .
# Recompile the core system using the bootstrap compiler
.PHONY: coreall
coreall: runtime
$(MAKE) ocamlc
$(MAKE) ocamllex ocamltools library
# Build the core system: the minimum needed to make depend and bootstrap
.PHONY: core
core: coldstart
$(MAKE) coreall
# Check if fixpoint reached
# We use tools/cmpbyt because it has better error reporting, but cmp could also
# be used.
CMPCMD ?= $(OCAMLRUN) tools/cmpbyt$(EXE)
.PHONY: compare
compare:
# The core system has to be rebuilt after bootstrap anyway, so strip ocamlc
# and ocamllex, which means the artefacts should be identical.
mv ocamlc$(EXE) ocamlc.tmp
$(OCAMLRUN) tools/stripdebug ocamlc.tmp ocamlc$(EXE)
mv lex/ocamllex$(EXE) ocamllex.tmp
$(OCAMLRUN) tools/stripdebug ocamllex.tmp lex/ocamllex$(EXE)
rm -f ocamllex.tmp ocamlc.tmp
@if $(CMPCMD) boot/ocamlc ocamlc$(EXE) \
&& $(CMPCMD) boot/ocamllex lex/ocamllex$(EXE); \
then echo "Fixpoint reached, bootstrap succeeded."; \
else \
echo "Fixpoint not reached, try one more bootstrapping cycle."; \
exit 1; \
fi
# Promote a compiler
PROMOTE ?= cp
.PHONY: promote-common
promote-common:
$(PROMOTE) ocamlc$(EXE) boot/ocamlc
$(PROMOTE) lex/ocamllex$(EXE) boot/ocamllex
cd stdlib; cp $(LIBFILES) ../boot
# Promote the newly compiled system to the rank of cross compiler
# (Runs on the old runtime, produces code for the new runtime)
.PHONY: promote-cross
promote-cross: promote-common
# Promote the newly compiled system to the rank of bootstrap compiler
# (Runs on the new runtime, produces code for the new runtime)
.PHONY: promote
promote: PROMOTE = $(OCAMLRUN) tools/stripdebug
promote: promote-common
cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
# Compile the native-code compiler
.PHONY: opt-core
opt-core: runtimeopt
$(MAKE) ocamlopt
$(MAKE) libraryopt
.PHONY: opt
opt: checknative
$(MAKE) runtimeopt
$(MAKE) ocamlopt
$(MAKE) libraryopt
$(MAKE) otherlibrariesopt ocamltoolsopt
# Native-code versions of the tools
.PHONY: opt.opt
opt.opt: checknative
$(MAKE) checkstack
$(MAKE) coreall
$(MAKE) ocaml
$(MAKE) opt-core
ifeq "$(BOOTSTRAPPING_FLEXDLL)" "true"
$(MAKE) flexlink.opt$(EXE)
endif
$(MAKE) ocamlc.opt
$(MAKE) otherlibraries $(WITH_DEBUGGER) $(WITH_OCAMLDOC) \
$(WITH_OCAMLTEST)
$(MAKE) ocamlopt.opt
$(MAKE) otherlibrariesopt
$(MAKE) ocamllex.opt ocamltoolsopt ocamltoolsopt.opt $(OCAMLDOC_OPT) \
$(OCAMLTEST_OPT) ocamlnat
ifeq "$(WITH_OCAMLDOC)-$(STDLIB_MANPAGES)" "ocamldoc-true"
$(MAKE) manpages
endif
# Core bootstrapping cycle
.PHONY: coreboot
ifeq "$(FLAT_FLOAT_ARRAY)" "true"
coreboot:
# Promote the new compiler but keep the old runtime
# This compiler runs on boot/ocamlrun and produces bytecode for
# runtime/ocamlrun
$(MAKE) promote-cross
# Rebuild ocamlc and ocamllex (run on runtime/ocamlrun)
# utils/config.ml will have the fixed bootstrap configuration
$(MAKE) partialclean
$(MAKE) IN_COREBOOT_CYCLE=true ocamlc ocamllex ocamltools
# Rebuild the library (using runtime/ocamlrun ./ocamlc)
$(MAKE) library-cross
# Promote the new compiler and the new runtime
$(MAKE) OCAMLRUN=runtime/ocamlrun$(EXE) promote
# Rebuild the core system
# utils/config.ml must still have the fixed bootstrap configuration
$(MAKE) partialclean
$(MAKE) IN_COREBOOT_CYCLE=true core
# Check if fixpoint reached
$(MAKE) compare
else
coreboot:
$(error Cannot bootstrap when configured with \
--disable-flat-float-array)
endif
# Recompile the system using the bootstrap compiler
.PHONY: all
all: coreall
$(MAKE) ocaml
$(MAKE) otherlibraries $(WITH_DEBUGGER) $(WITH_OCAMLDOC) \
$(WITH_OCAMLTEST)
ifeq "$(WITH_OCAMLDOC)-$(STDLIB_MANPAGES)" "ocamldoc-true"
$(MAKE) manpages
endif
# Bootstrap and rebuild the whole system.
# The compilation of ocaml will fail if the runtime has changed.
# Never mind, just do make bootstrap to reach fixpoint again.
.PHONY: bootstrap
bootstrap: coreboot
# utils/config.ml must be restored to config.status's configuration
# lex/ocamllex$(EXE) was stripped in order to compare it
rm -f utils/config.ml lex/ocamllex$(EXE)
$(MAKE) all
# Compile everything the first time
.PHONY: world
world: coldstart
$(MAKE) all
# Compile also native code compiler and libraries, fast
.PHONY: world.opt
world.opt: checknative
$(MAKE) coldstart
$(MAKE) opt.opt
# FlexDLL sources missing error messages
# Different git mechanism displayed depending on whether this source tree came
# from a git clone or a source tarball.
.PHONY: flexdll flexlink flexlink.opt
ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
flexdll flexlink flexlink.opt:
@echo It is no longer necessary to bootstrap FlexDLL with a separate
@echo make invocation. Simply place the sources for FlexDLL in a
@echo sub-directory.
@echo This can either be done by downloading a source tarball from
@echo \ https://github.com/alainfrisch/flexdll/releases
@if [ -d .git ]; then \
echo or by checking out the flexdll submodule with; \
echo \ git submodule update --init; \
else \
echo or by cloning the git repository; \
echo \ git clone https://github.com/alainfrisch/flexdll.git; \
fi
@echo "Then pass --with-flexdll=<dir> to configure and build as normal."
@false
else
.PHONY: flexdll
flexdll: flexdll/Makefile
@echo WARNING! make flexdll is no longer required
@echo This target will be removed in a future release.
.PHONY: flexlink
flexlink:
@echo Bootstrapping just flexlink.exe is no longer supported
@echo Bootstrapping FlexDLL is now enabled with
@echo ./configure --with-flexdll
@false
ifeq "$(wildcard ocamlopt.opt$(EXE))" ""
FLEXLINK_OCAMLOPT=../runtime/ocamlrun$(EXE) ../ocamlopt$(EXE)
else
FLEXLINK_OCAMLOPT=../ocamlopt.opt$(EXE)
endif
flexlink.opt$(EXE): $(FLEXDLL_SOURCE_FILES)
$(MAKE) -C $(FLEXDLL_SOURCES) $(FLEXLINK_BUILD_ENV) \
OCAML_FLEXLINK='$(value OCAMLRUN) $$(ROOTDIR)/boot/flexlink.byte$(EXE)' \
OCAMLOPT="$(FLEXLINK_OCAMLOPT) -nostdlib -I ../stdlib" -B flexlink.exe
cp $(FLEXDLL_SOURCES)/flexlink.exe $@
partialclean::
rm -f flexlink.opt$(EXE)
endif # ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
INSTALL_COMPLIBDIR = $(DESTDIR)$(COMPLIBDIR)
INSTALL_FLEXDLLDIR = $(INSTALL_LIBDIR)/flexdll
FLEXDLL_MANIFEST = default$(filter-out _i386,_$(ARCH)).manifest
DOC_FILES=\
Changes \
README.adoc \
README.win32.adoc \
LICENSE
# Run all tests
.PHONY: tests
tests:
$(MAKE) -C testsuite all
# Make clean in the test suite
.PHONY: clean
clean::
$(MAKE) -C testsuite clean
# Build the manual latex files from the etex source files
# (see manual/README.md)
.PHONY: manual-pregen
manual-pregen: opt.opt
cd manual; $(MAKE) clean && $(MAKE) pregen-etex
clean::
$(MAKE) -C manual clean
# The clean target
clean:: partialclean
rm -f $(PROGRAMS) $(PROGRAMS:=.exe)
# The bytecode compiler
ocamlc$(EXE): compilerlibs/ocamlcommon.cma \
compilerlibs/ocamlbytecomp.cma $(BYTESTART)
$(CAMLC) $(LINKFLAGS) -compat-32 -o $@ $^
partialclean::
rm -rf ocamlc$(EXE)
# The native-code compiler
ocamlopt$(EXE): compilerlibs/ocamlcommon.cma compilerlibs/ocamloptcomp.cma \
$(OPTSTART)
$(CAMLC) $(LINKFLAGS) -o $@ $^
partialclean::
rm -f ocamlopt$(EXE)
# The toplevel
ocaml_dependencies := \
compilerlibs/ocamlcommon.cma \
compilerlibs/ocamlbytecomp.cma \
compilerlibs/ocamltoplevel.cma $(TOPLEVELSTART)
.INTERMEDIATE: ocaml.tmp
ocaml.tmp: $(ocaml_dependencies)
$(CAMLC) $(LINKFLAGS) -I toplevel/byte -linkall -o $@ $^
ocaml$(EXE): $(expunge) ocaml.tmp
- $(OCAMLRUN) $^ $@ $(PERVASIVES)
partialclean::
rm -f ocaml$(EXE)
# Use TOPFLAGS to pass additional flags to the bytecode or native toplevel
# when running make runtop or make natruntop
TOPFLAGS ?=
OC_TOPFLAGS = $(STDLIBFLAGS) -I toplevel -noinit $(TOPINCLUDES) $(TOPFLAGS)
# Note: Beware that, since this rule begins with a coldstart, both
# boot/ocamlrun and runtime/ocamlrun will be the same when the toplevel
# is run.
.PHONY: runtop
runtop:
$(MAKE) coldstart
$(MAKE) ocamlc
$(MAKE) otherlibraries
$(MAKE) ocaml
@$(RLWRAP) $(OCAMLRUN) ./ocaml$(EXE) $(OC_TOPFLAGS)
.PHONY: natruntop
natruntop:
$(MAKE) core
$(MAKE) opt
$(MAKE) ocamlnat
@$(FLEXLINK_ENV) $(RLWRAP) ./ocamlnat$(EXE) $(OC_TOPFLAGS)
# Native dynlink
otherlibs/dynlink/dynlink.cmxa: otherlibs/dynlink/native/dynlink.ml
$(MAKE) -C otherlibs/dynlink allopt
# Cleanup the lexer
partialclean::
rm -f parsing/lexer.ml
beforedepend:: parsing/lexer.ml
# The bytecode compiler compiled with the native-code compiler
ocamlc.opt$(EXE): compilerlibs/ocamlcommon.cmxa \
compilerlibs/ocamlbytecomp.cmxa $(BYTESTART:.cmo=.cmx)
$(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^ -cclib "$(BYTECCLIBS)"
partialclean::
rm -f ocamlc.opt$(EXE)
# The native-code compiler compiled with itself
ocamlopt.opt$(EXE): \
compilerlibs/ocamlcommon.cmxa \
compilerlibs/ocamloptcomp.cmxa \
$(OPTSTART:.cmo=.cmx)
$(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^
partialclean::
rm -f ocamlopt.opt$(EXE)
# The predefined exceptions and primitives
lambda/runtimedef.ml: lambda/generate_runtimedef.sh runtime/caml/fail.h \
runtime/primitives
$^ > $@
partialclean::
rm -f lambda/runtimedef.ml
beforedepend:: lambda/runtimedef.ml
# Choose the right machine-dependent files
asmcomp/arch.ml: asmcomp/$(ARCH)/arch.ml
cd asmcomp; $(LN) $(ARCH)/arch.ml .
asmcomp/proc.ml: asmcomp/$(ARCH)/proc.ml
cd asmcomp; $(LN) $(ARCH)/proc.ml .
asmcomp/selection.ml: asmcomp/$(ARCH)/selection.ml
cd asmcomp; $(LN) $(ARCH)/selection.ml .
asmcomp/CSE.ml: asmcomp/$(ARCH)/CSE.ml
cd asmcomp; $(LN) $(ARCH)/CSE.ml .
asmcomp/reload.ml: asmcomp/$(ARCH)/reload.ml
cd asmcomp; $(LN) $(ARCH)/reload.ml .
asmcomp/scheduling.ml: asmcomp/$(ARCH)/scheduling.ml
cd asmcomp; $(LN) $(ARCH)/scheduling.ml .
# Preprocess the code emitters
cvt_emit := tools/cvt_emit$(EXE)
asmcomp/emit.ml: asmcomp/$(ARCH)/emit.mlp $(cvt_emit)
echo \# 1 \"asmcomp/$(ARCH)/emit.mlp\" > $@
$(OCAMLRUN) $(cvt_emit) < $< >> $@ \
|| { rm -f $@; exit 2; }
partialclean::
rm -f asmcomp/emit.ml
beforedepend:: asmcomp/emit.ml
$(cvt_emit): tools/cvt_emit.mll
$(MAKE) -C tools cvt_emit
# The "expunge" utility
$(expunge): compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma \
toplevel/expunge.cmo
$(CAMLC) $(LINKFLAGS) -o $@ $^
partialclean::
rm -f $(expunge)
# The runtime system
## Lists of source files
runtime_COMMON_C_SOURCES = \
addrmap \
afl \
alloc \
array \
backtrace \
bigarray \
callback \
codefrag \
compare \
custom \
debugger \
domain \
dynlink \
extern \
fiber \
finalise \
floats \
gc_ctrl \
gc_stats \
globroots \
hash \
intern \
ints \
io \
lexing \
lf_skiplist \
main \
major_gc \
md5 \
memory \
memprof \
meta \
minor_gc \
misc \
obj \
parsing \
platform \
printexc \
prng \
roots \
runtime_events \
shared_heap \
signals \
skiplist \
startup_aux \
str \
sync \
sys \
$(UNIX_OR_WIN32) \
weak
runtime_BYTECODE_ONLY_C_SOURCES = \
backtrace_byt \
fail_byt \
fix_code \
interp \
startup_byt
runtime_BYTECODE_C_SOURCES = \
$(runtime_COMMON_C_SOURCES:%=runtime/%.c) \
$(runtime_BYTECODE_ONLY_C_SOURCES:%=runtime/%.c)
runtime_NATIVE_ONLY_C_SOURCES = \
backtrace_nat \
clambda_checks \
dynlink_nat \
fail_nat \
frame_descriptors \
startup_nat \
signals_nat
runtime_NATIVE_C_SOURCES = \
$(runtime_COMMON_C_SOURCES:%=runtime/%.c) \
$(runtime_NATIVE_ONLY_C_SOURCES:%=runtime/%.c)
## Header files generated by configure
runtime_CONFIGURED_HEADERS = $(addprefix runtime/caml/, m.h s.h version.h)
## Header files generated by make
runtime_BUILT_HEADERS = $(addprefix runtime/, \
caml/opnames.h caml/jumptbl.h build_config.h)
## Targets to build and install
runtime_PROGRAMS = runtime/ocamlrun$(EXE)
runtime_BYTECODE_STATIC_LIBRARIES = $(addprefix runtime/, \
ld.conf libcamlrun.$(A))
runtime_BYTECODE_SHARED_LIBRARIES =
runtime_NATIVE_STATIC_LIBRARIES = runtime/libasmrun.$(A)
runtime_NATIVE_SHARED_LIBRARIES =
ifeq "$(RUNTIMED)" "true"
runtime_PROGRAMS += runtime/ocamlrund$(EXE)
runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlrund.$(A)
runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmrund.$(A)
endif
ifeq "$(INSTRUMENTED_RUNTIME)" "true"
runtime_PROGRAMS += runtime/ocamlruni$(EXE)
runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlruni.$(A)
runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmruni.$(A)
endif
ifeq "$(UNIX_OR_WIN32)" "unix"
ifeq "$(SUPPORTS_SHARED_LIBRARIES)" "true"
runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlrun_pic.$(A)
runtime_BYTECODE_SHARED_LIBRARIES += runtime/libcamlrun_shared.$(SO)
runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmrun_pic.$(A)
runtime_NATIVE_SHARED_LIBRARIES += runtime/libasmrun_shared.$(SO)
endif
endif
## List of object files for each target
libcamlrun_OBJECTS = $(runtime_BYTECODE_C_SOURCES:.c=.b.$(O))
libcamlrun_non_shared_OBJECTS = \
$(subst $(UNIX_OR_WIN32).b.$(O),$(UNIX_OR_WIN32)_non_shared.b.$(O), \
$(libcamlrun_OBJECTS))
libcamlrund_OBJECTS = $(runtime_BYTECODE_C_SOURCES:.c=.bd.$(O)) \
runtime/instrtrace.bd.$(O)
libcamlruni_OBJECTS = $(runtime_BYTECODE_C_SOURCES:.c=.bi.$(O))
libcamlrunpic_OBJECTS = $(runtime_BYTECODE_C_SOURCES:.c=.bpic.$(O))
libasmrun_OBJECTS = \
$(runtime_NATIVE_C_SOURCES:.c=.n.$(O)) $(runtime_ASM_OBJECTS)
libasmrund_OBJECTS = \
$(runtime_NATIVE_C_SOURCES:.c=.nd.$(O)) $(runtime_ASM_OBJECTS:.$(O)=.d.$(O))
libasmruni_OBJECTS = \
$(runtime_NATIVE_C_SOURCES:.c=.ni.$(O)) $(runtime_ASM_OBJECTS:.$(O)=.i.$(O))
libasmrunpic_OBJECTS = $(runtime_NATIVE_C_SOURCES:.c=.npic.$(O)) \
$(runtime_ASM_OBJECTS:.$(O)=_libasmrunpic.$(O))
## General (non target-specific) assembler and compiler flags
runtime_CPPFLAGS = -DCAMLDLLIMPORT=
ocamlrund_CPPFLAGS = -DDEBUG
ocamlruni_CPPFLAGS = -DCAML_INSTR
## Runtime targets
.PHONY: runtime-all
runtime-all: \
$(runtime_BYTECODE_STATIC_LIBRARIES) $(runtime_BYTECODE_SHARED_LIBRARIES) \
$(runtime_PROGRAMS) $(SAK)
.PHONY: runtime-allopt
ifneq "$(NATIVE_COMPILER)" "false"
runtime-allopt: \
$(runtime_NATIVE_STATIC_LIBRARIES) $(runtime_NATIVE_SHARED_LIBRARIES)
else
runtime-allopt:
$(error The build has been configured with --disable-native-compiler)
endif
## Generated non-object files
runtime/ld.conf: $(ROOTDIR)/Makefile.config
echo "$(STUBLIBDIR)" > $@
echo "$(LIBDIR)" >> $@
# If primitives contain duplicated lines (e.g. because the code is defined
# like
# #ifdef X
# CAMLprim value caml_foo() ...
# #else
# CAMLprim value caml_foo() ...
# #endif), horrible things will happen: duplicated entries in Runtimedef ->
# double registration in Symtable -> empty entry in the PRIM table ->
# the bytecode interpreter is confused.
# We sort the primitive file and remove duplicates to avoid this problem.
# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC
# port, the "sort" program in the path is Microsoft's and not cygwin's
# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly.
# Sort is unstable for "is_directory" and "isatty"
# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html:
# "using sort to process pathnames, it is recommended that LC_ALL .. set to C"
# To speed up builds, we avoid changing "primitives" when files
# containing primitives change but the primitives table does not
runtime/primitives: \
$(shell runtime/gen_primitives.sh > runtime/primitives.new; \
cmp -s runtime/primitives runtime/primitives.new || \
echo runtime/primitives.new)
cp $^ $@
runtime/prims.c : runtime/primitives
(echo '#define CAML_INTERNALS'; \
echo '#include "caml/mlvalues.h"'; \
echo '#include "caml/prims.h"'; \
sed -e 's/.*/extern value &();/' $<; \
echo 'c_primitive caml_builtin_cprim[] = {'; \
sed -e 's/.*/ &,/' $<; \
echo ' 0 };'; \
echo 'char * caml_names_of_builtin_cprim[] = {'; \
sed -e 's/.*/ "&",/' $<; \
echo ' 0 };') > $@
runtime/caml/opnames.h : runtime/caml/instruct.h
tr -d '\r' < $< | \
sed -e '/\/\*/d' \
-e '/^#/d' \
-e 's/enum /static char * names_of_/' \
-e 's/{$$/[] = {/' \
-e 's/\([[:upper:]][[:upper:]_0-9]*\)/"\1"/g' > $@
# runtime/caml/jumptbl.h is required only if you have GCC 2.0 or later
runtime/caml/jumptbl.h : runtime/caml/instruct.h
tr -d '\r' < $< | \
sed -n -e '/^ /s/ \([A-Z]\)/ \&\&lbl_\1/gp' \
-e '/^}/q' > $@
# These are provided as a temporary shim to allow cross-compilation systems
# to supply a host C compiler and different flags and a linking macro.
SAK_CC ?= $(CC)
SAK_CFLAGS ?= $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS)
SAK_LINK ?= $(MKEXE_VIA_CC)
$(SAK): runtime/sak.$(O)
$(call SAK_LINK,$@,$^)
runtime/sak.$(O): runtime/sak.c runtime/caml/misc.h runtime/caml/config.h
$(SAK_CC) -c $(SAK_CFLAGS) $(OUTPUTOBJ)$@ $<
C_LITERAL = $(shell $(SAK) encode-C-literal '$(1)')
runtime/build_config.h: $(ROOTDIR)/Makefile.config $(SAK)
echo '/* This file is generated from $(ROOTDIR)/Makefile.config */' > $@
echo '#define OCAML_STDLIB_DIR $(call C_LITERAL,$(LIBDIR))' >> $@
echo '#define HOST "$(HOST)"' >> $@
## Runtime libraries and programs
runtime/ocamlrun$(EXE): runtime/prims.$(O) runtime/libcamlrun.$(A)
$(MKEXE) -o $@ $^ $(BYTECCLIBS)
runtime/ocamlruns$(EXE): runtime/prims.$(O) runtime/libcamlrun_non_shared.$(A)
$(call MKEXE_VIA_CC,$@,$^ $(BYTECCLIBS))
runtime/libcamlrun.$(A): $(libcamlrun_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libcamlrun_non_shared.$(A): $(libcamlrun_non_shared_OBJECTS)
$(call MKLIB,$@, $^)
runtime/ocamlrund$(EXE): runtime/prims.$(O) runtime/libcamlrund.$(A)
$(MKEXE) $(MKEXEDEBUGFLAG) -o $@ $^ $(BYTECCLIBS)
runtime/libcamlrund.$(A): $(libcamlrund_OBJECTS)
$(call MKLIB,$@, $^)
runtime/ocamlruni$(EXE): runtime/prims.$(O) runtime/libcamlruni.$(A)
$(MKEXE) -o $@ $^ $(INSTRUMENTED_RUNTIME_LIBS) $(BYTECCLIBS)
runtime/libcamlruni.$(A): $(libcamlruni_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libcamlrun_pic.$(A): $(libcamlrunpic_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libcamlrun_shared.$(SO): $(libcamlrunpic_OBJECTS)
$(MKDLL) -o $@ $^ $(BYTECCLIBS)
runtime/libasmrun.$(A): $(libasmrun_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libasmrund.$(A): $(libasmrund_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libasmruni.$(A): $(libasmruni_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libasmrun_pic.$(A): $(libasmrunpic_OBJECTS)
$(call MKLIB,$@, $^)
runtime/libasmrun_shared.$(SO): $(libasmrunpic_OBJECTS)
$(MKDLL) -o $@ $^ $(NATIVECCLIBS)
## Runtime target-specific preprocessor and compiler flags
runtime/%.$(O): OC_CPPFLAGS += $(runtime_CPPFLAGS)
$(DEPDIR)/runtime/%.$(D): OC_CPPFLAGS += $(runtime_CPPFLAGS)
runtime/%.bd.$(O): OC_CPPFLAGS += $(ocamlrund_CPPFLAGS)
$(DEPDIR)/runtime/%.bd.$(D): OC_CPPFLAGS += $(ocamlrund_CPPFLAGS)
runtime/%.bi.$(O): OC_CPPFLAGS += $(ocamlruni_CPPFLAGS)
$(DEPDIR)/runtime/%.bi.$(D): OC_CPPFLAGS += $(ocamlruni_CPPFLAGS)
runtime/%.bpic.$(O): OC_CFLAGS += $(SHAREDLIB_CFLAGS)
$(DEPDIR)/runtime/%.bpic.$(D): OC_CFLAGS += $(SHAREDLIB_CFLAGS)
runtime/%.n.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)
$(DEPDIR)/runtime/%.n.$(D): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)
runtime/%.nd.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlrund_CPPFLAGS)
$(DEPDIR)/runtime/%.nd.$(D): \
OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlrund_CPPFLAGS)
runtime/%.ni.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlruni_CPPFLAGS)
$(DEPDIR)/runtime/%.ni.$(D): \
OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlruni_CPPFLAGS)
runtime/%.npic.$(O): OC_CFLAGS += $(OC_NATIVE_CPPFLAGS) $(SHAREDLIB_CFLAGS)
$(DEPDIR)/runtime/%.npic.$(D): \
OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(SHAREDLIB_CFLAGS)
## Compilation of runtime C files
# The COMPILE_C_FILE macro below receives as argument the pattern
# that corresponds to the name of the generated object file
# (without the extension, which is added by the macro)
define COMPILE_C_FILE
ifneq "$(COMPUTE_DEPS)" "false"
ifneq "$(1)" "%"
# -MG would ensure that the dependencies are generated even if the files listed
# in $$(runtime_BUILT_HEADERS) haven't been assembled yet. However,
# this goes subtly wrong if the user has the headers installed,
# as gcc will pick up a dependency on those instead and the local
# ones will not be generated. For this reason, we don't use -MG and
# instead include $(runtime_BUILT_HEADERS) in the order only dependencies
# to ensure that they exist before dependencies are computed.
$(DEPDIR)/$(1).$(D): runtime/%.c | $(DEPDIR)/runtime $(runtime_BUILT_HEADERS)
$$(DEP_CC) $$(OC_CPPFLAGS) $$(CPPFLAGS) $$< -MT \
'runtime/$$*$(subst runtime/%,,$(1)).$(O)' -MF $$@
endif # ifneq "$(1)" "%"
$(1).$(O): $(2).c
else
$(1).$(O): $(2).c \
$(runtime_CONFIGURED_HEADERS) $(runtime_BUILT_HEADERS) \
$(RUNTIME_HEADERS)
endif # ifneq "$(COMPUTE_DEPS)" "false"
$$(CC) -c $$(OC_CFLAGS) $$(CFLAGS) $$(OC_CPPFLAGS) $$(CPPFLAGS) \
$$(OUTPUTOBJ)$$@ $$<
endef
$(DEPDIR)/runtime:
$(MKDIR) $@
runtime_OBJECT_TYPES = % %.b %.bd %.bi %.bpic
ifneq "$(NATIVE_COMPILER)" "false"
runtime_OBJECT_TYPES += %.n %.nd %.ni %.np %.npic
endif
$(foreach runtime_OBJECT_TYPE, $(runtime_OBJECT_TYPES), \
$(eval $(call COMPILE_C_FILE,runtime/$(runtime_OBJECT_TYPE),runtime/%)))
runtime/$(UNIX_OR_WIN32)_non_shared.%.$(O): \
OC_CPPFLAGS += -DBUILDING_LIBCAMLRUNS
$(eval $(call COMPILE_C_FILE,runtime/$(UNIX_OR_WIN32)_non_shared.%, \
runtime/$(UNIX_OR_WIN32)))
$(foreach runtime_OBJECT_TYPE,$(subst %,,$(runtime_OBJECT_TYPES)), \
$(eval \
runtime/dynlink$(runtime_OBJECT_TYPE).$(O): $(ROOTDIR)/Makefile.config))
## Compilation of runtime assembly files
ASPP_ERROR = \
{ echo "If your assembler produced syntax errors, it is probably";\
echo "unhappy with the preprocessor. Check your assembler, or";\
echo "try producing $*.o by hand.";\
exit 2; }
runtime/%.o: runtime/%.S
$(ASPP) $(OC_ASPPFLAGS) -o $@ $< || $(ASPP_ERROR)
runtime/%.d.o: runtime/%.S
$(ASPP) $(OC_ASPPFLAGS) $(OC_DEBUG_CPPFLAGS) -o $@ $< || $(ASPP_ERROR)
runtime/%.i.o: runtime/%.S
$(ASPP) $(OC_ASPPFLAGS) $(OC_INSTR_CPPFLAGS) -o $@ $< || $(ASPP_ERROR)
runtime/%_libasmrunpic.o: runtime/%.S
$(ASPP) $(OC_ASPPFLAGS) $(SHAREDLIB_CFLAGS) -o $@ $<
runtime/domain_state64.inc: \
runtime/gen_domain_state64_inc.awk runtime/caml/domain_state.tbl
$(AWK) -f $^ > $@
runtime/domain_state32.inc: \
runtime/gen_domain_state32_inc.awk runtime/caml/domain_state.tbl
$(AWK) -f $^ > $@
runtime/amd64nt.obj: runtime/amd64nt.asm runtime/domain_state64.inc
$(ASM)$@ $<
runtime/i386nt.obj: runtime/i386nt.asm runtime/domain_state32.inc
$(ASM)$@ $<
runtime/amd64nt.d.obj: runtime/amd64nt.asm runtime/domain_state64.inc
$(ASM)$@ $(ocamlrund_CPPFLAGS) $<
runtime/i386nt.d.obj: runtime/i386nt.asm runtime/domain_state32.inc
$(ASM)$@ $(ocmalrund_CPPFLAGS) $<
runtime/amd64nt.i.obj: runtime/amd64nt.asm runtime/domain_state64.inc
$(ASM)$@ $(ocamlruni_CPPFLAGS) $<
runtime/i386nt.i.obj: runtime/i386nt.asm runtime/domain_state32.inc
$(ASM)$@ $(ocamlruni_CPPFLAGS) $<
runtime/%_libasmrunpic.obj: runtime/%.asm
$(ASM)$@ $<
## Runtime dependencies
runtime_DEP_FILES := $(addsuffix .b, \
$(basename $(runtime_BYTECODE_C_SOURCES) runtime/instrtrace))
ifneq "$(NATIVE_COMPILER)" "false"
runtime_DEP_FILES += $(addsuffix .n, $(basename $(runtime_NATIVE_C_SOURCES)))
endif
runtime_DEP_FILES += $(addsuffix d, $(runtime_DEP_FILES)) \
$(addsuffix i, $(runtime_DEP_FILES)) \