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 # -g was introduced in 3.10.0.
46 #ifneq ($(ENABLE_OPTIMIZED),1)
47 # OCAMLDEBUGFLAG := -g
50 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
51 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
52 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
55 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
56 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
59 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
60 OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
62 OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
63 OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
66 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
67 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
68 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
69 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
70 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
73 # The .cmo files are the only intermediates; all others are to be installed.
74 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
75 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
76 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
77 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
78 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
79 OutputLibs := $(UsedLibNames:%=$(OcamlDir)/%)
81 # Installation targets
82 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
83 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
84 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
85 DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%)
88 ##===- Dependencies -------------------------------------------------------===##
89 # Copy the sources into the intermediate directory because older ocamlc doesn't
90 # support -o except when linking (outputs are placed next to inputs).
92 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
93 $(Verb) $(CP) -f $< $@
95 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
96 $(Verb) $(CP) -f $< $@
98 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
99 $(OcamlDir)/.dir $(ObjDir)/.dir
100 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
102 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
104 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
107 ##===- Build static library from C sources --------------------------------===##
109 all-local:: $(LibraryA)
110 clean-local:: clean-a
111 install-local:: install-a
112 uninstall-local:: uninstall-a
114 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
115 $(Echo) "Building $(BuildMode) $(notdir $@)"
117 $(Verb) $(Archive) $@ $(ObjectsO)
121 -$(Verb) $(RM) -f $(LibraryA)
123 install-a:: $(LibraryA)
124 $(Echo) "Installing $(BuildMode) $(DestA)"
125 $(Verb) $(MKDIR) $(PROJ_libocamldir)
126 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
130 $(Echo) "Uninstalling $(DestA)"
131 -$(Verb) $(RM) -f $(DestA)
134 ##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===##
136 all-local:: build-deplibs
137 clean-local:: clean-deplibs
138 install-local:: install-deplibs
139 uninstall-local:: uninstall-deplibs
141 build-deplibs: $(OutputLibs)
143 $(OcamlDir)/%.a: $(LibDir)/%.a
146 $(OcamlDir)/%.o: $(LibDir)/%.o
150 $(Verb) rm -f $(OutputLibs)
153 $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \
154 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
158 $(Verb) rm -f $(DestLibs)
161 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
163 all-local:: build-cmis
164 clean-local:: clean-cmis
165 install-local:: install-cmis
166 uninstall-local:: uninstall-cmis
168 build-cmis: $(OutputsCMI)
170 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
171 $(Verb) $(CP) -f $< $@
173 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
174 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
175 $(Verb) $(Compile.CMI) $@ $<
178 -$(Verb) $(RM) -f $(OutputsCMI)
180 # Also install the .mli's (headers) as documentation.
181 install-cmis: $(OutputsCMI) $(OcamlHeaders)
182 $(Verb) $(MKDIR) $(PROJ_libocamldir)
183 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
184 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
185 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
187 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
188 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
189 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
193 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
194 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
195 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
197 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
198 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
199 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
203 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
205 all-local:: $(OutputCMA)
206 clean-local:: clean-cma
207 install-local:: install-cma
208 uninstall-local:: uninstall-cma
210 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
211 $(Verb) $(CP) -f $< $@
213 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
214 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
215 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
217 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
218 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
219 $(Verb) $(Compile.CMO) $@ $<
222 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
224 install-cma:: $(OutputCMA)
225 $(Echo) "Installing $(BuildMode) $(DestCMA)"
226 $(Verb) $(MKDIR) $(PROJ_libocamldir)
227 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
230 $(Echo) "Uninstalling $(DestCMA)"
231 -$(Verb) $(RM) -f $(DestCMA)
234 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
236 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
237 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
240 all-local:: $(OutputCMXA) $(OutputsCMX)
241 clean-local:: clean-cmxa
242 install-local:: install-cmxa
243 uninstall-local:: uninstall-cmxa
245 $(OutputCMXA): $(LibraryCMXA)
246 $(Verb) $(CP) -f $< $@
247 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
249 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
250 $(Verb) $(CP) -f $< $@
252 $(LibraryCMXA): $(ObjectsCMX)
253 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
254 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
255 $(Verb) $(RM) -f $(@:.cmxa=.o)
257 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
258 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
259 $(Verb) $(Compile.CMX) $@ $<
262 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
264 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
265 $(Verb) $(MKDIR) $(PROJ_libocamldir)
266 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
267 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
268 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
269 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
270 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
271 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
272 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
276 $(Echo) "Uninstalling $(DestCMXA)"
277 $(Verb) $(RM) -f $(DestCMXA)
278 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
279 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
280 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
281 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
282 $(RM) -f $(PROJ_libocamldir)/$$i; \
288 ##===- Debugging gunk -----------------------------------------------------===##
289 printvars:: printcamlvars
292 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
293 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
294 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
295 $(Echo) "OCAMLC : " '$(OCAMLC)'
296 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
297 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
298 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
299 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
300 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
301 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
302 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
303 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
304 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
305 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
306 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
307 $(Echo) "OcamlSources : " '$(OcamlSources)'
308 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
309 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
310 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
311 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
312 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
313 $(Echo) "DestA : " '$(DestA)'
314 $(Echo) "DestCMA : " '$(DestCMA)'
315 $(Echo) "DestCMXA : " '$(DestCMXA)'
316 $(Echo) "UsedLibs : " '$(UsedLibs)'
317 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
319 .PHONY: printcamlvars build-cmis \
320 clean-a clean-cmis clean-cma clean-cmxa \
321 install-a install-cmis install-cma install-cmxa \
322 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa