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 # 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 CFLAGS += -I$(shell $(OCAMLC) -where)
25 include $(LEVEL)/Makefile.common
27 # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
28 # user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
29 PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
30 OcamlDir := $(LibDir)/ocaml
32 # Info from llvm-config and similar
34 UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
35 UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
39 OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
40 OCAMLAFLAGS += $(patsubst %,-cclib %, \
41 $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
42 $(UsedLibs) -l$(LIBRARYNAME))
44 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
45 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
46 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
48 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
49 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
52 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
53 OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
55 OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
56 OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
59 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
60 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
61 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
62 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
63 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
66 # The .cmo files are the only intermediates; all others are to be installed.
67 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
68 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
69 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
70 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
71 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
73 # Installation targets
74 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
75 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
76 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
79 ##===- Dependencies -------------------------------------------------------===##
80 # Copy the sources into the intermediate directory because older ocamlc doesn't
81 # support -o except when linking (outputs are placed next to inputs).
83 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
84 $(Verb) $(CP) -f $< $@
86 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
87 $(Verb) $(CP) -f $< $@
89 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
90 $(OcamlDir)/.dir $(ObjDir)/.dir
91 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
93 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
95 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
98 ##===- Build static library from C sources --------------------------------===##
100 all-local:: $(LibraryA)
101 clean-local:: clean-a
102 install-local:: install-a
103 uninstall-local:: uninstall-a
105 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
106 $(Echo) "Building $(BuildMode) $(notdir $@)"
108 $(Verb) $(Archive) $@ $(ObjectsO)
112 -$(Verb) $(RM) -f $(LibraryA)
114 install-a:: $(LibraryA)
115 $(Echo) "Installing $(BuildMode) $(DestA)"
116 $(Verb) $(MKDIR) $(PROJ_libocamldir)
117 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
121 $(Echo) "Uninstalling $(DestA)"
122 -$(Verb) $(RM) -f $(DestA)
125 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
127 all-local:: build-cmis
128 clean-local:: clean-cmis
129 install-local:: install-cmis
130 uninstall-local:: uninstall-cmis
132 build-cmis: $(OutputsCMI)
134 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
135 $(Verb) $(CP) -f $< $@
137 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
138 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
139 $(Verb) $(Compile.CMI) $@ $<
142 -$(Verb) $(RM) -f $(OutputsCMI)
144 # Also install the .mli's (headers) as documentation.
145 install-cmis: $(OutputsCMI) $(OcamlHeaders)
146 $(Verb) $(MKDIR) $(PROJ_libocamldir)
147 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
148 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
149 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
151 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
152 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
153 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
157 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
158 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
159 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
161 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
162 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
163 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
167 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
169 all-local:: $(OutputCMA)
170 clean-local:: clean-cma
171 install-local:: install-cma
172 uninstall-local:: uninstall-cma
174 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
175 $(Verb) $(CP) -f $< $@
177 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
178 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
179 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
180 $(Verb) for i in $(UsedLibNames); do \
181 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
184 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
185 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
186 $(Verb) $(Compile.CMO) $@ $<
189 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
191 install-cma:: $(OutputCMA)
192 $(Echo) "Installing $(BuildMode) $(DestCMA)"
193 $(Verb) $(MKDIR) $(PROJ_libocamldir)
194 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
195 $(Verb) for i in $(UsedLibNames); do \
196 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
200 $(Echo) "Uninstalling $(DestCMA)"
201 -$(Verb) $(RM) -f $(DestCMA)
202 $(Verb) for i in $(UsedLibNames); do \
203 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
207 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
209 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
210 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
213 all-local:: $(OutputCMXA) $(OutputsCMX)
214 clean-local:: clean-cmxa
215 install-local:: install-cmxa
216 uninstall-local:: uninstall-cmxa
218 $(OutputCMXA): $(LibraryCMXA)
219 $(Verb) $(CP) -f $< $@
220 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
222 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
223 $(Verb) $(CP) -f $< $@
225 $(LibraryCMXA): $(ObjectsCMX)
226 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
227 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
228 $(Verb) $(RM) -f $(@:.cmxa=.o)
230 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
231 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
232 $(Verb) $(Compile.CMX) $@ $<
235 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
237 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
238 $(Verb) $(MKDIR) $(PROJ_libocamldir)
239 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
240 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
241 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
242 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
243 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
244 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
245 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
249 $(Echo) "Uninstalling $(DestCMXA)"
250 $(Verb) $(RM) -f $(DestCMXA)
251 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
252 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
253 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
254 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
255 $(RM) -f $(PROJ_libocamldir)/$$i; \
261 ##===- Debugging gunk -----------------------------------------------------===##
262 printvars:: printcamlvars
265 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
266 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
267 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
268 $(Echo) "OCAMLC : " '$(OCAMLC)'
269 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
270 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
271 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
272 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
273 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
274 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
275 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
276 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
277 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
278 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
279 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
280 $(Echo) "OcamlSources : " '$(OcamlSources)'
281 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
282 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
283 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
284 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
285 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
286 $(Echo) "DestA : " '$(DestA)'
287 $(Echo) "DestCMA : " '$(DestCMA)'
288 $(Echo) "DestCMXA : " '$(DestCMXA)'
289 $(Echo) "UsedLibs : " '$(UsedLibs)'
290 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
292 .PHONY: printcamlvars build-cmis \
293 clean-a clean-cmis clean-cma clean-cmxa \
294 install-a install-cmis install-cma install-cmxa \
295 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa