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)
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 OcamlSources := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
55 OcamlHeaders := $(OcamlSources:.ml=.mli)
57 # Output and intermediate files
58 # The .cmo files are the only intermediates; all others get installed.
59 BareLibraryA := lib$(LIBRARYNAME).a
60 LibraryA := $(OcamlDir)/$(BareLibraryA)
61 LibraryCMA := $(OcamlDir)/$(LIBRARYNAME).cma
62 LibraryCMXA := $(OcamlDir)/$(LIBRARYNAME).cmxa
63 ObjectsCMI := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(OcamlDir)/%.cmi)
64 ObjectsCMO := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(ObjDir)/%.cmo)
65 ObjectsCMX := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(OcamlDir)/%.cmx)
68 # Punting on ocamldep, since its output is only suitable for builds where
69 # objects are placed directly adjacent to sources, which is not us.
70 # Unfortunately, this is subtly incorrect and leads to occasional problems.
71 # ocamlc/ocamlopt really need an option akin to gcc -M or gcc -MD.
72 $(ObjectsCMO): $(ObjectsCMI) $(UsedOcamLibs:%=$(OcamlDir)/%.cmi)
73 $(ObjectsCMX): $(ObjectsCMI) $(UsedOcamLibs:%=$(OcamlDir)/%.cmi)
75 # Installation targets
76 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
77 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
78 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
81 ##===- Build static library from C sources --------------------------------===##
83 all-local:: $(LibraryA)
85 install-local:: install-a
86 uninstall-local:: uninstall-a
88 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
89 $(Echo) "Building $(BuildMode) $(notdir $@)"
91 $(Verb) $(Archive) $@ $(ObjectsO)
95 -$(Verb) $(RM) -f $(LibraryA)
97 install-a:: $(LibraryA)
98 $(Echo) "Installing $(BuildMode) $(DestA)"
99 $(Verb) $(MKDIR) $(PROJ_libocamldir)
100 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
104 $(Echo) "Uninstalling $(DestA)"
105 -$(Verb) $(RM) -f $(DestA)
108 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
110 all-local:: build-cmis
111 clean-local:: clean-cmis
112 install-local:: install-cmis
113 uninstall-local:: uninstall-cmis
115 build-cmis: $(ObjectsCMI)
117 $(OcamlDir)/%.cmi: $(PROJ_SRC_DIR)/%.mli $(OcamlDir)/.dir
118 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
119 $(Verb) $(Compile.CMI) $@ $<
122 -$(Verb) $(RM) -f $(ObjectsCMI)
124 # Also install the .mli's (headers) as documentation.
125 install-cmis: $(ObjectsCMI)
126 $(Verb) $(MKDIR) $(PROJ_libocamldir)
127 $(Verb) for i in $(patsubst $(OcamlDir)/%,%,$(ObjectsCMI)); do \
128 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
129 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
131 $(Verb) for i in $(patsubst $(PROJ_SRC_DIR)/%,%,$(OcamlHeaders)); do \
132 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
133 $(DataInstall) $(PROJ_SRC_DIR)/$$i "$(PROJ_libocamldir)/$$i"; \
137 $(Verb) for i in $(patsubst $(OcamlDir)/%,%,$(ObjectsCMI)); do \
138 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
139 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
141 $(Verb) for i in $(patsubst $(PROJ_SRC_DIR)/%,%,$(OcamlHeaders)); do \
142 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
143 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
147 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
149 all-local:: $(LibraryCMA)
150 clean-local:: clean-cma
151 install-local:: install-cma
152 uninstall-local:: uninstall-cma
154 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
155 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
156 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
157 $(Verb) for i in $(UsedLibNames); do \
158 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
161 $(ObjDir)/%.cmo: $(PROJ_SRC_DIR)/%.ml $(OcamlDir)/.dir
162 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
163 $(Verb) $(Compile.CMO) $@ $<
166 $(Verb) $(RM) -f $(LibraryCMA)
168 install-cma:: $(LibraryCMA)
169 $(Echo) "Installing $(BuildMode) $(DestCMA)"
170 $(Verb) $(MKDIR) $(PROJ_libocamldir)
171 $(Verb) $(DataInstall) $(LibraryCMA) "$(DestCMA)"
172 $(Verb) for i in $(UsedLibNames); do \
173 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
174 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
178 $(Echo) "Uninstalling $(DestCMA)"
179 -$(Verb) $(RM) -f $(DestCMA)
180 $(Verb) for i in $(UsedLibNames); do \
181 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
182 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
186 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
188 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
189 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
192 all-local:: $(LibraryCMXA)
193 clean-local:: clean-cmxa
194 install-local:: install-cmxa
195 uninstall-local:: uninstall-cmxa
197 $(LibraryCMXA): $(ObjectsCMX)
198 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
199 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
200 $(Verb) $(RM) -f $(@:.cmxa=.o)
202 $(OcamlDir)/%.cmx: $(PROJ_SRC_DIR)/%.ml
203 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
204 $(Verb) $(Compile.CMX) $@ $<
207 $(Verb) $(RM) -f $(LibraryCMXA) $(LibraryCMXA:.cmxa=.o) \
208 $(LibraryCMXA:.cmxa=.a) $(ObjectsCMX)
210 install-cmxa:: $(LibraryCMXA)
211 $(Verb) $(MKDIR) $(PROJ_libocamldir)
212 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
213 $(Verb) $(DataInstall) $(LibraryCMXA) $(DestCMXA)
214 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
215 $(Verb) $(DataInstall) $(LibraryCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
216 $(Verb) for i in $(ObjectsCMX:$(OcamlDir)/%=%); do \
217 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
218 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
221 uninstall-cmxa:: $(LibraryCMXA)
222 $(Echo) "Uninstalling $(DestCMXA)"
223 $(Verb) $(RM) -f $(DestCMXA)
224 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
225 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
226 $(Verb) for i in $(ObjectsCMX:$(OcamlDir)/%=%); do \
227 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
228 $(RM) -f $(PROJ_libocamldir)/$$i; \
234 ##===- Debugging gunk -----------------------------------------------------===##
235 printvars:: printcamlvars
238 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
239 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
240 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
241 $(Echo) "OCAMLC : " '$(OCAMLC)'
242 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
243 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
244 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
245 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
246 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
247 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
248 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
249 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
250 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
251 $(Echo) "OcamlSources : " '$(OcamlSources)'
252 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
253 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
254 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
255 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
256 $(Echo) "DestA : " '$(DestA)'
257 $(Echo) "DestCMA : " '$(DestCMA)'
258 $(Echo) "DestCMXA : " '$(DestCMXA)'
259 $(Echo) "UsedLibs : " '$(UsedLibs)'
260 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
262 .PHONY: printcamlvars build-cmis \
263 clean-a clean-cmis clean-cma clean-cmxa \
264 install-a install-cmis install-cma install-cmxa \
265 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa