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
34 ifndef IS_CLEANING_TARGET
36 UsedLibs
= $
(shell $
(LLVM_CONFIG
) --libs $
(UsedComponents
))
37 UsedLibNames
= $
(shell $
(LLVM_CONFIG
) --libnames $
(UsedComponents
))
42 OCAMLCFLAGS
+= -I $
(ObjDir
) -I $
(OcamlDir
)
43 ifndef IS_CLEANING_TARGET
45 OCAMLAFLAGS
+= $
(patsubst
%,-cclib
%, \
46 $
(filter
-out
-L$
(LibDir
),-l$
(LIBRARYNAME
) \
47 $
(shell $
(LLVM_CONFIG
) --ldflags
)) \
50 OCAMLAFLAGS
+= $
(patsubst
%,-cclib
%, \
51 $
(filter
-out
-L$
(LibDir
),$
(shell $
(LLVM_CONFIG
) --ldflags
)) \
56 #
-g was introduced
in 3.10.0.
57 #ifneq
($
(ENABLE_OPTIMIZED
),1)
58 # OCAMLDEBUGFLAG
:= -g
61 Compile.CMI
:= $
(strip $
(OCAMLC
) -c $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
62 Compile.CMO
:= $
(strip $
(OCAMLC
) -c $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
63 Archive.CMA
:= $
(strip $
(OCAMLC
) -a
-custom $
(OCAMLAFLAGS
) $
(OCAMLDEBUGFLAG
) \
66 Compile.CMX
:= $
(strip $
(OCAMLOPT
) -c $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
67 Archive.CMXA
:= $
(strip $
(OCAMLOPT
) -a $
(OCAMLAFLAGS
) $
(OCAMLDEBUGFLAG
) -o
)
70 Archive.EXE
:= $
(strip $
(OCAMLOPT
) -cc $
(CXX
) $
(OCAMLCFLAGS
) $
(UsedOcamLibs
:%=%.cmxa
) $
(OCAMLDEBUGFLAG
) -o
)
72 Archive.EXE
:= $
(strip $
(OCAMLC
) -cc $
(CXX
) $
(OCAMLCFLAGS
) $
(OCAMLDEBUGFLAG
:%=%.cma
) -o
)
77 OcamlSources1
:= $
(sort $
(wildcard $
(PROJ_SRC_DIR
)/*.ml
))
81 OcamlHeaders1
:= $
(sort $
(wildcard $
(PROJ_SRC_DIR
)/*.mli
))
84 OcamlSources2
:= $
(filter
-out $
(ExcludeSources
),$
(OcamlSources1
))
85 OcamlHeaders2
:= $
(filter
-out $
(ExcludeHeaders
),$
(OcamlHeaders1
))
87 OcamlSources
:= $
(OcamlSources2
:$
(PROJ_SRC_DIR
)/%=$
(ObjDir
)/%)
88 OcamlHeaders
:= $
(OcamlHeaders2
:$
(PROJ_SRC_DIR
)/%=$
(ObjDir
)/%)
91 ObjectsCMI
:= $
(OcamlSources
:%.ml
=%.cmi
)
92 ObjectsCMO
:= $
(OcamlSources
:%.ml
=%.cmo
)
93 ObjectsCMX
:= $
(OcamlSources
:%.ml
=%.cmx
)
96 LibraryCMA
:= $
(ObjDir
)/$
(LIBRARYNAME
).cma
97 LibraryCMXA
:= $
(ObjDir
)/$
(LIBRARYNAME
).cmxa
101 ToolEXE
:= $
(ObjDir
)/$
(TOOLNAME
)$
(EXEEXT
)
105 # The
.cmo files are the only intermediates
; all others are
to be installed
.
106 OutputsCMI
:= $
(ObjectsCMI
:$
(ObjDir
)/%.cmi
=$
(OcamlDir
)/%.cmi
)
107 OutputsCMX
:= $
(ObjectsCMX
:$
(ObjDir
)/%.cmx
=$
(OcamlDir
)/%.cmx
)
108 OutputLibs
:= $
(UsedLibNames
:%=$
(OcamlDir
)/%)
111 LibraryA
:= $
(OcamlDir
)/lib$
(LIBRARYNAME
).a
112 OutputCMA
:= $
(LibraryCMA
:$
(ObjDir
)/%.cma
=$
(OcamlDir
)/%.cma
)
113 OutputCMXA
:= $
(LibraryCMXA
:$
(ObjDir
)/%.cmxa
=$
(OcamlDir
)/%.cmxa
)
118 OutputEXE
:= $
(ExmplDir
)/$
(strip $
(TOOLNAME
))$
(EXEEXT
)
120 OutputEXE
:= $
(ToolDir
)/$
(strip $
(TOOLNAME
))$
(EXEEXT
)
124 # Installation targets
125 DestLibs
:= $
(UsedLibNames
:%=$
(PROJ_libocamldir
)/%)
128 DestA
:= $
(PROJ_libocamldir
)/lib$
(LIBRARYNAME
).a
129 DestCMA
:= $
(PROJ_libocamldir
)/$
(LIBRARYNAME
).cma
130 DestCMXA
:= $
(PROJ_libocamldir
)/$
(LIBRARYNAME
).cmxa
133 ##
===- Dependencies
-------------------------------------------------------===##
134 # Copy the sources into the intermediate directory because older ocamlc doesn't
135 # support
-o except
when linking
(outputs are placed next
to inputs
).
137 $
(ObjDir
)/%.mli
: $
(PROJ_SRC_DIR
)/%.mli $
(ObjDir
)/.dir
138 $
(Verb
) $
(CP
) -f $
< $
@
140 $
(ObjDir
)/%.ml
: $
(PROJ_SRC_DIR
)/%.ml $
(ObjDir
)/.dir
141 $
(Verb
) $
(CP
) -f $
< $
@
143 $
(ObjectsCMI
): $
(UsedOcamlInterfaces
:%=$
(OcamlDir
)/%.cmi
)
146 $
(ObjDir
)/$
(LIBRARYNAME
).ocamldep
: $
(OcamlSources
) $
(OcamlHeaders
) \
147 $
(OcamlDir
)/.dir $
(ObjDir
)/.dir
148 $
(Verb
) $
(OCAMLDEP
) $
(OCAMLCFLAGS
) $
(OcamlSources
) $
(OcamlHeaders
) > $
@
150 -include $
(ObjDir
)/$
(LIBRARYNAME
).ocamldep
154 $
(ObjDir
)/$
(TOOLNAME
).ocamldep
: $
(OcamlSources
) $
(OcamlHeaders
) \
155 $
(OcamlDir
)/.dir $
(ObjDir
)/.dir
156 $
(Verb
) $
(OCAMLDEP
) $
(OCAMLCFLAGS
) $
(OcamlSources
) $
(OcamlHeaders
) > $
@
158 -include $
(ObjDir
)/$
(TOOLNAME
).ocamldep
161 ##
===- Build static library from C sources
--------------------------------===##
164 all
-local
:: $
(LibraryA
)
165 clean
-local
:: clean
-a
166 install
-local
:: install
-a
167 uninstall
-local
:: uninstall
-a
169 $
(LibraryA
): $
(ObjectsO
) $
(OcamlDir
)/.dir
170 $
(Echo
) "Building $(BuildMode) $(notdir $@)"
172 $
(Verb
) $
(Archive
) $
@ $
(ObjectsO
)
176 -$
(Verb
) $
(RM
) -f $
(LibraryA
)
178 install
-a
:: $
(LibraryA
)
179 $
(Echo
) "Installing $(BuildMode) $(DestA)"
180 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
181 $
(Verb
) $
(INSTALL
) $
(LibraryA
) $
(DestA
)
185 $
(Echo
) "Uninstalling $(DestA)"
186 -$
(Verb
) $
(RM
) -f $
(DestA
)
190 ##
===- Deposit dependent libraries adjacent
to Ocaml libs
-----------------===##
192 all
-local
:: build
-deplibs
193 clean
-local
:: clean
-deplibs
194 install
-local
:: install
-deplibs
195 uninstall
-local
:: uninstall
-deplibs
197 build
-deplibs
: $
(OutputLibs
)
199 $
(OcamlDir
)/%.a
: $
(LibDir
)/%.a
202 $
(OcamlDir
)/%.o
: $
(LibDir
)/%.o
206 $
(Verb
) $
(RM
) -f $
(OutputLibs
)
209 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
210 $
(Verb
) for i
in $
(DestLibs
:$
(PROJ_libocamldir
)/%=%); do \
211 ln
-sf
"$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
215 $
(Verb
) $
(RM
) -f $
(DestLibs
)
218 ##
===- Build ocaml interfaces
(.mli's
-> .cmi's
) --------------------------===##
220 ifneq
($
(OcamlHeaders
),)
221 all
-local
:: build
-cmis
222 clean
-local
:: clean
-cmis
223 install
-local
:: install
-cmis
224 uninstall
-local
:: uninstall
-cmis
226 build
-cmis
: $
(OutputsCMI
)
228 $
(OcamlDir
)/%.cmi
: $
(ObjDir
)/%.cmi $
(OcamlDir
)/.dir
229 $
(Verb
) $
(CP
) -f $
< $
@
231 $
(ObjDir
)/%.cmi
: $
(ObjDir
)/%.mli $
(ObjDir
)/.dir
232 $
(Echo
) "Compiling $(notdir $<) for $(BuildMode) build"
233 $
(Verb
) $
(Compile.CMI
) $
@ $
<
236 -$
(Verb
) $
(RM
) -f $
(OutputsCMI
)
238 # Also install the
.mli's
(headers
) as documentation
.
239 install
-cmis
: $
(OutputsCMI
) $
(OcamlHeaders
)
240 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
241 $
(Verb
) for i
in $
(OutputsCMI
:$
(OcamlDir
)/%=%); do \
242 $
(EchoCmd
) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
243 $
(DataInstall
) $
(OcamlDir
)/$$i
"$(PROJ_libocamldir)/$$i"; \
245 $
(Verb
) for i
in $
(OcamlHeaders
:$
(ObjDir
)/%=%); do \
246 $
(EchoCmd
) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
247 $
(DataInstall
) $
(ObjDir
)/$$i
"$(PROJ_libocamldir)/$$i"; \
251 $
(Verb
) for i
in $
(OutputsCMI
:$
(OcamlDir
)/%=%); do \
252 $
(EchoCmd
) "Uninstalling $(PROJ_libocamldir)/$$i"; \
253 $
(RM
) -f
"$(PROJ_libocamldir)/$$i"; \
255 $
(Verb
) for i
in $
(OcamlHeaders
:$
(ObjDir
)/%=%); do \
256 $
(EchoCmd
) "Uninstalling $(PROJ_libocamldir)/$$i"; \
257 $
(RM
) -f
"$(PROJ_libocamldir)/$$i"; \
262 ##
===- Build ocaml bytecode archive
(.ml's
-> .cmo's
-> .cma
) -------------===##
264 $
(ObjDir
)/%.cmo
: $
(ObjDir
)/%.ml
265 $
(Echo
) "Compiling $(notdir $<) for $(BuildMode) build"
266 $
(Verb
) $
(Compile.CMO
) $
@ $
<
269 all
-local
:: $
(OutputCMA
)
270 clean
-local
:: clean
-cma
271 install
-local
:: install
-cma
272 uninstall
-local
:: uninstall
-cma
274 $
(OutputCMA
): $
(LibraryCMA
) $
(OcamlDir
)/.dir
275 $
(Verb
) $
(CP
) -f $
< $
@
277 $
(LibraryCMA
): $
(ObjectsCMO
) $
(OcamlDir
)/.dir
278 $
(Echo
) "Archiving $(notdir $@) for $(BuildMode) build"
279 $
(Verb
) $
(Archive.CMA
) $
@ $
(ObjectsCMO
)
282 $
(Verb
) $
(RM
) -f $
(OutputCMA
) $
(UsedLibNames
:%=$
(OcamlDir
)/%)
284 install
-cma
:: $
(OutputCMA
)
285 $
(Echo
) "Installing $(BuildMode) $(DestCMA)"
286 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
287 $
(Verb
) $
(DataInstall
) $
(OutputCMA
) "$(DestCMA)"
290 $
(Echo
) "Uninstalling $(DestCMA)"
291 -$
(Verb
) $
(RM
) -f $
(DestCMA
)
294 ##
===- Build optimized ocaml archive
(.ml's
-> .cmx's
-> .cmxa
, .a
) -------===##
296 # The ocamlopt compiler is supported on a set
of targets disjoint from LLVM's
.
297 # If unavailable
, 'configure' will not define OCAMLOPT
in Makefile.config
.
300 $
(OcamlDir
)/%.cmx
: $
(ObjDir
)/%.cmx
301 $
(Verb
) $
(CP
) -f $
< $
@
303 $
(ObjDir
)/%.cmx
: $
(ObjDir
)/%.ml
304 $
(Echo
) "Compiling optimized $(notdir $<) for $(BuildMode) build"
305 $
(Verb
) $
(Compile.CMX
) $
@ $
<
308 all
-local
:: $
(OutputCMXA
) $
(OutputsCMX
)
309 clean
-local
:: clean
-cmxa
310 install
-local
:: install
-cmxa
311 uninstall
-local
:: uninstall
-cmxa
313 $
(OutputCMXA
): $
(LibraryCMXA
)
314 $
(Verb
) $
(CP
) -f $
< $
@
315 $
(Verb
) $
(CP
) -f $
(<:.cmxa
=.a
) $
(@:.cmxa
=.a
)
317 $
(LibraryCMXA
): $
(ObjectsCMX
)
318 $
(Echo
) "Archiving $(notdir $@) for $(BuildMode) build"
319 $
(Verb
) $
(Archive.CMXA
) $
@ $
(ObjectsCMX
)
320 $
(Verb
) $
(RM
) -f $
(@:.cmxa
=.o
)
323 $
(Verb
) $
(RM
) -f $
(OutputCMXA
) $
(OutputCMXA
:.cmxa
=.a
) $
(OutputsCMX
)
325 install
-cmxa
:: $
(OutputCMXA
) $
(OutputsCMX
)
326 $
(Verb
) $
(MKDIR
) $
(PROJ_libocamldir
)
327 $
(Echo
) "Installing $(BuildMode) $(DestCMXA)"
328 $
(Verb
) $
(DataInstall
) $
(OutputCMXA
) $
(DestCMXA
)
329 $
(Echo
) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
330 $
(Verb
) $
(DataInstall
) $
(OutputCMXA
:.cmxa
=.a
) $
(DestCMXA
:.cmxa
=.a
)
331 $
(Verb
) for i
in $
(OutputsCMX
:$
(OcamlDir
)/%=%); do \
332 $
(EchoCmd
) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
333 $
(DataInstall
) $
(OcamlDir
)/$$i
"$(PROJ_libocamldir)/$$i"; \
337 $
(Echo
) "Uninstalling $(DestCMXA)"
338 $
(Verb
) $
(RM
) -f $
(DestCMXA
)
339 $
(Echo
) "Uninstalling $(DestCMXA:.cmxa=.a)"
340 $
(Verb
) $
(RM
) -f $
(DestCMXA
:.cmxa
=.a
)
341 $
(Verb
) for i
in $
(OutputsCMX
:$
(OcamlDir
)/%=%); do \
342 $
(EchoCmd
) "Uninstalling $(PROJ_libocamldir)/$$i"; \
343 $
(RM
) -f $
(PROJ_libocamldir
)/$$i
; \
348 ##
===- Build executables
--------------------------------------------------===##
351 all
-local
:: $
(OutputEXE
)
352 clean
-local
:: clean
-exe
354 $
(OutputEXE
): $
(ToolEXE
) $
(OcamlDir
)/.dir
355 $
(Verb
) $
(CP
) -f $
< $
@
358 $
(ToolEXE
): $
(ObjectsCMO
) $
(OcamlDir
)/.dir
359 $
(Echo
) "Archiving $(notdir $@) for $(BuildMode) build"
360 $
(Verb
) $
(Archive.EXE
) $
@ $
(ObjectsCMO
)
362 $
(ToolEXE
): $
(ObjectsCMX
) $
(OcamlDir
)/.dir
363 $
(Echo
) "Archiving $(notdir $@) for $(BuildMode) build"
364 $
(Verb
) $
(Archive.EXE
) $
@ $
(ObjectsCMX
)
368 ##
===- Generate documentation
---------------------------------------------===##
370 $
(ObjDir
)/$
(LIBRARYNAME
).odoc
: $
(ObjectsCMI
)
371 $
(Echo
) "Documenting $(notdir $@)"
372 $
(Verb
) $
(OCAMLDOC
) -I $
(ObjDir
) -I $
(OcamlDir
) -dump $
@ $
(OcamlHeaders
)
374 ocamldoc
: $
(ObjDir
)/$
(LIBRARYNAME
).odoc
376 ##
===- Debugging gunk
-----------------------------------------------------===##
377 printvars
:: printcamlvars
380 $
(Echo
) "LLVM_CONFIG : " '$
(LLVM_CONFIG
)'
381 $
(Echo
) "OCAMLCFLAGS : " '$
(OCAMLCFLAGS
)'
382 $
(Echo
) "OCAMLAFLAGS : " '$
(OCAMLAFLAGS
)'
383 $
(Echo
) "OCAMLC : " '$
(OCAMLC
)'
384 $
(Echo
) "OCAMLOPT : " '$
(OCAMLOPT
)'
385 $
(Echo
) "OCAMLDEP : " '$
(OCAMLDEP
)'
386 $
(Echo
) "Compile.CMI : " '$
(Compile.CMI
)'
387 $
(Echo
) "Compile.CMO : " '$
(Compile.CMO
)'
388 $
(Echo
) "Archive.CMA : " '$
(Archive.CMA
)'
389 $
(Echo
) "Compile.CMX : " '$
(Compile.CMX
)'
390 $
(Echo
) "Archive.CMXA : " '$
(Archive.CMXA
)'
391 $
(Echo
) "CAML_LIBDIR : " '$
(CAML_LIBDIR
)'
392 $
(Echo
) "LibraryCMA : " '$
(LibraryCMA
)'
393 $
(Echo
) "LibraryCMXA : " '$
(LibraryCMXA
)'
394 $
(Echo
) "OcamlSources1: " '$
(OcamlSources1
)'
395 $
(Echo
) "OcamlSources2: " '$
(OcamlSources2
)'
396 $
(Echo
) "OcamlSources : " '$
(OcamlSources
)'
397 $
(Echo
) "OcamlHeaders1: " '$
(OcamlHeaders1
)'
398 $
(Echo
) "OcamlHeaders2: " '$
(OcamlHeaders2
)'
399 $
(Echo
) "OcamlHeaders : " '$
(OcamlHeaders
)'
400 $
(Echo
) "ObjectsCMI : " '$
(ObjectsCMI
)'
401 $
(Echo
) "ObjectsCMO : " '$
(ObjectsCMO
)'
402 $
(Echo
) "ObjectsCMX : " '$
(ObjectsCMX
)'
403 $
(Echo
) "OCAML_LIBDIR : " '$
(OCAML_LIBDIR
)'
404 $
(Echo
) "DestA : " '$
(DestA
)'
405 $
(Echo
) "DestCMA : " '$
(DestCMA
)'
406 $
(Echo
) "DestCMXA : " '$
(DestCMXA
)'
407 $
(Echo
) "UsedLibs : " '$
(UsedLibs
)'
408 $
(Echo
) "UsedLibNames : " '$
(UsedLibNames
)'
410 .PHONY
: printcamlvars build
-cmis \
411 clean
-a clean
-cmis clean
-cma clean
-cmxa \
412 install
-a install
-cmis install
-cma install
-cmxa \
414 uninstall
-a uninstall
-cmis uninstall
-cma uninstall
-cmxa \