1 ##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===##
3 # The LLVM Compiler Infrastructure
5 # This file was developed by Gordon Henriksen and is distributed under the
6 # University of Illinois Open Source 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 ##===----------------------------------------------------------------------===##
15 include $(LEVEL)/Makefile.config
17 # CFLAGS needs to be set before Makefile.rules is included. Yes, ocaml puts its
18 # includes under its libdir.
19 CFLAGS += -I$(OCAML_LIBDIR)
21 include $(LEVEL)/Makefile.common
23 # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
24 # user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
25 PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
26 OcamlDir := $(LibDir)/ocaml
28 # Info from llvm-config and similar
30 UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
31 UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
35 OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
36 OCAMLAFLAGS += $(patsubst %,-cclib %, \
37 $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
38 $(UsedLibs) -l$(LIBRARYNAME))
40 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
41 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
42 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
44 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
45 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
48 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
49 OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
51 OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
52 OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
55 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
56 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
57 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
58 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
59 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
62 # The .cmo files are the only intermediates; all others are to be installed.
63 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
64 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
65 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
66 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
67 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
69 # Installation targets
70 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
71 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
72 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
75 ##===- Dependencies -------------------------------------------------------===##
76 # Copy the sources into the intermediate directory because older ocamlc doesn't
77 # support -o except when linking (outputs are placed next to inputs).
79 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
80 $(Verb) $(CP) -f $< $@
82 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
83 $(Verb) $(CP) -f $< $@
85 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
86 $(OcamlDir)/.dir $(ObjDir)/.dir
87 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
89 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
91 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
94 ##===- Build static library from C sources --------------------------------===##
96 all-local:: $(LibraryA)
98 install-local:: install-a
99 uninstall-local:: uninstall-a
101 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
102 $(Echo) "Building $(BuildMode) $(notdir $@)"
104 $(Verb) $(Archive) $@ $(ObjectsO)
108 -$(Verb) $(RM) -f $(LibraryA)
110 install-a:: $(LibraryA)
111 $(Echo) "Installing $(BuildMode) $(DestA)"
112 $(Verb) $(MKDIR) $(PROJ_libocamldir)
113 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
117 $(Echo) "Uninstalling $(DestA)"
118 -$(Verb) $(RM) -f $(DestA)
121 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
123 all-local:: build-cmis
124 clean-local:: clean-cmis
125 install-local:: install-cmis
126 uninstall-local:: uninstall-cmis
128 build-cmis: $(OutputsCMI)
130 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
131 $(Verb) $(CP) -f $< $@
133 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
134 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
135 $(Verb) $(Compile.CMI) $@ $<
138 -$(Verb) $(RM) -f $(OutputsCMI)
140 # Also install the .mli's (headers) as documentation.
141 install-cmis: $(OutputsCMI) $(OcamlHeaders)
142 $(Verb) $(MKDIR) $(PROJ_libocamldir)
143 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
144 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
145 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
147 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
148 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
149 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
153 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
154 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
155 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
157 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
158 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
159 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
163 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
165 all-local:: $(OutputCMA)
166 clean-local:: clean-cma
167 install-local:: install-cma
168 uninstall-local:: uninstall-cma
170 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
171 $(Verb) $(CP) -f $< $@
173 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
174 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
175 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
176 $(Verb) for i in $(UsedLibNames); do \
177 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
180 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
181 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
182 $(Verb) $(Compile.CMO) $@ $<
185 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
187 install-cma:: $(OutputCMA)
188 $(Echo) "Installing $(BuildMode) $(DestCMA)"
189 $(Verb) $(MKDIR) $(PROJ_libocamldir)
190 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
191 $(Verb) for i in $(UsedLibNames); do \
192 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
193 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
197 $(Echo) "Uninstalling $(DestCMA)"
198 -$(Verb) $(RM) -f $(DestCMA)
199 $(Verb) for i in $(UsedLibNames); do \
200 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
201 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
205 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
207 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
208 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
211 all-local:: $(OutputCMXA) $(OutputsCMX)
212 clean-local:: clean-cmxa
213 install-local:: install-cmxa
214 uninstall-local:: uninstall-cmxa
216 $(OutputCMXA): $(LibraryCMXA)
217 $(Verb) $(CP) -f $< $@
218 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
220 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
221 $(Verb) $(CP) -f $< $@
223 $(LibraryCMXA): $(ObjectsCMX)
224 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
225 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
226 $(Verb) $(RM) -f $(@:.cmxa=.o)
228 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
229 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
230 $(Verb) $(Compile.CMX) $@ $<
233 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
235 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
236 $(Verb) $(MKDIR) $(PROJ_libocamldir)
237 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
238 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
239 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
240 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
241 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
242 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
243 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
247 $(Echo) "Uninstalling $(DestCMXA)"
248 $(Verb) $(RM) -f $(DestCMXA)
249 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
250 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
251 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
252 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
253 $(RM) -f $(PROJ_libocamldir)/$$i; \
259 ##===- Debugging gunk -----------------------------------------------------===##
260 printvars:: printcamlvars
263 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
264 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
265 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
266 $(Echo) "OCAMLC : " '$(OCAMLC)'
267 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
268 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
269 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
270 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
271 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
272 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
273 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
274 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
275 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
276 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
277 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
278 $(Echo) "OcamlSources : " '$(OcamlSources)'
279 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
280 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
281 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
282 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
283 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
284 $(Echo) "DestA : " '$(DestA)'
285 $(Echo) "DestCMA : " '$(DestCMA)'
286 $(Echo) "DestCMXA : " '$(DestCMXA)'
287 $(Echo) "UsedLibs : " '$(UsedLibs)'
288 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
290 .PHONY: printcamlvars build-cmis \
291 clean-a clean-cmis clean-cma clean-cmxa \
292 install-a install-cmis install-cma install-cmxa \
293 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa