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),-l$(LIBRARYNAME) \
42 $(shell $(LLVM_CONFIG) --ldflags)) \
45 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
46 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
47 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
49 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
50 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
53 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
54 OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
56 OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
57 OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
60 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
61 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
62 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
63 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
64 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
67 # The .cmo files are the only intermediates; all others are to be installed.
68 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
69 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
70 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
71 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
72 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
74 # Installation targets
75 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
76 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
77 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
80 ##===- Dependencies -------------------------------------------------------===##
81 # Copy the sources into the intermediate directory because older ocamlc doesn't
82 # support -o except when linking (outputs are placed next to inputs).
84 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
85 $(Verb) $(CP) -f $< $@
87 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
88 $(Verb) $(CP) -f $< $@
90 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
91 $(OcamlDir)/.dir $(ObjDir)/.dir
92 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
94 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
96 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
99 ##===- Build static library from C sources --------------------------------===##
101 all-local:: $(LibraryA)
102 clean-local:: clean-a
103 install-local:: install-a
104 uninstall-local:: uninstall-a
106 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
107 $(Echo) "Building $(BuildMode) $(notdir $@)"
109 $(Verb) $(Archive) $@ $(ObjectsO)
113 -$(Verb) $(RM) -f $(LibraryA)
115 install-a:: $(LibraryA)
116 $(Echo) "Installing $(BuildMode) $(DestA)"
117 $(Verb) $(MKDIR) $(PROJ_libocamldir)
118 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
122 $(Echo) "Uninstalling $(DestA)"
123 -$(Verb) $(RM) -f $(DestA)
126 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
128 all-local:: build-cmis
129 clean-local:: clean-cmis
130 install-local:: install-cmis
131 uninstall-local:: uninstall-cmis
133 build-cmis: $(OutputsCMI)
135 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
136 $(Verb) $(CP) -f $< $@
138 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
139 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
140 $(Verb) $(Compile.CMI) $@ $<
143 -$(Verb) $(RM) -f $(OutputsCMI)
145 # Also install the .mli's (headers) as documentation.
146 install-cmis: $(OutputsCMI) $(OcamlHeaders)
147 $(Verb) $(MKDIR) $(PROJ_libocamldir)
148 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
149 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
150 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
152 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
153 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
154 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
158 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
159 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
160 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
162 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
163 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
164 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
168 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
170 all-local:: $(OutputCMA)
171 clean-local:: clean-cma
172 install-local:: install-cma
173 uninstall-local:: uninstall-cma
175 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
176 $(Verb) $(CP) -f $< $@
178 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
179 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
180 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
181 $(Verb) for i in $(UsedLibNames); do \
182 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
185 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
186 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
187 $(Verb) $(Compile.CMO) $@ $<
190 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
192 install-cma:: $(OutputCMA)
193 $(Echo) "Installing $(BuildMode) $(DestCMA)"
194 $(Verb) $(MKDIR) $(PROJ_libocamldir)
195 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
196 $(Verb) for i in $(UsedLibNames); do \
197 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
201 $(Echo) "Uninstalling $(DestCMA)"
202 -$(Verb) $(RM) -f $(DestCMA)
203 $(Verb) for i in $(UsedLibNames); do \
204 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
208 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
210 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
211 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
214 all-local:: $(OutputCMXA) $(OutputsCMX)
215 clean-local:: clean-cmxa
216 install-local:: install-cmxa
217 uninstall-local:: uninstall-cmxa
219 $(OutputCMXA): $(LibraryCMXA)
220 $(Verb) $(CP) -f $< $@
221 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
223 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
224 $(Verb) $(CP) -f $< $@
226 $(LibraryCMXA): $(ObjectsCMX)
227 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
228 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
229 $(Verb) $(RM) -f $(@:.cmxa=.o)
231 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
232 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
233 $(Verb) $(Compile.CMX) $@ $<
236 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
238 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
239 $(Verb) $(MKDIR) $(PROJ_libocamldir)
240 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
241 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
242 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
243 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
244 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
245 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
246 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
250 $(Echo) "Uninstalling $(DestCMXA)"
251 $(Verb) $(RM) -f $(DestCMXA)
252 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
253 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
254 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
255 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
256 $(RM) -f $(PROJ_libocamldir)/$$i; \
262 ##===- Debugging gunk -----------------------------------------------------===##
263 printvars:: printcamlvars
266 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
267 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
268 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
269 $(Echo) "OCAMLC : " '$(OCAMLC)'
270 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
271 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
272 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
273 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
274 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
275 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
276 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
277 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
278 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
279 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
280 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
281 $(Echo) "OcamlSources : " '$(OcamlSources)'
282 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
283 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
284 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
285 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
286 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
287 $(Echo) "DestA : " '$(DestA)'
288 $(Echo) "DestCMA : " '$(DestCMA)'
289 $(Echo) "DestCMXA : " '$(DestCMXA)'
290 $(Echo) "UsedLibs : " '$(UsedLibs)'
291 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
293 .PHONY: printcamlvars build-cmis \
294 clean-a clean-cmis clean-cma clean-cmxa \
295 install-a install-cmis install-cma install-cmxa \
296 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa