forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
1086 lines (889 loc) · 29.2 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 = .
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) -g -nostdlib -I boot -use-prims runtime/primitives
CAMLOPT=$(CAMLRUN) ./ocamlopt -g -nostdlib -I stdlib -I otherlibs/dynlink
ARCHES=amd64 i386 arm arm64 power s390x riscv
INCLUDES=-I utils -I parsing -I typing -I bytecomp -I file_formats \
-I lambda -I middle_end -I middle_end/closure \
-I middle_end/flambda -I middle_end/flambda/base_types \
-I asmcomp -I asmcomp/debug \
-I driver -I toplevel
COMPFLAGS=-strict-sequence -principal -absname -w +a-4-9-40-41-42-44-45-48-66 \
-warn-error A \
-bin-annot -safe-string -strict-formats $(INCLUDES)
LINKFLAGS=
ifeq "$(strip $(NATDYNLINKOPTS))" ""
OCAML_NATDYNLINKOPTS=
else
OCAML_NATDYNLINKOPTS = -ccopt "$(NATDYNLINKOPTS)"
endif
YACCFLAGS=-v --strict
CAMLLEX=$(CAMLRUN) boot/ocamllex
CAMLDEP=$(CAMLRUN) boot/ocamlc -depend
DEPFLAGS=-slash
DEPINCLUDES=$(INCLUDES)
OCAMLDOC_OPT=$(WITH_OCAMLDOC:=.opt)
OCAMLTEST_OPT=$(WITH_OCAMLTEST:=.opt)
BYTESTART=driver/main.cmo
OPTSTART=driver/optmain.cmo
TOPLEVELSTART=toplevel/topstart.cmo
OPTTOPLEVELSTART=toplevel/opttopstart.cmo
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)))
RUNTOP=./runtime/ocamlrun ./ocaml \
-nostdlib -I stdlib \
-noinit $(TOPFLAGS) $(TOPINCLUDES)
NATRUNTOP=./ocamlnat$(EXE) \
-nostdlib -I stdlib \
-noinit $(TOPFLAGS) $(TOPINCLUDES)
ifeq "$(UNIX_OR_WIN32)" "unix"
EXTRAPATH=
else
EXTRAPATH = PATH="otherlibs/win32unix:$(PATH)"
endif
BOOT_FLEXLINK_CMD=
ifeq "$(UNIX_OR_WIN32)" "win32"
FLEXDLL_SUBMODULE_PRESENT := $(wildcard flexdll/Makefile)
ifeq "$(FLEXDLL_SUBMODULE_PRESENT)" ""
BOOT_FLEXLINK_CMD =
else
BOOT_FLEXLINK_CMD = FLEXLINK_CMD="../boot/ocamlrun ../flexdll/flexlink.exe"
endif
else
endif
# targets for the compilerlibs/*.{cma,cmxa} archives
include compilerlibs/Makefile.compilerlibs
# The configuration file
utils/config.ml: utils/config.mlp Makefile.config utils/Makefile
$(MAKE) -C utils config.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 VERSION tools/autogen
tools/autogen
.PHONY: partialclean
partialclean::
rm -f utils/config.ml utils/domainstate.ml utils/domainstate.mli
.PHONY: beforedepend
beforedepend:: utils/config.ml utils/domainstate.ml utils/domainstate.mli
# Start up the system from the distribution compiler
.PHONY: coldstart
coldstart:
$(MAKE) -C runtime $(BOOT_FLEXLINK_CMD) all
cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
$(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) \
CAMLC='$$(BOOT_OCAMLC) -use-prims ../runtime/primitives' all
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:
$(MAKE) coldstart
$(MAKE) coreall
# Check if fixpoint reached
.PHONY: compare
compare:
@if $(CAMLRUN) tools/cmpbyt boot/ocamlc ocamlc \
&& $(CAMLRUN) tools/cmpbyt boot/ocamllex lex/ocamllex; \
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 boot/ocamlc
$(PROMOTE) lex/ocamllex 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 = $(CAMLRUN) 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) runtime
$(MAKE) core
$(MAKE) ocaml
$(MAKE) opt-core
$(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)
ifeq "$(WITH_OCAMLDOC)-$(STDLIB_MANPAGES)" "ocamldoc-true"
$(MAKE) manpages
endif
# Core bootstrapping cycle
.PHONY: coreboot
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)
$(MAKE) partialclean
$(MAKE) ocamlc ocamllex ocamltools
# Rebuild the library (using runtime/ocamlrun ./ocamlc)
$(MAKE) library-cross
# Promote the new compiler and the new runtime
$(MAKE) CAMLRUN=runtime/ocamlrun promote
# Rebuild the core system
$(MAKE) partialclean
$(MAKE) core
# Check if fixpoint reached
$(MAKE) compare
# 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
$(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.
flexdll/Makefile:
@echo In order to bootstrap FlexDLL, you need to place the sources in
@echo flexdll.
@echo This can either be done by downloading a source tarball from
@echo \ http://alain.frisch.fr/flexdll.html
@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
@false
.PHONY: flexdll
flexdll: flexdll/Makefile flexlink
$(MAKE) -C flexdll \
OCAML_CONFIG_FILE=../Makefile.config \
MSVC_DETECT=0 CHAINS=$(FLEXDLL_CHAIN) NATDYNLINK=false support
# Bootstrapping flexlink - leaves a bytecode image of flexlink.exe in flexdll/
.PHONY: flexlink
flexlink: flexdll/Makefile
$(MAKE) -C runtime BOOTSTRAPPING_FLEXLINK=yes ocamlrun$(EXE)
cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE)
$(MAKE) -C stdlib COMPILER=../boot/ocamlc \
$(filter-out *.cmi,$(LIBFILES))
cd stdlib && cp $(LIBFILES) ../boot/
$(MAKE) -C flexdll MSVC_DETECT=0 OCAML_CONFIG_FILE=../Makefile.config \
CHAINS=$(FLEXDLL_CHAIN) NATDYNLINK=false \
OCAMLOPT="../boot/ocamlrun ../boot/ocamlc -nostdlib -I ../boot" \
flexlink.exe
$(MAKE) -C runtime clean
$(MAKE) partialclean
.PHONY: flexlink.opt
flexlink.opt:
cd flexdll && \
mv flexlink.exe flexlink && \
($(MAKE) OCAML_FLEXLINK="../boot/ocamlrun ./flexlink" MSVC_DETECT=0 \
OCAML_CONFIG_FILE=../Makefile.config \
OCAMLOPT="../ocamlopt.opt -nostdlib -I ../stdlib" \
flexlink.exe || \
(mv flexlink flexlink.exe && false)) && \
mv flexlink.exe flexlink.opt && \
mv flexlink flexlink.exe
INSTALL_COMPLIBDIR=$(DESTDIR)$(COMPLIBDIR)
INSTALL_FLEXDLLDIR=$(INSTALL_LIBDIR)/flexdll
.PHONY: install-flexdll
install-flexdll:
$(INSTALL_PROG) flexdll/flexlink.exe "$(INSTALL_BINDIR)/flexlink$(EXE)"
ifneq "$(filter-out mingw,$(TOOLCHAIN))" ""
$(INSTALL_DATA) flexdll/default$(filter-out _i386,_$(ARCH)).manifest \
"$(INSTALL_BINDIR)/"
endif
if test -n "$(wildcard flexdll/flexdll_*.$(O))" ; then \
$(MKDIR) "$(INSTALL_FLEXDLLDIR)" ; \
$(INSTALL_DATA) flexdll/flexdll_*.$(O) "$(INSTALL_FLEXDLLDIR)" ; \
fi
# Installation
.PHONY: install
install:
$(MKDIR) "$(INSTALL_BINDIR)"
$(MKDIR) "$(INSTALL_LIBDIR)"
$(MKDIR) "$(INSTALL_STUBLIBDIR)"
$(MKDIR) "$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
VERSION \
"$(INSTALL_LIBDIR)"
$(MAKE) -C runtime install
$(INSTALL_PROG) ocaml "$(INSTALL_BINDIR)/ocaml$(EXE)"
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(INSTALL_PROG) ocamlc "$(INSTALL_BINDIR)/ocamlc.byte$(EXE)"
endif
$(MAKE) -C stdlib install
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(INSTALL_PROG) lex/ocamllex "$(INSTALL_BINDIR)/ocamllex.byte$(EXE)"
endif
$(INSTALL_PROG) yacc/ocamlyacc$(EXE) "$(INSTALL_BINDIR)/ocamlyacc$(EXE)"
$(INSTALL_DATA) \
utils/*.cmi \
parsing/*.cmi \
typing/*.cmi \
bytecomp/*.cmi \
file_formats/*.cmi \
lambda/*.cmi \
driver/*.cmi \
toplevel/*.cmi \
"$(INSTALL_COMPLIBDIR)"
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
$(INSTALL_DATA) \
utils/*.cmt utils/*.cmti utils/*.mli \
parsing/*.cmt parsing/*.cmti parsing/*.mli \
typing/*.cmt typing/*.cmti typing/*.mli \
file_formats/*.cmt file_formats/*.cmti file_formats/*.mli \
lambda/*.cmt lambda/*.cmti lambda/*.mli \
bytecomp/*.cmt bytecomp/*.cmti bytecomp/*.mli \
driver/*.cmt driver/*.cmti driver/*.mli \
toplevel/*.cmt toplevel/*.cmti toplevel/*.mli \
"$(INSTALL_COMPLIBDIR)"
endif
$(INSTALL_DATA) \
compilerlibs/*.cma \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
$(BYTESTART) $(TOPLEVELSTART) \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_PROG) expunge "$(INSTALL_LIBDIR)/expunge$(EXE)"
$(INSTALL_DATA) \
toplevel/topdirs.cmi \
"$(INSTALL_LIBDIR)"
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
$(INSTALL_DATA) \
toplevel/topdirs.cmt toplevel/topdirs.cmti \
toplevel/topdirs.mli \
"$(INSTALL_LIBDIR)"
endif
$(MAKE) -C tools install
ifeq "$(UNIX_OR_WIN32)" "unix" # Install manual pages only on Unix
$(MKDIR) "$(INSTALL_MANDIR)/man$(PROGRAMS_MAN_SECTION)"
-$(MAKE) -C man install
endif
for i in $(OTHERLIBRARIES); do \
$(MAKE) -C otherlibs/$$i install || exit $$?; \
done
# Transitional: findlib 1.7.3 is confused if leftover num.cm? files remain
# from an previous installation of OCaml before otherlibs/num was removed.
rm -f "$(INSTALL_LIBDIR)"/num.cm?
# End transitional
ifneq "$(WITH_OCAMLDOC)" ""
$(MAKE) -C ocamldoc install
endif
if test -n "$(WITH_DEBUGGER)"; then \
$(MAKE) -C debugger install; \
fi
ifeq "$(UNIX_OR_WIN32)" "win32"
if test -n "$(FLEXDLL_SUBMODULE_PRESENT)"; then \
$(MAKE) install-flexdll; \
fi
endif
$(INSTALL_DATA) Makefile.config "$(INSTALL_LIBDIR)/Makefile.config"
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
if test -f ocamlopt; then $(MAKE) installopt; else \
cd "$(INSTALL_BINDIR)"; \
$(LN) ocamlc.byte$(EXE) ocamlc$(EXE); \
$(LN) ocamllex.byte$(EXE) ocamllex$(EXE); \
fi
else
if test -f ocamlopt; then $(MAKE) installopt; fi
endif
# Installation of the native-code compiler
.PHONY: installopt
installopt:
$(MAKE) -C runtime installopt
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
$(INSTALL_PROG) ocamlopt "$(INSTALL_BINDIR)/ocamlopt.byte$(EXE)"
endif
$(MAKE) -C stdlib installopt
$(INSTALL_DATA) \
middle_end/*.cmi \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
middle_end/closure/*.cmi \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
middle_end/flambda/*.cmi \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
middle_end/flambda/base_types/*.cmi \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
asmcomp/*.cmi \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
asmcomp/debug/*.cmi \
"$(INSTALL_COMPLIBDIR)"
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
$(INSTALL_DATA) \
middle_end/*.cmt middle_end/*.cmti \
middle_end/*.mli \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
middle_end/closure/*.cmt middle_end/closure/*.cmti \
middle_end/closure/*.mli \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
middle_end/flambda/*.cmt middle_end/flambda/*.cmti \
middle_end/flambda/*.mli \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
middle_end/flambda/base_types/*.cmt \
middle_end/flambda/base_types/*.cmti \
middle_end/flambda/base_types/*.mli \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
asmcomp/*.cmt asmcomp/*.cmti \
asmcomp/*.mli \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
asmcomp/debug/*.cmt asmcomp/debug/*.cmti \
asmcomp/debug/*.mli \
"$(INSTALL_COMPLIBDIR)"
endif
$(INSTALL_DATA) \
$(OPTSTART) \
"$(INSTALL_COMPLIBDIR)"
ifneq "$(WITH_OCAMLDOC)" ""
$(MAKE) -C ocamldoc installopt
endif
for i in $(OTHERLIBRARIES); do \
$(MAKE) -C otherlibs/$$i installopt || exit $$?; \
done
ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true"
if test -f ocamlopt.opt ; then $(MAKE) installoptopt; else \
cd "$(INSTALL_BINDIR)"; \
$(LN) ocamlc.byte$(EXE) ocamlc$(EXE); \
$(LN) ocamlopt.byte$(EXE) ocamlopt$(EXE); \
$(LN) ocamllex.byte$(EXE) ocamllex$(EXE); \
fi
else
if test -f ocamlopt.opt ; then $(MAKE) installoptopt; fi
endif
$(MAKE) -C tools installopt
if test -f ocamlopt.opt -a -f flexdll/flexlink.opt ; then \
$(INSTALL_PROG) \
flexdll/flexlink.opt "$(INSTALL_BINDIR)/flexlink$(EXE)" ; \
fi
.PHONY: installoptopt
installoptopt:
$(INSTALL_PROG) ocamlc.opt "$(INSTALL_BINDIR)/ocamlc.opt$(EXE)"
$(INSTALL_PROG) ocamlopt.opt "$(INSTALL_BINDIR)/ocamlopt.opt$(EXE)"
$(INSTALL_PROG) \
lex/ocamllex.opt "$(INSTALL_BINDIR)/ocamllex.opt$(EXE)"
cd "$(INSTALL_BINDIR)"; \
$(LN) ocamlc.opt$(EXE) ocamlc$(EXE); \
$(LN) ocamlopt.opt$(EXE) ocamlopt$(EXE); \
$(LN) ocamllex.opt$(EXE) ocamllex$(EXE)
$(INSTALL_DATA) \
utils/*.cmx parsing/*.cmx typing/*.cmx bytecomp/*.cmx \
file_formats/*.cmx \
lambda/*.cmx \
driver/*.cmx asmcomp/*.cmx middle_end/*.cmx \
middle_end/closure/*.cmx \
middle_end/flambda/*.cmx \
middle_end/flambda/base_types/*.cmx \
asmcomp/debug/*.cmx \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
compilerlibs/*.cmxa compilerlibs/*.$(A) \
"$(INSTALL_COMPLIBDIR)"
$(INSTALL_DATA) \
$(BYTESTART:.cmo=.cmx) $(BYTESTART:.cmo=.$(O)) \
$(OPTSTART:.cmo=.cmx) $(OPTSTART:.cmo=.$(O)) \
"$(INSTALL_COMPLIBDIR)"
if test -f ocamlnat$(EXE) ; then \
$(INSTALL_PROG) \
ocamlnat$(EXE) "$(INSTALL_BINDIR)/ocamlnat$(EXE)"; \
$(INSTALL_DATA) \
toplevel/opttopdirs.cmi \
"$(INSTALL_LIBDIR)"; \
$(INSTALL_DATA) \
$(OPTTOPLEVELSTART:.cmo=.cmx) $(OPTTOPLEVELSTART:.cmo=.$(O)) \
"$(INSTALL_COMPLIBDIR)"; \
fi
cd "$(INSTALL_COMPLIBDIR)" && \
$(RANLIB) ocamlcommon.$(A) ocamlbytecomp.$(A) ocamloptcomp.$(A)
# Installation of the *.ml sources of compiler-libs
.PHONY: install-compiler-sources
install-compiler-sources:
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
$(INSTALL_DATA) \
utils/*.ml parsing/*.ml typing/*.ml bytecomp/*.ml driver/*.ml \
file_formats/*.ml \
lambda/*.ml \
toplevel/*.ml middle_end/*.ml middle_end/closure/*.ml \
middle_end/flambda/*.ml middle_end/flambda/base_types/*.ml \
asmcomp/*.ml \
asmcmp/debug/*.ml \
"$(INSTALL_COMPLIBDIR)"
endif
# 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
# The clean target
clean:: partialclean
# The bytecode compiler
ocamlc: compilerlibs/ocamlcommon.cma compilerlibs/ocamlbytecomp.cma $(BYTESTART)
$(CAMLC) $(LINKFLAGS) -compat-32 -o $@ $^
partialclean::
rm -rf ocamlc
# The native-code compiler
ocamlopt: compilerlibs/ocamlcommon.cma compilerlibs/ocamloptcomp.cma \
$(OPTSTART)
$(CAMLC) $(LINKFLAGS) -o $@ $^
partialclean::
rm -f ocamlopt
# The toplevel
ocaml_dependencies := \
compilerlibs/ocamlcommon.cma \
compilerlibs/ocamlbytecomp.cma \
compilerlibs/ocamltoplevel.cma $(TOPLEVELSTART)
.INTERMEDIATE: ocaml.tmp
ocaml.tmp: $(ocaml_dependencies)
$(CAMLC) $(LINKFLAGS) -linkall -o $@ $^
ocaml: expunge ocaml.tmp
- $(CAMLRUN) $^ $@ $(PERVASIVES)
partialclean::
rm -f ocaml
.PHONY: runtop
runtop:
$(MAKE) coldstart
$(MAKE) ocamlc
$(MAKE) otherlibraries
$(MAKE) ocaml
@rlwrap --help 2>/dev/null && $(EXTRAPATH) rlwrap $(RUNTOP) ||\
$(EXTRAPATH) $(RUNTOP)
.PHONY: natruntop
natruntop:
$(MAKE) core
$(MAKE) opt
$(MAKE) ocamlnat
@rlwrap --help 2>/dev/null && $(EXTRAPATH) rlwrap $(NATRUNTOP) ||\
$(EXTRAPATH) $(NATRUNTOP)
# Native dynlink
otherlibs/dynlink/dynlink.cmxa: otherlibs/dynlink/native/dynlink.ml
$(MAKE) -C otherlibs/dynlink allopt
# The lexer
parsing/lexer.ml: parsing/lexer.mll
$(CAMLLEX) $(OCAMLLEX_FLAGS) $<
partialclean::
rm -f parsing/lexer.ml
beforedepend:: parsing/lexer.ml
# The bytecode compiler compiled with the native-code compiler
ocamlc.opt: compilerlibs/ocamlcommon.cmxa compilerlibs/ocamlbytecomp.cmxa \
$(BYTESTART:.cmo=.cmx)
$(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^ -cclib "$(BYTECCLIBS)"
partialclean::
rm -f ocamlc.opt
# The native-code compiler compiled with itself
ocamlopt.opt: compilerlibs/ocamlcommon.cmxa compilerlibs/ocamloptcomp.cmxa \
$(OPTSTART:.cmo=.cmx)
$(CAMLOPT_CMD) $(LINKFLAGS) -o $@ $^
partialclean::
rm -f ocamlopt.opt
# The predefined exceptions and primitives
runtime/primitives:
$(MAKE) -C runtime 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
asmcomp/emit.ml: asmcomp/$(ARCH)/emit.mlp tools/cvt_emit
echo \# 1 \"$(ARCH)/emit.mlp\" > $@
$(CAMLRUN) tools/cvt_emit < $< >> $@ \
|| { rm -f $@; exit 2; }
partialclean::
rm -f asmcomp/emit.ml
beforedepend:: asmcomp/emit.ml
tools/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 for the bytecode compiler
.PHONY: runtime
runtime: stdlib/libcamlrun.$(A)
.PHONY: makeruntime
makeruntime:
$(MAKE) -C runtime $(BOOT_FLEXLINK_CMD) all
runtime/libcamlrun.$(A): makeruntime ;
stdlib/libcamlrun.$(A): runtime/libcamlrun.$(A)
cd stdlib; $(LN) ../runtime/libcamlrun.$(A) .
clean::
$(MAKE) -C runtime clean
rm -f stdlib/libcamlrun.a stdlib/libcamlrun.lib
otherlibs_all := bigarray dynlink raw_spacetime_lib \
str systhreads unix win32unix
subdirs := debugger lex ocamldoc ocamltest stdlib tools \
$(addprefix otherlibs/, $(otherlibs_all)) \
.PHONY: alldepend
alldepend: depend
for dir in $(subdirs); do \
$(MAKE) -C $$dir depend || exit; \
done
# The runtime system for the native-code compiler
.PHONY: runtimeopt
runtimeopt: stdlib/libasmrun.$(A)
.PHONY: makeruntimeopt
makeruntimeopt:
$(MAKE) -C runtime $(BOOT_FLEXLINK_CMD) allopt
runtime/libasmrun.$(A): makeruntimeopt ;
stdlib/libasmrun.$(A): runtime/libasmrun.$(A)
cp $< $@
clean::
rm -f stdlib/libasmrun.a stdlib/libasmrun.lib
# The standard library
.PHONY: library
library: ocamlc
$(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) all
.PHONY: library-cross
library-cross:
$(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) CAMLRUN=../runtime/ocamlrun all
.PHONY: libraryopt
libraryopt:
$(MAKE) -C stdlib $(BOOT_FLEXLINK_CMD) allopt
partialclean::
$(MAKE) -C stdlib clean
# The lexer and parser generators
.PHONY: ocamllex
ocamllex: ocamlyacc
$(MAKE) -C lex all
.PHONY: ocamllex.opt
ocamllex.opt: ocamlopt
$(MAKE) -C lex allopt
partialclean::
$(MAKE) -C lex clean
.PHONY: ocamlyacc
ocamlyacc:
$(MAKE) -C yacc $(BOOT_FLEXLINK_CMD) all
clean::
$(MAKE) -C yacc clean
# The Menhir-generated parser
# In order to avoid a build-time dependency on Menhir,
# we store the result of the parser generator (which
# are OCaml source files) and Menhir's runtime libraries
# (that the parser files rely on) in boot/.
# The rules below do not depend on Menhir being available,
# they just build the parser from boot/.
# See Makefile.menhir for the rules to rebuild the parser and update
# boot/, which require Menhir. The targets in Makefile.menhir
# (also included here for convenience) must be used after any
# modification of parser.mly.
include Makefile.menhir
# To avoid module-name conflicts with compiler-lib users that link
# with their code with their own MenhirLib module (possibly with
# a different Menhir version), we rename MenhirLib into
# CamlinternalMenhirlib -- and replace the module occurrences in the
# generated parser.ml.
parsing/camlinternalMenhirLib.ml: boot/menhir/menhirLib.ml
cp $< $@
parsing/camlinternalMenhirLib.mli: boot/menhir/menhirLib.mli
echo '[@@@ocaml.warning "-67"]' > $@
cat $< >> $@
# Copy parsing/parser.ml from boot/
parsing/parser.ml: boot/menhir/parser.ml parsing/parser.mly \
tools/check-parser-uptodate-or-warn.sh
@-tools/check-parser-uptodate-or-warn.sh
sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@
parsing/parser.mli: boot/menhir/parser.mli
sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@
beforedepend:: parsing/camlinternalMenhirLib.ml \
parsing/camlinternalMenhirLib.mli \
parsing/parser.ml parsing/parser.mli
partialclean:: partialclean-menhir
# OCamldoc
.PHONY: ocamldoc
ocamldoc: ocamlc ocamlyacc ocamllex otherlibraries
$(MAKE) -C ocamldoc all
.PHONY: ocamldoc.opt
ocamldoc.opt: ocamlc.opt ocamlyacc ocamllex
$(MAKE) -C ocamldoc opt.opt
# OCamltest
ocamltest: ocamlc ocamlyacc ocamllex
$(MAKE) -C ocamltest all
ocamltest.opt: ocamlc.opt ocamlyacc ocamllex
$(MAKE) -C ocamltest allopt
partialclean::
$(MAKE) -C ocamltest clean
# Documentation
.PHONY: html_doc
html_doc: ocamldoc
$(MAKE) -C ocamldoc $@
@echo "documentation is in ./ocamldoc/stdlib_html/"
.PHONY: manpages
manpages:
$(MAKE) -C ocamldoc $@
partialclean::
$(MAKE) -C ocamldoc clean
# The extra libraries
.PHONY: otherlibraries
otherlibraries: ocamltools
$(MAKE) -C otherlibs all
.PHONY: otherlibrariesopt
otherlibrariesopt:
$(MAKE) -C otherlibs allopt
partialclean::
$(MAKE) -C otherlibs partialclean
clean::
$(MAKE) -C otherlibs clean
# The replay debugger
.PHONY: ocamldebugger
ocamldebugger: ocamlc ocamlyacc ocamllex otherlibraries
$(MAKE) -C debugger all
partialclean::
$(MAKE) -C debugger clean
# Check that the native-code compiler is supported
.PHONY: checknative
checknative:
ifeq "$(ARCH)" "none"
checknative:
$(error The native-code compiler is not supported on this platform)
else
@
endif
# Check that the stack limit is reasonable (Unix-only)
.PHONY: checkstack
checkstack:
ifeq "$(UNIX_OR_WIN32)" "unix"
if $(MKEXE) $(OUTPUTEXE)tools/checkstack$(EXE) tools/checkstack.c; \
then tools/checkstack$(EXE); \
fi
rm -f tools/checkstack$(EXE)
else
@
endif
# Lint @since and @deprecated annotations
VERSIONS=$(shell git tag|grep '^[0-9]*.[0-9]*.[0-9]*$$'|grep -v '^[12].')
.PHONY: lintapidiff
lintapidiff:
$(MAKE) -C tools lintapidiff.opt
git ls-files -- 'otherlibs/*/*.mli' 'stdlib/*.mli' |\
grep -Ev internal\|obj\|spacetime\|stdLabels\|moreLabels |\
tools/lintapidiff.opt $(VERSIONS)
# Tools
.PHONY: ocamltools
ocamltools: ocamlc ocamllex compilerlibs/ocamlmiddleend.cma
$(MAKE) -C tools all
.PHONY: ocamltoolsopt
ocamltoolsopt: ocamlopt
$(MAKE) -C tools opt
.PHONY: ocamltoolsopt.opt
ocamltoolsopt.opt: ocamlc.opt ocamllex.opt compilerlibs/ocamlmiddleend.cmxa
$(MAKE) -C tools opt.opt
partialclean::
$(MAKE) -C tools clean
## Test compilation of backend-specific parts
ARCH_SPECIFIC =\
asmcomp/arch.ml asmcomp/proc.ml asmcomp/CSE.ml asmcomp/selection.ml \
asmcomp/scheduling.ml asmcomp/reload.ml
partialclean::
rm -f $(ARCH_SPECIFIC)
beforedepend:: $(ARCH_SPECIFIC)
# This rule provides a quick way to check that machine-dependent
# files compiles fine for a foreign architecture (passed as ARCH=xxx).
.PHONY: check_arch
check_arch:
@echo "========= CHECKING asmcomp/$(ARCH) =============="
@rm -f $(ARCH_SPECIFIC) asmcomp/emit.ml asmcomp/*.cm*
@$(MAKE) compilerlibs/ocamloptcomp.cma \
>/dev/null
@rm -f $(ARCH_SPECIFIC) asmcomp/emit.ml asmcomp/*.cm*
.PHONY: check_all_arches
check_all_arches:
ifeq ($(ARCH64),true)
@STATUS=0; \
for i in $(ARCHES); do \
$(MAKE) --no-print-directory check_arch ARCH=$$i || STATUS=1; \
done; \
exit $$STATUS
else
@echo "Architecture tests are disabled on 32-bit platforms."
endif
# The native toplevel
# When the native toplevel executable has an extension (e.g. ".exe"),
# provide a phony 'ocamlnat' synonym
ifneq ($(EXE),)
.PHONY: ocamlnat
ocamlnat: ocamlnat$(EXE)
endif
ocamlnat$(EXE): compilerlibs/ocamlcommon.cmxa compilerlibs/ocamloptcomp.cmxa \
compilerlibs/ocamlbytecomp.cmxa \
otherlibs/dynlink/dynlink.cmxa \
compilerlibs/ocamlopttoplevel.cmxa \
$(OPTTOPLEVELSTART:.cmo=.cmx)