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.
18 CFLAGS += -I$(shell $(OCAMLC) -where)
20 include $(LEVEL)/Makefile.common
22 # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
23 # user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
24 PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
25 OcamlDir := $(LibDir)/ocaml
27 # Info from llvm-config and similar
29 UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
30 UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
34 OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
35 OCAMLAFLAGS += $(patsubst %,-cclib %, \
36 $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
37 $(UsedLibs) -l$(LIBRARYNAME))
39 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
40 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
41 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
43 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
44 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
47 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
48 OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
50 OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
51 OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
54 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
55 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
56 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
57 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
58 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
61 # The .cmo files are the only intermediates; all others are to be installed.
62 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
63 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
64 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
65 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
66 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
68 # Installation targets
69 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
70 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
71 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
74 ##===- Dependencies -------------------------------------------------------===##
75 # Copy the sources into the intermediate directory because older ocamlc doesn't
76 # support -o except when linking (outputs are placed next to inputs).
78 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
79 $(Verb) $(CP) -f $< $@
81 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
82 $(Verb) $(CP) -f $< $@
84 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
85 $(OcamlDir)/.dir $(ObjDir)/.dir
86 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
88 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
90 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
93 ##===- Build static library from C sources --------------------------------===##
95 all-local:: $(LibraryA)
97 install-local:: install-a
98 uninstall-local:: uninstall-a
100 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
101 $(Echo) "Building $(BuildMode) $(notdir $@)"
103 $(Verb) $(Archive) $@ $(ObjectsO)
107 -$(Verb) $(RM) -f $(LibraryA)
109 install-a:: $(LibraryA)
110 $(Echo) "Installing $(BuildMode) $(DestA)"
111 $(Verb) $(MKDIR) $(PROJ_libocamldir)
112 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
116 $(Echo) "Uninstalling $(DestA)"
117 -$(Verb) $(RM) -f $(DestA)
120 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
122 all-local:: build-cmis
123 clean-local:: clean-cmis
124 install-local:: install-cmis
125 uninstall-local:: uninstall-cmis
127 build-cmis: $(OutputsCMI)
129 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
130 $(Verb) $(CP) -f $< $@
132 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
133 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
134 $(Verb) $(Compile.CMI) $@ $<
137 -$(Verb) $(RM) -f $(OutputsCMI)
139 # Also install the .mli's (headers) as documentation.
140 install-cmis: $(OutputsCMI) $(OcamlHeaders)
141 $(Verb) $(MKDIR) $(PROJ_libocamldir)
142 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
143 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
144 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
146 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
147 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
148 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
152 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
153 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
154 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
156 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
157 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
158 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
162 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
164 all-local:: $(OutputCMA)
165 clean-local:: clean-cma
166 install-local:: install-cma
167 uninstall-local:: uninstall-cma
169 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
170 $(Verb) $(CP) -f $< $@
172 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
173 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
174 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
175 $(Verb) for i in $(UsedLibNames); do \
176 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
179 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
180 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
181 $(Verb) $(Compile.CMO) $@ $<
184 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
186 install-cma:: $(OutputCMA)
187 $(Echo) "Installing $(BuildMode) $(DestCMA)"
188 $(Verb) $(MKDIR) $(PROJ_libocamldir)
189 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
190 $(Verb) for i in $(UsedLibNames); do \
191 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
192 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
196 $(Echo) "Uninstalling $(DestCMA)"
197 -$(Verb) $(RM) -f $(DestCMA)
198 $(Verb) for i in $(UsedLibNames); do \
199 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
200 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
204 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
206 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
207 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
210 all-local:: $(OutputCMXA) $(OutputsCMX)
211 clean-local:: clean-cmxa
212 install-local:: install-cmxa
213 uninstall-local:: uninstall-cmxa
215 $(OutputCMXA): $(LibraryCMXA)
216 $(Verb) $(CP) -f $< $@
217 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
219 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
220 $(Verb) $(CP) -f $< $@
222 $(LibraryCMXA): $(ObjectsCMX)
223 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
224 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
225 $(Verb) $(RM) -f $(@:.cmxa=.o)
227 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
228 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
229 $(Verb) $(Compile.CMX) $@ $<
232 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
234 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
235 $(Verb) $(MKDIR) $(PROJ_libocamldir)
236 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
237 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
238 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
239 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
240 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
241 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
242 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
246 $(Echo) "Uninstalling $(DestCMXA)"
247 $(Verb) $(RM) -f $(DestCMXA)
248 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
249 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
250 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
251 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
252 $(RM) -f $(PROJ_libocamldir)/$$i; \
258 ##===- Debugging gunk -----------------------------------------------------===##
259 printvars:: printcamlvars
262 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
263 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
264 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
265 $(Echo) "OCAMLC : " '$(OCAMLC)'
266 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
267 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
268 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
269 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
270 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
271 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
272 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
273 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
274 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
275 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
276 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
277 $(Echo) "OcamlSources : " '$(OcamlSources)'
278 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
279 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
280 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
281 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
282 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
283 $(Echo) "DestA : " '$(DestA)'
284 $(Echo) "DestCMA : " '$(DestCMA)'
285 $(Echo) "DestCMXA : " '$(DestCMXA)'
286 $(Echo) "UsedLibs : " '$(UsedLibs)'
287 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
289 .PHONY: printcamlvars build-cmis \
290 clean-a clean-cmis clean-cma clean-cmxa \
291 install-a install-cmis install-cma install-cmxa \
292 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa