blob: 8edb180c3df8a0a4dec68f30368fa39d835cd918 [file] [log] [blame]
Gordon Henriksen0908d492007-09-18 12:26:17 +00001##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===##
2#
3# The LLVM Compiler Infrastructure
4#
Chris Lattner57360d12007-12-29 20:11:13 +00005# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
Gordon Henriksen0908d492007-09-18 12:26:17 +00007#
8##===----------------------------------------------------------------------===##
9#
10# An ocaml library is a unique project type in the context of LLVM, so rules are
11# here rather than in Makefile.rules.
12#
Gordon Henriksenc0491ac2007-10-06 21:00:36 +000013# Reference materials on installing ocaml libraries:
14#
15# https://fedoraproject.org/wiki/Packaging/OCaml
16# http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt
17#
Gordon Henriksen0908d492007-09-18 12:26:17 +000018##===----------------------------------------------------------------------===##
19
20include $(LEVEL)/Makefile.config
21
Gordon Henriksen3b802472007-10-04 00:07:50 +000022# CFLAGS needs to be set before Makefile.rules is included.
Gordon Henriksen9e7aba22008-01-06 21:54:35 +000023CXX.Flags += -I"$(shell $(OCAMLC) -where)"
24C.Flags += -I"$(shell $(OCAMLC) -where)"
Gordon Henriksen0908d492007-09-18 12:26:17 +000025
26include $(LEVEL)/Makefile.common
27
28# Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
Gordon Henriksen1d4e0782007-10-02 16:42:10 +000029# user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
Gordon Henriksen0908d492007-09-18 12:26:17 +000030PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
31OcamlDir := $(LibDir)/ocaml
32
33# Info from llvm-config and similar
34ifdef UsedComponents
35UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
36UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
37endif
38
39# Tools
Gordon Henriksena8c36602007-09-20 16:47:41 +000040OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
Gordon Henriksen0908d492007-09-18 12:26:17 +000041OCAMLAFLAGS += $(patsubst %,-cclib %, \
Gordon Henriksened29a282007-10-12 19:48:13 +000042 $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \
43 $(shell $(LLVM_CONFIG) --ldflags)) \
44 $(UsedLibs))
Gordon Henriksen2e855e62007-12-23 16:59:28 +000045
Gordon Henriksen4e20a092007-12-25 08:37:43 +000046# -g was introduced in 3.10.0.
47#ifneq ($(ENABLE_OPTIMIZED),1)
48# OCAMLDEBUGFLAG := -g
49#endif
Gordon Henriksen0908d492007-09-18 12:26:17 +000050
Gordon Henriksen2e855e62007-12-23 16:59:28 +000051Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
52Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
53Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
54 -o)
Gordon Henriksen0908d492007-09-18 12:26:17 +000055
Gordon Henriksen2e855e62007-12-23 16:59:28 +000056Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
57Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
Gordon Henriksen0908d492007-09-18 12:26:17 +000058
59# Source files
Gordon Henriksena8c36602007-09-20 16:47:41 +000060OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
61OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
Gordon Henriksen0908d492007-09-18 12:26:17 +000062
Gordon Henriksena8c36602007-09-20 16:47:41 +000063OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
64OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000065
Gordon Henriksena8c36602007-09-20 16:47:41 +000066# Intermediate files
67LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
68LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
69ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
70ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
71ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
72
73# Output files
74# The .cmo files are the only intermediates; all others are to be installed.
75LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
76OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
77OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
78OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
79OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
Gordon Henriksen516276e2007-12-03 21:15:53 +000080OutputLibs := $(UsedLibNames:%=$(OcamlDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000081
82# Installation targets
83DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
84DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
85DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
Gordon Henriksen516276e2007-12-03 21:15:53 +000086DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000087
88
Gordon Henriksena8c36602007-09-20 16:47:41 +000089##===- Dependencies -------------------------------------------------------===##
90# Copy the sources into the intermediate directory because older ocamlc doesn't
91# support -o except when linking (outputs are placed next to inputs).
92
93$(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
94 $(Verb) $(CP) -f $< $@
95
96$(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
97 $(Verb) $(CP) -f $< $@
98
Gordon Henriksenab4456f2007-09-23 13:37:44 +000099$(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
100 $(OcamlDir)/.dir $(ObjDir)/.dir
Gordon Henriksene6074a02008-03-04 14:52:05 +0000101 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@
Gordon Henriksena8c36602007-09-20 16:47:41 +0000102
Gordon Henriksen46abf912007-09-26 20:56:12 +0000103$(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
104
Gordon Henriksena8c36602007-09-20 16:47:41 +0000105-include $(ObjDir)/$(LIBRARYNAME).ocamldep
106
107
Gordon Henriksen0908d492007-09-18 12:26:17 +0000108##===- Build static library from C sources --------------------------------===##
109
110all-local:: $(LibraryA)
111clean-local:: clean-a
112install-local:: install-a
113uninstall-local:: uninstall-a
114
115$(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
116 $(Echo) "Building $(BuildMode) $(notdir $@)"
117 -$(Verb) $(RM) -f $@
118 $(Verb) $(Archive) $@ $(ObjectsO)
119 $(Verb) $(Ranlib) $@
120
121clean-a::
122 -$(Verb) $(RM) -f $(LibraryA)
123
124install-a:: $(LibraryA)
125 $(Echo) "Installing $(BuildMode) $(DestA)"
126 $(Verb) $(MKDIR) $(PROJ_libocamldir)
127 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
128 $(Verb)
129
130uninstall-a::
131 $(Echo) "Uninstalling $(DestA)"
132 -$(Verb) $(RM) -f $(DestA)
133
134
Gordon Henriksen516276e2007-12-03 21:15:53 +0000135##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===##
136
137all-local:: build-deplibs
138clean-local:: clean-deplibs
139install-local:: install-deplibs
140uninstall-local:: uninstall-deplibs
141
142build-deplibs: $(OutputLibs)
143
144$(OcamlDir)/%.a: $(LibDir)/%.a
145 $(Verb) ln -sf $< $@
146
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000147$(OcamlDir)/%.o: $(LibDir)/%.o
148 $(Verb) ln -sf $< $@
149
Gordon Henriksen516276e2007-12-03 21:15:53 +0000150clean-deplibs:
151 $(Verb) rm -f $(OutputLibs)
152
153install-deplibs:
154 $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \
155 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
156 done
157
158uninstall-deplibs:
159 $(Verb) rm -f $(DestLibs)
160
161
Gordon Henriksen0908d492007-09-18 12:26:17 +0000162##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
163
164all-local:: build-cmis
165clean-local:: clean-cmis
166install-local:: install-cmis
167uninstall-local:: uninstall-cmis
168
Gordon Henriksena8c36602007-09-20 16:47:41 +0000169build-cmis: $(OutputsCMI)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000170
Gordon Henriksena8c36602007-09-20 16:47:41 +0000171$(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
172 $(Verb) $(CP) -f $< $@
173
174$(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
Gordon Henriksen0908d492007-09-18 12:26:17 +0000175 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
176 $(Verb) $(Compile.CMI) $@ $<
177
178clean-cmis::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000179 -$(Verb) $(RM) -f $(OutputsCMI)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000180
181# Also install the .mli's (headers) as documentation.
Gordon Henriksena8c36602007-09-20 16:47:41 +0000182install-cmis: $(OutputsCMI) $(OcamlHeaders)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000183 $(Verb) $(MKDIR) $(PROJ_libocamldir)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000184 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000185 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
186 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
187 done
Gordon Henriksena8c36602007-09-20 16:47:41 +0000188 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000189 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
Gordon Henriksena8c36602007-09-20 16:47:41 +0000190 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000191 done
192
193uninstall-cmis::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000194 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000195 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
196 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
197 done
Gordon Henriksena8c36602007-09-20 16:47:41 +0000198 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000199 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
200 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
201 done
202
203
204##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
205
Gordon Henriksena8c36602007-09-20 16:47:41 +0000206all-local:: $(OutputCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000207clean-local:: clean-cma
208install-local:: install-cma
209uninstall-local:: uninstall-cma
210
Gordon Henriksena8c36602007-09-20 16:47:41 +0000211$(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
212 $(Verb) $(CP) -f $< $@
213
Gordon Henriksen0908d492007-09-18 12:26:17 +0000214$(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
215 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
216 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000217
Gordon Henriksena8c36602007-09-20 16:47:41 +0000218$(ObjDir)/%.cmo: $(ObjDir)/%.ml
Gordon Henriksen0908d492007-09-18 12:26:17 +0000219 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
220 $(Verb) $(Compile.CMO) $@ $<
221
222clean-cma::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000223 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000224
Gordon Henriksena8c36602007-09-20 16:47:41 +0000225install-cma:: $(OutputCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000226 $(Echo) "Installing $(BuildMode) $(DestCMA)"
227 $(Verb) $(MKDIR) $(PROJ_libocamldir)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000228 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
Gordon Henriksen0908d492007-09-18 12:26:17 +0000229
230uninstall-cma::
231 $(Echo) "Uninstalling $(DestCMA)"
232 -$(Verb) $(RM) -f $(DestCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000233
234
235##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
236
237# The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
238# If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
239ifdef OCAMLOPT
240
Gordon Henriksena8c36602007-09-20 16:47:41 +0000241all-local:: $(OutputCMXA) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000242clean-local:: clean-cmxa
243install-local:: install-cmxa
244uninstall-local:: uninstall-cmxa
245
Gordon Henriksena8c36602007-09-20 16:47:41 +0000246$(OutputCMXA): $(LibraryCMXA)
247 $(Verb) $(CP) -f $< $@
248 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
249
250$(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
251 $(Verb) $(CP) -f $< $@
252
Gordon Henriksen0908d492007-09-18 12:26:17 +0000253$(LibraryCMXA): $(ObjectsCMX)
254 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
255 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
256 $(Verb) $(RM) -f $(@:.cmxa=.o)
257
Gordon Henriksena8c36602007-09-20 16:47:41 +0000258$(ObjDir)/%.cmx: $(ObjDir)/%.ml
Gordon Henriksen0908d492007-09-18 12:26:17 +0000259 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
260 $(Verb) $(Compile.CMX) $@ $<
261
262clean-cmxa::
Gordon Henriksen4b169cd2008-03-07 18:43:51 +0000263 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.a) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000264
Gordon Henriksena8c36602007-09-20 16:47:41 +0000265install-cmxa:: $(OutputCMXA) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000266 $(Verb) $(MKDIR) $(PROJ_libocamldir)
267 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
Gordon Henriksena8c36602007-09-20 16:47:41 +0000268 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000269 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
Gordon Henriksena8c36602007-09-20 16:47:41 +0000270 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
271 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000272 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
273 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
274 done
275
Gordon Henriksena8c36602007-09-20 16:47:41 +0000276uninstall-cmxa::
Gordon Henriksen0908d492007-09-18 12:26:17 +0000277 $(Echo) "Uninstalling $(DestCMXA)"
278 $(Verb) $(RM) -f $(DestCMXA)
279 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
280 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000281 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000282 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
283 $(RM) -f $(PROJ_libocamldir)/$$i; \
284 done
285
286endif
287
288
289##===- Debugging gunk -----------------------------------------------------===##
290printvars:: printcamlvars
291
292printcamlvars::
293 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
294 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
295 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
296 $(Echo) "OCAMLC : " '$(OCAMLC)'
297 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000298 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000299 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
300 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
301 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
302 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
303 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
304 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
305 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
306 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000307 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000308 $(Echo) "OcamlSources : " '$(OcamlSources)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000309 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000310 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
311 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
312 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
313 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
314 $(Echo) "DestA : " '$(DestA)'
315 $(Echo) "DestCMA : " '$(DestCMA)'
316 $(Echo) "DestCMXA : " '$(DestCMXA)'
317 $(Echo) "UsedLibs : " '$(UsedLibs)'
318 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
319
320.PHONY: printcamlvars build-cmis \
321 clean-a clean-cmis clean-cma clean-cmxa \
322 install-a install-cmis install-cma install-cmxa \
323 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa