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 # Find the ocaml stdlib root. /usr/local/lib/ocaml is the default when built
18 # from source; distros use something like /usr/lib/ocaml/3.10.0.
20 OCAML_LIBDIR := $(shell $(OCAMLC) -where)
23 # CFLAGS needs to be set before Makefile.rules is included. Yes, ocaml puts its
24 # includes under its libdir.
25 CFLAGS += -I$(OCAML_LIBDIR)
27 include $(LEVEL)/Makefile.common
29 # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
30 # user can override this with OCAML_LIBDIR.
31 PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
32 OcamlDir := $(LibDir)/ocaml
34 # Info from llvm-config and similar
36 UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
37 UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
41 OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
42 OCAMLAFLAGS += $(patsubst %,-cclib %, \
43 $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
44 $(UsedLibs) -l$(LIBRARYNAME))
46 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
47 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
48 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
50 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
51 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
54 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
55 OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
57 OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
58 OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
61 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
62 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
63 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
64 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
65 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
68 # The .cmo files are the only intermediates; all others are to be installed.
69 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
70 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
71 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
72 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
73 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
75 # Installation targets
76 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
77 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
78 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
81 ##===- Dependencies -------------------------------------------------------===##
82 # Copy the sources into the intermediate directory because older ocamlc doesn't
83 # support -o except when linking (outputs are placed next to inputs).
85 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
86 $(Verb) $(CP) -f $< $@
88 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
89 $(Verb) $(CP) -f $< $@
91 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
92 $(OcamlDir)/.dir $(ObjDir)/.dir
93 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
95 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
97 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
100 ##===- Build static library from C sources --------------------------------===##
102 all-local:: $(LibraryA)
103 clean-local:: clean-a
104 install-local:: install-a
105 uninstall-local:: uninstall-a
107 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
108 $(Echo) "Building $(BuildMode) $(notdir $@)"
110 $(Verb) $(Archive) $@ $(ObjectsO)
114 -$(Verb) $(RM) -f $(LibraryA)
116 install-a:: $(LibraryA)
117 $(Echo) "Installing $(BuildMode) $(DestA)"
118 $(Verb) $(MKDIR) $(PROJ_libocamldir)
119 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
123 $(Echo) "Uninstalling $(DestA)"
124 -$(Verb) $(RM) -f $(DestA)
127 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
129 all-local:: build-cmis
130 clean-local:: clean-cmis
131 install-local:: install-cmis
132 uninstall-local:: uninstall-cmis
134 build-cmis: $(OutputsCMI)
136 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
137 $(Verb) $(CP) -f $< $@
139 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
140 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
141 $(Verb) $(Compile.CMI) $@ $<
144 -$(Verb) $(RM) -f $(OutputsCMI)
146 # Also install the .mli's (headers) as documentation.
147 install-cmis: $(OutputsCMI) $(OcamlHeaders)
148 $(Verb) $(MKDIR) $(PROJ_libocamldir)
149 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
150 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
151 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
153 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
154 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
155 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
159 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
160 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
161 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
163 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
164 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
165 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
169 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
171 all-local:: $(OutputCMA)
172 clean-local:: clean-cma
173 install-local:: install-cma
174 uninstall-local:: uninstall-cma
176 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
177 $(Verb) $(CP) -f $< $@
179 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
180 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
181 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
182 $(Verb) for i in $(UsedLibNames); do \
183 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
186 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
187 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
188 $(Verb) $(Compile.CMO) $@ $<
191 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
193 install-cma:: $(OutputCMA)
194 $(Echo) "Installing $(BuildMode) $(DestCMA)"
195 $(Verb) $(MKDIR) $(PROJ_libocamldir)
196 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
197 $(Verb) for i in $(UsedLibNames); do \
198 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
199 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
203 $(Echo) "Uninstalling $(DestCMA)"
204 -$(Verb) $(RM) -f $(DestCMA)
205 $(Verb) for i in $(UsedLibNames); do \
206 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
207 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
211 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
213 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
214 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
217 all-local:: $(OutputCMXA) $(OutputsCMX)
218 clean-local:: clean-cmxa
219 install-local:: install-cmxa
220 uninstall-local:: uninstall-cmxa
222 $(OutputCMXA): $(LibraryCMXA)
223 $(Verb) $(CP) -f $< $@
224 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
226 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
227 $(Verb) $(CP) -f $< $@
229 $(LibraryCMXA): $(ObjectsCMX)
230 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
231 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
232 $(Verb) $(RM) -f $(@:.cmxa=.o)
234 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
235 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
236 $(Verb) $(Compile.CMX) $@ $<
239 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
241 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
242 $(Verb) $(MKDIR) $(PROJ_libocamldir)
243 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
244 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
245 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
246 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
247 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
248 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
249 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
253 $(Echo) "Uninstalling $(DestCMXA)"
254 $(Verb) $(RM) -f $(DestCMXA)
255 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
256 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
257 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
258 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
259 $(RM) -f $(PROJ_libocamldir)/$$i; \
265 ##===- Debugging gunk -----------------------------------------------------===##
266 printvars:: printcamlvars
269 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
270 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
271 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
272 $(Echo) "OCAMLC : " '$(OCAMLC)'
273 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
274 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
275 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
276 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
277 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
278 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
279 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
280 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
281 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
282 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
283 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
284 $(Echo) "OcamlSources : " '$(OcamlSources)'
285 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
286 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
287 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
288 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
289 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
290 $(Echo) "DestA : " '$(DestA)'
291 $(Echo) "DestCMA : " '$(DestCMA)'
292 $(Echo) "DestCMXA : " '$(DestCMXA)'
293 $(Echo) "UsedLibs : " '$(UsedLibs)'
294 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
296 .PHONY: printcamlvars build-cmis \
297 clean-a clean-cmis clean-cma clean-cmxa \
298 install-a install-cmis install-cma install-cmxa \
299 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa