blob: 0093eb28cf6d7928e5dd46564ac3d492813c843a [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.
23CFLAGS += -I$(shell $(OCAMLC) -where)
Gordon Henriksen0908d492007-09-18 12:26:17 +000024
25include $(LEVEL)/Makefile.common
26
27# Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
Gordon Henriksen1d4e0782007-10-02 16:42:10 +000028# user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
Gordon Henriksen0908d492007-09-18 12:26:17 +000029PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
30OcamlDir := $(LibDir)/ocaml
31
32# Info from llvm-config and similar
33ifdef UsedComponents
34UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
35UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
36endif
37
38# Tools
Gordon Henriksena8c36602007-09-20 16:47:41 +000039OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
Gordon Henriksen0908d492007-09-18 12:26:17 +000040OCAMLAFLAGS += $(patsubst %,-cclib %, \
Gordon Henriksened29a282007-10-12 19:48:13 +000041 $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \
42 $(shell $(LLVM_CONFIG) --ldflags)) \
43 $(UsedLibs))
Gordon Henriksen2e855e62007-12-23 16:59:28 +000044
Gordon Henriksen4e20a092007-12-25 08:37:43 +000045# -g was introduced in 3.10.0.
46#ifneq ($(ENABLE_OPTIMIZED),1)
47# OCAMLDEBUGFLAG := -g
48#endif
Gordon Henriksen0908d492007-09-18 12:26:17 +000049
Gordon Henriksen2e855e62007-12-23 16:59:28 +000050Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
51Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
52Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
53 -o)
Gordon Henriksen0908d492007-09-18 12:26:17 +000054
Gordon Henriksen2e855e62007-12-23 16:59:28 +000055Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
56Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
Gordon Henriksen0908d492007-09-18 12:26:17 +000057
58# Source files
Gordon Henriksena8c36602007-09-20 16:47:41 +000059OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
60OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
Gordon Henriksen0908d492007-09-18 12:26:17 +000061
Gordon Henriksena8c36602007-09-20 16:47:41 +000062OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
63OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000064
Gordon Henriksena8c36602007-09-20 16:47:41 +000065# Intermediate files
66LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
67LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
68ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
69ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
70ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
71
72# Output files
73# The .cmo files are the only intermediates; all others are to be installed.
74LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
75OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
76OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
77OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
78OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
Gordon Henriksen516276e2007-12-03 21:15:53 +000079OutputLibs := $(UsedLibNames:%=$(OcamlDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000080
81# Installation targets
82DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
83DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
84DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
Gordon Henriksen516276e2007-12-03 21:15:53 +000085DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000086
87
Gordon Henriksena8c36602007-09-20 16:47:41 +000088##===- 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).
91
92$(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
93 $(Verb) $(CP) -f $< $@
94
95$(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
96 $(Verb) $(CP) -f $< $@
97
Gordon Henriksenab4456f2007-09-23 13:37:44 +000098$(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
99 $(OcamlDir)/.dir $(ObjDir)/.dir
Gordon Henriksena8c36602007-09-20 16:47:41 +0000100 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
101
Gordon Henriksen46abf912007-09-26 20:56:12 +0000102$(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
103
Gordon Henriksena8c36602007-09-20 16:47:41 +0000104-include $(ObjDir)/$(LIBRARYNAME).ocamldep
105
106
Gordon Henriksen0908d492007-09-18 12:26:17 +0000107##===- Build static library from C sources --------------------------------===##
108
109all-local:: $(LibraryA)
110clean-local:: clean-a
111install-local:: install-a
112uninstall-local:: uninstall-a
113
114$(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
115 $(Echo) "Building $(BuildMode) $(notdir $@)"
116 -$(Verb) $(RM) -f $@
117 $(Verb) $(Archive) $@ $(ObjectsO)
118 $(Verb) $(Ranlib) $@
119
120clean-a::
121 -$(Verb) $(RM) -f $(LibraryA)
122
123install-a:: $(LibraryA)
124 $(Echo) "Installing $(BuildMode) $(DestA)"
125 $(Verb) $(MKDIR) $(PROJ_libocamldir)
126 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
127 $(Verb)
128
129uninstall-a::
130 $(Echo) "Uninstalling $(DestA)"
131 -$(Verb) $(RM) -f $(DestA)
132
133
Gordon Henriksen516276e2007-12-03 21:15:53 +0000134##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===##
135
136all-local:: build-deplibs
137clean-local:: clean-deplibs
138install-local:: install-deplibs
139uninstall-local:: uninstall-deplibs
140
141build-deplibs: $(OutputLibs)
142
143$(OcamlDir)/%.a: $(LibDir)/%.a
144 $(Verb) ln -sf $< $@
145
Gordon Henriksen2e855e62007-12-23 16:59:28 +0000146$(OcamlDir)/%.o: $(LibDir)/%.o
147 $(Verb) ln -sf $< $@
148
Gordon Henriksen516276e2007-12-03 21:15:53 +0000149clean-deplibs:
150 $(Verb) rm -f $(OutputLibs)
151
152install-deplibs:
153 $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \
154 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
155 done
156
157uninstall-deplibs:
158 $(Verb) rm -f $(DestLibs)
159
160
Gordon Henriksen0908d492007-09-18 12:26:17 +0000161##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
162
163all-local:: build-cmis
164clean-local:: clean-cmis
165install-local:: install-cmis
166uninstall-local:: uninstall-cmis
167
Gordon Henriksena8c36602007-09-20 16:47:41 +0000168build-cmis: $(OutputsCMI)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000169
Gordon Henriksena8c36602007-09-20 16:47:41 +0000170$(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
171 $(Verb) $(CP) -f $< $@
172
173$(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
Gordon Henriksen0908d492007-09-18 12:26:17 +0000174 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
175 $(Verb) $(Compile.CMI) $@ $<
176
177clean-cmis::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000178 -$(Verb) $(RM) -f $(OutputsCMI)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000179
180# Also install the .mli's (headers) as documentation.
Gordon Henriksena8c36602007-09-20 16:47:41 +0000181install-cmis: $(OutputsCMI) $(OcamlHeaders)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000182 $(Verb) $(MKDIR) $(PROJ_libocamldir)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000183 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000184 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
185 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
186 done
Gordon Henriksena8c36602007-09-20 16:47:41 +0000187 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000188 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
Gordon Henriksena8c36602007-09-20 16:47:41 +0000189 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000190 done
191
192uninstall-cmis::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000193 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000194 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
195 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
196 done
Gordon Henriksena8c36602007-09-20 16:47:41 +0000197 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000198 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
199 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
200 done
201
202
203##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
204
Gordon Henriksena8c36602007-09-20 16:47:41 +0000205all-local:: $(OutputCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000206clean-local:: clean-cma
207install-local:: install-cma
208uninstall-local:: uninstall-cma
209
Gordon Henriksena8c36602007-09-20 16:47:41 +0000210$(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
211 $(Verb) $(CP) -f $< $@
212
Gordon Henriksen0908d492007-09-18 12:26:17 +0000213$(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
214 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
215 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000216
Gordon Henriksena8c36602007-09-20 16:47:41 +0000217$(ObjDir)/%.cmo: $(ObjDir)/%.ml
Gordon Henriksen0908d492007-09-18 12:26:17 +0000218 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
219 $(Verb) $(Compile.CMO) $@ $<
220
221clean-cma::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000222 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000223
Gordon Henriksena8c36602007-09-20 16:47:41 +0000224install-cma:: $(OutputCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000225 $(Echo) "Installing $(BuildMode) $(DestCMA)"
226 $(Verb) $(MKDIR) $(PROJ_libocamldir)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000227 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
Gordon Henriksen0908d492007-09-18 12:26:17 +0000228
229uninstall-cma::
230 $(Echo) "Uninstalling $(DestCMA)"
231 -$(Verb) $(RM) -f $(DestCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000232
233
234##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
235
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.
238ifdef OCAMLOPT
239
Gordon Henriksena8c36602007-09-20 16:47:41 +0000240all-local:: $(OutputCMXA) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000241clean-local:: clean-cmxa
242install-local:: install-cmxa
243uninstall-local:: uninstall-cmxa
244
Gordon Henriksena8c36602007-09-20 16:47:41 +0000245$(OutputCMXA): $(LibraryCMXA)
246 $(Verb) $(CP) -f $< $@
247 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
248
249$(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
250 $(Verb) $(CP) -f $< $@
251
Gordon Henriksen0908d492007-09-18 12:26:17 +0000252$(LibraryCMXA): $(ObjectsCMX)
253 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
254 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
255 $(Verb) $(RM) -f $(@:.cmxa=.o)
256
Gordon Henriksena8c36602007-09-20 16:47:41 +0000257$(ObjDir)/%.cmx: $(ObjDir)/%.ml
Gordon Henriksen0908d492007-09-18 12:26:17 +0000258 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
259 $(Verb) $(Compile.CMX) $@ $<
260
261clean-cmxa::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000262 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000263
Gordon Henriksena8c36602007-09-20 16:47:41 +0000264install-cmxa:: $(OutputCMXA) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000265 $(Verb) $(MKDIR) $(PROJ_libocamldir)
266 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
Gordon Henriksena8c36602007-09-20 16:47:41 +0000267 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000268 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
Gordon Henriksena8c36602007-09-20 16:47:41 +0000269 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
270 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000271 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
272 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
273 done
274
Gordon Henriksena8c36602007-09-20 16:47:41 +0000275uninstall-cmxa::
Gordon Henriksen0908d492007-09-18 12:26:17 +0000276 $(Echo) "Uninstalling $(DestCMXA)"
277 $(Verb) $(RM) -f $(DestCMXA)
278 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
279 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000280 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000281 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
282 $(RM) -f $(PROJ_libocamldir)/$$i; \
283 done
284
285endif
286
287
288##===- Debugging gunk -----------------------------------------------------===##
289printvars:: printcamlvars
290
291printcamlvars::
292 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
293 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
294 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
295 $(Echo) "OCAMLC : " '$(OCAMLC)'
296 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000297 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000298 $(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)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000306 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000307 $(Echo) "OcamlSources : " '$(OcamlSources)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000308 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000309 $(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)'
318
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