forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
296 lines (238 loc) · 10.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
#**************************************************************************
#* *
#* OCaml *
#* *
#* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
#* Mark Shinwell, Jane Street Europe *
#* *
#* Copyright 1999 Institut National de Recherche en Informatique et *
#* en Automatique. *
#* Copyright 2018--2019 Jane Street Group LLC *
#* *
#* 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. *
#* *
#**************************************************************************
# Makefile for the dynamic link library
# FIXME reduce redundancy by including ../Makefile
ROOTDIR = ../..
include $(ROOTDIR)/Makefile.common
include $(ROOTDIR)/Makefile.best_binaries
CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun$(EXE)
OCAMLC=$(BEST_OCAMLC) -g -nostdlib -I $(ROOTDIR)/stdlib
OCAMLOPT=$(BEST_OCAMLOPT) -g -nostdlib -I $(ROOTDIR)/stdlib
# COMPFLAGS should be in sync with the toplevel Makefile's COMPFLAGS.
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
COMPFLAGS += -I byte
OPTCOMPFLAGS += -I native
LOCAL_SRC=dynlink_compilerlibs
OBJS=byte/dynlink_compilerlibs.cmo dynlink_types.cmo \
dynlink_platform_intf.cmo dynlink_common.cmo byte/dynlink.cmo
NATOBJS=native/dynlink_compilerlibs.cmx dynlink_types.cmx \
dynlink_platform_intf.cmx dynlink_common.cmx native/dynlink.cmx
# We need/desire access to compilerlibs for various reasons:
# - The bytecode dynamic linker is in compilerlibs and has many dependencies
# from there.
# - It stops duplication of code (e.g. magic numbers from [Config]).
# - It allows future improvement by re-using various types.
# We have to pack our own version of compilerlibs (even if compilerlibs
# becomes packed in the future by default) otherwise problems will be caused
# if a user tries to link dynlink.cm{x,}a with code either having modules
# of the same names or code that is already linked against compilerlibs.
#
# The modules needed from compilerlibs have to be recompiled so that the
# -for-pack option can be specified. Packing without such option having been
# specified, as used to be performed in this Makefile, is currently permitted
# for bytecode (but may be disallowed in the future) but not native.
# .mli files from compilerlibs that don't have a corresponding .ml file.
COMPILERLIBS_INTFS=\
parsing/asttypes.mli \
parsing/parsetree.mli \
typing/outcometree.mli \
file_formats/cmo_format.mli \
file_formats/cmxs_format.mli
# .ml files from compilerlibs that have corresponding .mli files.
COMPILERLIBS_SOURCES=\
utils/config.ml \
utils/build_path_prefix_map.ml \
utils/misc.ml \
utils/identifiable.ml \
utils/numbers.ml \
utils/arg_helper.ml \
utils/clflags.ml \
utils/profile.ml \
utils/consistbl.ml \
utils/terminfo.ml \
utils/warnings.ml \
utils/load_path.ml \
utils/int_replace_polymorphic_compare.ml \
parsing/location.ml \
parsing/longident.ml \
parsing/docstrings.ml \
parsing/syntaxerr.ml \
parsing/ast_helper.ml \
parsing/ast_mapper.ml \
parsing/attr_helper.ml \
parsing/builtin_attributes.ml \
typing/ident.ml \
typing/path.ml \
typing/primitive.ml \
typing/type_immediacy.ml \
typing/types.ml \
typing/btype.ml \
typing/subst.ml \
typing/predef.ml \
typing/datarepr.ml \
file_formats/cmi_format.ml \
typing/persistent_env.ml \
typing/env.ml \
lambda/debuginfo.ml \
lambda/lambda.ml \
lambda/runtimedef.ml \
bytecomp/instruct.ml \
bytecomp/opcodes.ml \
bytecomp/bytesections.ml \
bytecomp/dll.ml \
bytecomp/meta.ml \
bytecomp/symtable.ml
# Rules to make a local copy of the .ml and .mli files required. We also
# provide .ml files for .mli-only modules---without this, such modules do
# not seem to be located by the type checker inside bytecode packs.
# Note: .ml-only modules are not supported by the (.mli.cmi) rule below.
$(LOCAL_SRC)/Makefile: $(LOCAL_SRC)/Makefile.copy-sources Makefile
cp -f $< $@
for ml in $(COMPILERLIBS_SOURCES); do \
echo "$(LOCAL_SRC)/$$(basename $$ml): $(ROOTDIR)/$$ml" \
>> $@; \
echo "$(LOCAL_SRC)/$$(basename $$ml)i: $(ROOTDIR)/$${ml}i" \
>> $@; \
done;
for mli in $(COMPILERLIBS_INTFS); do \
echo "$(LOCAL_SRC)/$$(basename $$mli): $(ROOTDIR)/$$mli" \
>> $@; \
echo \
"$(LOCAL_SRC)/$$(basename $$mli .mli).ml: $(ROOTDIR)/$$mli"\
>> $@; \
done
# Rules to automatically generate dependencies for the local copy of the
# compilerlibs sources.
COMPILERLIBS_SOURCES_NO_DIRS=$(notdir $(COMPILERLIBS_SOURCES))
COMPILERLIBS_INTFS_NO_DIRS=$(notdir $(COMPILERLIBS_INTFS))
COMPILERLIBS_INTFS_BASE_NAMES=$(basename $(COMPILERLIBS_INTFS_NO_DIRS))
COMPILERLIBS_INTFS_ML_NO_DIRS=$(addsuffix .ml, $(COMPILERLIBS_INTFS_BASE_NAMES))
COMPILERLIBS_COPIED_INTFS=\
$(addprefix $(LOCAL_SRC)/, $(COMPILERLIBS_INTFS_ML_NO_DIRS))
COMPILERLIBS_COPIED_SOURCES=\
$(addprefix $(LOCAL_SRC)/, $(COMPILERLIBS_SOURCES_NO_DIRS)) \
$(COMPILERLIBS_COPIED_INTFS)
COMPILERLIBS_SOURCES_INTFS=\
$(addsuffix i, $(COMPILERLIBS_SOURCES))
COMPILERLIBS_COPIED_SOURCES_INTFS=\
$(addsuffix i, $(COMPILERLIBS_COPIED_SOURCES))
# $(LOCAL_SRC)/Makefile uses the variables above in dependencies, so must be
# include'd after they've been defined.
-include $(LOCAL_SRC)/Makefile
# Rules to build the local copy of the compilerlibs sources in such a way
# that the resulting .cm{o,x} files can be packed.
COMPILERLIBS_CMO=$(COMPILERLIBS_COPIED_SOURCES:.ml=.cmo)
COMPILERLIBS_CMX=$(COMPILERLIBS_COPIED_SOURCES:.ml=.cmx)
$(LOCAL_SRC)/%.cmi: $(LOCAL_SRC)/%.mli
$(OCAMLC) -c -for-pack Dynlink_compilerlibs $(COMPFLAGS) \
-I $(LOCAL_SRC) -o $@ $(LOCAL_SRC)/$*.mli
$(LOCAL_SRC)/%.cmo: $(LOCAL_SRC)/%.ml
$(OCAMLC) -c -for-pack Dynlink_compilerlibs $(COMPFLAGS) \
-I $(LOCAL_SRC) -o $@ $(LOCAL_SRC)/$*.ml
$(LOCAL_SRC)/%.cmx: $(LOCAL_SRC)/%.ml
$(OCAMLOPT) -c -for-pack Dynlink_compilerlibs $(COMPFLAGS) \
$(OPTCOMPFLAGS) -I $(LOCAL_SRC) -o $@ $(LOCAL_SRC)/$*.ml
# Rules for building the [Dynlink_compilerlibs] bytecode and native packs
# from their components.
byte/dynlink_compilerlibs.cmo: $(COMPILERLIBS_CMO)
$(OCAMLC) $(COMPFLAGS) -pack -o $@ $(COMPILERLIBS_CMO)
byte/dynlink_compilerlibs.cmi: byte/dynlink_compilerlibs.cmo
native/dynlink_compilerlibs.cmx: $(COMPILERLIBS_CMX)
$(OCAMLOPT) $(COMPFLAGS) $(OPTCOMPFLAGS) -pack -o $@ $(COMPILERLIBS_CMX)
%/dynlink.cmi: dynlink.cmi dynlink.mli
cp $^ $*/
# Rules for building the interface of the [Dynlink_compilerlibs] packs.
# To avoid falling foul of the problem described below, the .cmo and .cmx
# files for the dynlink-specific compilerlibs packs generated here---and in
# particular the corresponding .cmi files -- are kept in separate directories.
# The main dynlink rules start here.
extract_crc := extract_crc$(EXE)
all: dynlink.cma $(extract_crc)
allopt: dynlink.cmxa
dynlink.cma: $(OBJS)
$(OCAMLC) $(COMPFLAGS) -ccopt "$(NATDYNLINKOPTS)" -a -I byte -o $@ $^
dynlink.cmxa: $(NATOBJS)
$(OCAMLOPT) $(COMPFLAGS) -ccopt "$(NATDYNLINKOPTS)" -a -I native \
-o $@ $^
# As for all other .cmxa files, ensure that the .cmx files are in the same
# directory. If this were omitted, ocamldoc in particular will fail to build
# with a -opaque warning. Note that installopt refers to $(NATOBJS) so doesn't
# require this file to exist, hence its inclusion in the recipe for dynlink.cmxa
# rather than as a dependency elsewhere.
cp native/dynlink.cmx dynlink.cmx
# Since there is no .mli for [Dynlink_platform_intf], we need to be
# careful that compilation of the .cmx file does not write the .cmi file again,
# which would cause rebuilding of ocamlopt. The easiest way to do this seems
# to be to copy the .ml file, which is a valid .mli, to the .mli.
dynlink_platform_intf.mli: dynlink_platform_intf.ml
cp $< $@
$(eval $(call PROGRAM_SYNONYM,extract_crc))
$(extract_crc): dynlink.cma byte/dynlink_compilerlibs.cmo extract_crc.cmo
$(OCAMLC) -o $@ $^
install:
$(INSTALL_DATA) \
dynlink.cmi dynlink.cma \
"$(INSTALL_LIBDIR)"
ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true"
$(INSTALL_DATA) \
dynlink.cmti dynlink.mli \
"$(INSTALL_LIBDIR)"
endif
$(INSTALL_PROG) $(extract_crc) "$(INSTALL_LIBDIR)"
installopt:
if $(NATDYNLINK); then \
$(INSTALL_DATA) \
$(NATOBJS) dynlink.cmxa dynlink.$(A) \
"$(INSTALL_LIBDIR)" && \
cd "$(INSTALL_LIBDIR)" && $(RANLIB) dynlink.$(A); \
fi
partialclean:
rm -f $(extract_crc) *.cm[ioaxt] *.cmti *.cmxa \
byte/*.cm[iot] byte/*.cmti \
native/*.cm[ixt] native/*.cmti native/*.o native/*.obj \
$(LOCAL_SRC)/*.cm[ioaxt] $(LOCAL_SRC)/*.cmti \
$(LOCAL_SRC)/*.o $(LOCAL_SRC)/*.obj
clean: partialclean
rm -f extract_crc extract_crc.exe
rm -f *.a *.lib *.o *.obj *.so *.dll dynlink_platform_intf.mli \
$(LOCAL_SRC)/*.ml $(LOCAL_SRC)/*.mli $(LOCAL_SRC)/Makefile \
$(LOCAL_SRC)/.depend byte/dynlink.mli native/dynlink.mli
.PHONY: beforedepend
beforedepend: dynlink_platform_intf.mli
.PHONY: depend
DEPEND_DUMMY_FILES=\
native/dynlink_compilerlibs.ml \
byte/dynlink_compilerlibs.mli \
byte/dynlink.mli \
native/dynlink.mli
depend: beforedepend
touch $(DEPEND_DUMMY_FILES)
$(CAMLRUN) $(ROOTDIR)/boot/ocamlc -depend -slash \
-I byte -bytecode *.mli *.ml byte/dynlink.ml > .depend
$(CAMLRUN) $(ROOTDIR)/boot/ocamlc -depend -slash \
-I native -native *.ml native/dynlink.ml >> .depend
rm -f $(DEPEND_DUMMY_FILES)
include .depend
.SUFFIXES: .ml .mli .cmi .cmo .cmx
.mli.cmi:
$(OCAMLC) -c $(COMPFLAGS) $<
.ml.cmo:
$(OCAMLC) -c $(COMPFLAGS) $<
.ml.cmx:
$(OCAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $<