1 ##
===- tools
/ml
/Makefile
-----------------------------------*- Makefile
-*-===##
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University
of Illinois Open Source
6 #
License. See
LICENSE.TXT
for details
.
8 ##
===----------------------------------------------------------------------===##
10 # An ocaml library is a unique project
type in the context
of LLVM
, so rules are
11 # here rather than
in Makefile.rules
.
13 # Reference materials on installing ocaml libraries
:
15 # https
://fedoraproject
.org
/wiki
/Packaging
/OCaml
16 # http
://pkg
-ocaml
-maint
.alioth
.debian
.org
/ocaml_packaging_policy
.txt
18 ##
===----------------------------------------------------------------------===##
20 include $
(LEVEL
)/Makefile.config
22 # CFLAGS needs
to be set before
Makefile.rules is included
.
23 CXX.Flags
+= -I
"$(shell $(OCAMLC) -where)"
24 C.Flags
+= -I
"$(shell $(OCAMLC) -where)"
26 include $
(LEVEL
)/Makefile.common
28 # Intentionally ignore PROJ_prefix here
. We want the ocaml stdlib
. However
, the
29 # user can override this
with OCAML_LIBDIR
or configure
--with-ocaml
-libdir
=.
30 PROJ_libocamldir
:= $
(DESTDIR
)$
(OCAML_LIBDIR
)
31 OcamlDir
:= $
(LibDir
)/ocaml
33 # Info from llvm
-config
and similar
35 UsedLibs
= $
(shell $
(LLVM_CONFIG
) --libs $
(UsedComponents
))
36 UsedLibNames
= $
(shell $
(LLVM_CONFIG
) --libnames $
(UsedComponents
))
40 OCAMLCFLAGS
+= -I $
(ObjDir
) -I $
(OcamlDir
)
42 OCAMLAFLAGS
+= $
(patsubst
%,-cclib
%, \
43 $
(filter
-out
-L$
(LibDir
),-l$
(LIBRARYNAME
) \
44 $
(shell $
(LLVM_CONFIG
) --ldflags
)) \
47 OCAMLAFLAGS
+= $
(patsubst
%,-cclib
%, \
48 $
(filter
-out
-L$
(LibDir
),$
(shell $
(LLVM_CONFIG
) --ldflags
)) \
52 #
-g was introduced
in 3.10.0.
53 #ifneq
($
(ENABLE_OPTIMIZED
),1)
54 # OCAMLDEBUGFLAG
:= -g
57 Compile.CMI
:= $
(strip $
(OCAMLC
) -c $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
58 Compile.CMO
:= $
(strip $
(OCAMLC
) -c $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
59 Archive.CMA
:= $
(strip $
(OCAMLC
) -a
-custom $
(OCAMLAFLAGS
) $
(OCAMLDEBUGFLAG
) \
62 Compile.CMX
:= $
(strip $
(OCAMLOPT
) -c $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
63 Archive.CMXA
:= $
(strip $
(OCAMLOPT
) -a $
(OCAMLAFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
66 OcamlSources1
:= $
(sort $
(wildcard $
(PROJ_SRC_DIR
)/*.ml
))
67 OcamlHeaders1
:= $
(OcamlSources1
:.ml
=.mli
)
69 OcamlSources
:= $
(OcamlSources1
:$
(PROJ_SRC_DIR
)/%=$
(ObjDir
)/%)
70 OcamlHeaders
:= $
(OcamlHeaders1
:$
(PROJ_SRC_DIR
)/%=$
(ObjDir
)/%)
73 LibraryCMA
:= $
(ObjDir
)/$
(LIBRARYNAME
).cma
74 LibraryCMXA
:= $
(ObjDir
)/$
(LIBRARYNAME
).cmxa
75 ObjectsCMI
:= $
(OcamlSources
:%.ml
=%.cmi
)
76 ObjectsCMO
:= $
(OcamlSources
:%.ml
=%.cmo
)
77 ObjectsCMX
:= $
(OcamlSources
:%.ml
=%.cmx
)
80 # The
.cmo files are the only intermediates
; all others are
to be installed
.
81 LibraryA
:= $
(OcamlDir
)/lib$
(LIBRARYNAME
).a
82 OutputCMA
:= $
(LibraryCMA
:$
(ObjDir
)/%.cma
=$
(OcamlDir
)/%.cma
)
83 OutputCMXA
:= $
(LibraryCMXA
:$
(ObjDir
)/%.cmxa
=$
(OcamlDir
)/%.cmxa
)
84 OutputsCMI
:= $
(ObjectsCMI
:$
(ObjDir
)/%.cmi
=$
(OcamlDir
)/%.cmi
)
85 OutputsCMX
:= $
(ObjectsCMX
:$
(ObjDir
)/%.cmx
=$
(OcamlDir
)/%.cmx
)
86 OutputLibs
:= $
(UsedLibNames
:%=$
(OcamlDir
)/%)
88 # Installation targets
89 DestA
:= $
(PROJ_libocamldir
)/lib$
(LIBRARYNAME
).a
90 DestCMA
:= $
(PROJ_libocamldir
)/$
(LIBRARYNAME
).cma
91 DestCMXA
:= $
(PROJ_libocamldir
)/$
(LIBRARYNAME
).cmxa
92 DestLibs
:= $
(UsedLibNames
:%=$
(PROJ_libocamldir
)/%)
95 ##
===- Dependencies
-------------------------------------------------------===##
96 # Copy the sources into the intermediate directory because older ocamlc doesn't
97 # support
-o except
when linking
(outputs are placed next
to inputs
).
99 $
(ObjDir
)/%.mli
: $
(PROJ_SRC_DIR
)/%.mli $
(ObjDir
)/.dir
100 $
(Verb
) $
(CP
) -f $
< $
@
102 $
(ObjDir
)/%.ml
: $
(PROJ_SRC_DIR
)/%.ml $
(ObjDir
)/.dir
103 $
(Verb
) $
(CP
) -f $
< $
@
105 $
(ObjDir
)/$
(LIBRARYNAME
).ocamldep
: $
(OcamlSources
) $
(OcamlHeaders
) \
106 $
(OcamlDir
)/.dir $
(ObjDir
)/.dir
107 $
(Verb
) $
(OCAMLDEP
) $
(OCAMLCFLAGS
) $
(OcamlSources
) $
(OcamlHeaders
) > $
@
109 $
(ObjectsCMI
): $
(UsedOcamlInterfaces
:%=$
(OcamlDir
)/%.cmi
)
111 -include $
(ObjDir
)/$
(LIBRARYNAME
).ocamldep
114 ##
===- Build static library from C sources
--------------------------------===##
117 all
-local
:: $
(LibraryA
)
118 clean
-local
:: clean
-a
119 install
-local
:: install
-a
120 uninstall
-local
:: uninstall
-a
122 $
(LibraryA
): $
(ObjectsO
) $
(OcamlDir
)/.dir
123 $
(Echo
) "Building $(BuildMode) $(notdir $@)"
125 $
(Verb
) $
(Archive
) $
@ $
(ObjectsO
)
129 -$
(Verb
) $
(RM
) -f $
(LibraryA
)
131 install
-a
:: $
(LibraryA
)
132 $
(Echo
) "Installing $(BuildMode) $(DestA)"
133 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
134 $
(Verb
) $
(INSTALL
) $
(LibraryA
) $
(DestA
)
138 $
(Echo
) "Uninstalling $(DestA)"
139 -$
(Verb
) $
(RM
) -f $
(DestA
)
143 ##
===- Deposit dependent libraries adjacent
to Ocaml libs
-----------------===##
145 all
-local
:: build
-deplibs
146 clean
-local
:: clean
-deplibs
147 install
-local
:: install
-deplibs
148 uninstall
-local
:: uninstall
-deplibs
150 build
-deplibs
: $
(OutputLibs
)
152 $
(OcamlDir
)/%.a
: $
(LibDir
)/%.a
155 $
(OcamlDir
)/%.o
: $
(LibDir
)/%.o
159 $
(Verb
) rm
-f $
(OutputLibs
)
162 $
(Verb
) for i
in $
(DestLibs
:$
(PROJ_libocamldir
)/%=%); do \
163 ln
-sf
"$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
167 $
(Verb
) rm
-f $
(DestLibs
)
170 ##
===- Build ocaml interfaces
(.mli's
-> .cmi's
) --------------------------===##
172 all
-local
:: build
-cmis
173 clean
-local
:: clean
-cmis
174 install
-local
:: install
-cmis
175 uninstall
-local
:: uninstall
-cmis
177 build
-cmis
: $
(OutputsCMI
)
179 $
(OcamlDir
)/%.cmi
: $
(ObjDir
)/%.cmi $
(OcamlDir
)/.dir
180 $
(Verb
) $
(CP
) -f $
< $
@
182 $
(ObjDir
)/%.cmi
: $
(ObjDir
)/%.mli $
(ObjDir
)/.dir
183 $
(Echo
) "Compiling $(notdir $<) for $(BuildMode) build"
184 $
(Verb
) $
(Compile.CMI
) $
@ $
<
187 -$
(Verb
) $
(RM
) -f $
(OutputsCMI
)
189 # Also install the
.mli's
(headers
) as documentation
.
190 install
-cmis
: $
(OutputsCMI
) $
(OcamlHeaders
)
191 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
192 $
(Verb
) for i
in $
(OutputsCMI
:$
(OcamlDir
)/%=%); do \
193 $
(EchoCmd
) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
194 $
(DataInstall
) $
(OcamlDir
)/$$i
"$(PROJ_libocamldir)/$$i"; \
196 $
(Verb
) for i
in $
(OcamlHeaders
:$
(ObjDir
)/%=%); do \
197 $
(EchoCmd
) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
198 $
(DataInstall
) $
(ObjDir
)/$$i
"$(PROJ_libocamldir)/$$i"; \
202 $
(Verb
) for i
in $
(OutputsCMI
:$
(OcamlDir
)/%=%); do \
203 $
(EchoCmd
) "Uninstalling $(PROJ_libocamldir)/$$i"; \
204 $
(RM
) -f
"$(PROJ_libocamldir)/$$i"; \
206 $
(Verb
) for i
in $
(OcamlHeaders
:$
(ObjDir
)/%=%); do \
207 $
(EchoCmd
) "Uninstalling $(PROJ_libocamldir)/$$i"; \
208 $
(RM
) -f
"$(PROJ_libocamldir)/$$i"; \
212 ##
===- Build ocaml bytecode archive
(.ml's
-> .cmo's
-> .cma
) -------------===##
214 all
-local
:: $
(OutputCMA
)
215 clean
-local
:: clean
-cma
216 install
-local
:: install
-cma
217 uninstall
-local
:: uninstall
-cma
219 $
(OutputCMA
): $
(LibraryCMA
) $
(OcamlDir
)/.dir
220 $
(Verb
) $
(CP
) -f $
< $
@
222 $
(LibraryCMA
): $
(ObjectsCMO
) $
(OcamlDir
)/.dir
223 $
(Echo
) "Archiving $(notdir $@) for $(BuildMode) build"
224 $
(Verb
) $
(Archive.CMA
) $
@ $
(ObjectsCMO
)
226 $
(ObjDir
)/%.cmo
: $
(ObjDir
)/%.ml
227 $
(Echo
) "Compiling $(notdir $<) for $(BuildMode) build"
228 $
(Verb
) $
(Compile.CMO
) $
@ $
<
231 $
(Verb
) $
(RM
) -f $
(OutputCMA
) $
(UsedLibNames
:%=$
(OcamlDir
)/%)
233 install
-cma
:: $
(OutputCMA
)
234 $
(Echo
) "Installing $(BuildMode) $(DestCMA)"
235 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
236 $
(Verb
) $
(DataInstall
) $
(OutputCMA
) "$(DestCMA)"
239 $
(Echo
) "Uninstalling $(DestCMA)"
240 -$
(Verb
) $
(RM
) -f $
(DestCMA
)
243 ##
===- Build optimized ocaml archive
(.ml's
-> .cmx's
-> .cmxa
, .a
) -------===##
245 # The ocamlopt compiler is supported on a set
of targets disjoint from LLVM's
.
246 # If unavailable
, 'configure' will not define OCAMLOPT
in Makefile.config
.
249 all
-local
:: $
(OutputCMXA
) $
(OutputsCMX
)
250 clean
-local
:: clean
-cmxa
251 install
-local
:: install
-cmxa
252 uninstall
-local
:: uninstall
-cmxa
254 $
(OutputCMXA
): $
(LibraryCMXA
)
255 $
(Verb
) $
(CP
) -f $
< $
@
256 $
(Verb
) $
(CP
) -f $
(<:.cmxa
=.a
) $
(@:.cmxa
=.a
)
258 $
(OcamlDir
)/%.cmx
: $
(ObjDir
)/%.cmx
259 $
(Verb
) $
(CP
) -f $
< $
@
261 $
(LibraryCMXA
): $
(ObjectsCMX
)
262 $
(Echo
) "Archiving $(notdir $@) for $(BuildMode) build"
263 $
(Verb
) $
(Archive.CMXA
) $
@ $
(ObjectsCMX
)
264 $
(Verb
) $
(RM
) -f $
(@:.cmxa
=.o
)
266 $
(ObjDir
)/%.cmx
: $
(ObjDir
)/%.ml
267 $
(Echo
) "Compiling optimized $(notdir $<) for $(BuildMode) build"
268 $
(Verb
) $
(Compile.CMX
) $
@ $
<
271 $
(Verb
) $
(RM
) -f $
(OutputCMXA
) $
(OutputCMXA
:.cmxa
=.a
) $
(OutputsCMX
)
273 install
-cmxa
:: $
(OutputCMXA
) $
(OutputsCMX
)
274 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
275 $
(Echo
) "Installing $(BuildMode) $(DestCMXA)"
276 $
(Verb
) $
(DataInstall
) $
(OutputCMXA
) $
(DestCMXA
)
277 $
(Echo
) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
278 $
(Verb
) $
(DataInstall
) $
(OutputCMXA
:.cmxa
=.a
) $
(DestCMXA
:.cmxa
=.a
)
279 $
(Verb
) for i
in $
(OutputsCMX
:$
(OcamlDir
)/%=%); do \
280 $
(EchoCmd
) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
281 $
(DataInstall
) $
(OcamlDir
)/$$i
"$(PROJ_libocamldir)/$$i"; \
285 $
(Echo
) "Uninstalling $(DestCMXA)"
286 $
(Verb
) $
(RM
) -f $
(DestCMXA
)
287 $
(Echo
) "Uninstalling $(DestCMXA:.cmxa=.a)"
288 $
(Verb
) $
(RM
) -f $
(DestCMXA
:.cmxa
=.a
)
289 $
(Verb
) for i
in $
(OutputsCMX
:$
(OcamlDir
)/%=%); do \
290 $
(EchoCmd
) "Uninstalling $(PROJ_libocamldir)/$$i"; \
291 $
(RM
) -f $
(PROJ_libocamldir
)/$$i
; \
296 ##
===- Generate documentation
---------------------------------------------===##
298 $
(ObjDir
)/$
(LIBRARYNAME
).odoc
: $
(ObjectsCMI
)
299 $
(Echo
) "Documenting $(notdir $@)"
300 $
(Verb
) $
(OCAMLDOC
) -I $
(ObjDir
) -I $
(OcamlDir
) -dump $
@ $
(OcamlHeaders
)
302 ocamldoc
: $
(ObjDir
)/$
(LIBRARYNAME
).odoc
304 ##
===- Debugging gunk
-----------------------------------------------------===##
305 printvars
:: printcamlvars
308 $
(Echo
) "LLVM_CONFIG : " '$
(LLVM_CONFIG
)'
309 $
(Echo
) "OCAMLCFLAGS : " '$
(OCAMLCFLAGS
)'
310 $
(Echo
) "OCAMLAFLAGS : " '$
(OCAMLAFLAGS
)'
311 $
(Echo
) "OCAMLC : " '$
(OCAMLC
)'
312 $
(Echo
) "OCAMLOPT : " '$
(OCAMLOPT
)'
313 $
(Echo
) "OCAMLDEP : " '$
(OCAMLDEP
)'
314 $
(Echo
) "Compile.CMI : " '$
(Compile.CMI
)'
315 $
(Echo
) "Compile.CMO : " '$
(Compile.CMO
)'
316 $
(Echo
) "Archive.CMA : " '$
(Archive.CMA
)'
317 $
(Echo
) "Compile.CMX : " '$
(Compile.CMX
)'
318 $
(Echo
) "Archive.CMXA : " '$
(Archive.CMXA
)'
319 $
(Echo
) "CAML_LIBDIR : " '$
(CAML_LIBDIR
)'
320 $
(Echo
) "LibraryCMA : " '$
(LibraryCMA
)'
321 $
(Echo
) "LibraryCMXA : " '$
(LibraryCMXA
)'
322 $
(Echo
) "OcamlSources1: " '$
(OcamlSources1
)'
323 $
(Echo
) "OcamlSources : " '$
(OcamlSources
)'
324 $
(Echo
) "OcamlHeaders : " '$
(OcamlHeaders
)'
325 $
(Echo
) "ObjectsCMI : " '$
(ObjectsCMI
)'
326 $
(Echo
) "ObjectsCMO : " '$
(ObjectsCMO
)'
327 $
(Echo
) "ObjectsCMX : " '$
(ObjectsCMX
)'
328 $
(Echo
) "OCAML_LIBDIR : " '$
(OCAML_LIBDIR
)'
329 $
(Echo
) "DestA : " '$
(DestA
)'
330 $
(Echo
) "DestCMA : " '$
(DestCMA
)'
331 $
(Echo
) "DestCMXA : " '$
(DestCMXA
)'
332 $
(Echo
) "UsedLibs : " '$
(UsedLibs
)'
333 $
(Echo
) "UsedLibNames : " '$
(UsedLibNames
)'
335 .PHONY
: printcamlvars build
-cmis \
336 clean
-a clean
-cmis clean
-cma clean
-cmxa \
337 install
-a install
-cmis install
-cma install
-cmxa \
338 uninstall
-a uninstall
-cmis uninstall
-cma uninstall
-cmxa