blob: b157c3194eb64d0a4f81b0d2e60fb900453c0632 [file] [log] [blame]
Gordon Henriksen0908d492007-09-18 12:26:17 +00001##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===##
2#
3# The LLVM Compiler Infrastructure
4#
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.
7#
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#
13##===----------------------------------------------------------------------===##
14
15include $(LEVEL)/Makefile.config
16
Gordon Henriksen0908d492007-09-18 12:26:17 +000017# CFLAGS needs to be set before Makefile.rules is included. Yes, ocaml puts its
18# includes under its libdir.
19CFLAGS += -I$(OCAML_LIBDIR)
20
21include $(LEVEL)/Makefile.common
22
23# Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
Gordon Henriksen1d4e0782007-10-02 16:42:10 +000024# user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
Gordon Henriksen0908d492007-09-18 12:26:17 +000025PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
26OcamlDir := $(LibDir)/ocaml
27
28# Info from llvm-config and similar
29ifdef UsedComponents
30UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
31UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
32endif
33
34# Tools
Gordon Henriksena8c36602007-09-20 16:47:41 +000035OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
Gordon Henriksen0908d492007-09-18 12:26:17 +000036OCAMLAFLAGS += $(patsubst %,-cclib %, \
37 $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
38 $(UsedLibs) -l$(LIBRARYNAME))
39
40Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
41Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
42Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
43
44Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
45Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
46
47# Source files
Gordon Henriksena8c36602007-09-20 16:47:41 +000048OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
49OcamlHeaders1 := $(OcamlSources1:.ml=.mli)
Gordon Henriksen0908d492007-09-18 12:26:17 +000050
Gordon Henriksena8c36602007-09-20 16:47:41 +000051OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
52OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +000053
Gordon Henriksena8c36602007-09-20 16:47:41 +000054# Intermediate files
55LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
56LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
57ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
58ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
59ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
60
61# Output files
62# The .cmo files are the only intermediates; all others are to be installed.
63LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
64OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
65OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
66OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
67OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
Gordon Henriksen0908d492007-09-18 12:26:17 +000068
69# Installation targets
70DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
71DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
72DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
73
74
Gordon Henriksena8c36602007-09-20 16:47:41 +000075##===- Dependencies -------------------------------------------------------===##
76# Copy the sources into the intermediate directory because older ocamlc doesn't
77# support -o except when linking (outputs are placed next to inputs).
78
79$(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
80 $(Verb) $(CP) -f $< $@
81
82$(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
83 $(Verb) $(CP) -f $< $@
84
Gordon Henriksenab4456f2007-09-23 13:37:44 +000085$(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
86 $(OcamlDir)/.dir $(ObjDir)/.dir
Gordon Henriksena8c36602007-09-20 16:47:41 +000087 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@
88
Gordon Henriksen46abf912007-09-26 20:56:12 +000089$(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
90
Gordon Henriksena8c36602007-09-20 16:47:41 +000091-include $(ObjDir)/$(LIBRARYNAME).ocamldep
92
93
Gordon Henriksen0908d492007-09-18 12:26:17 +000094##===- Build static library from C sources --------------------------------===##
95
96all-local:: $(LibraryA)
97clean-local:: clean-a
98install-local:: install-a
99uninstall-local:: uninstall-a
100
101$(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
102 $(Echo) "Building $(BuildMode) $(notdir $@)"
103 -$(Verb) $(RM) -f $@
104 $(Verb) $(Archive) $@ $(ObjectsO)
105 $(Verb) $(Ranlib) $@
106
107clean-a::
108 -$(Verb) $(RM) -f $(LibraryA)
109
110install-a:: $(LibraryA)
111 $(Echo) "Installing $(BuildMode) $(DestA)"
112 $(Verb) $(MKDIR) $(PROJ_libocamldir)
113 $(Verb) $(LTInstall) $(LibraryA) $(DestA)
114 $(Verb)
115
116uninstall-a::
117 $(Echo) "Uninstalling $(DestA)"
118 -$(Verb) $(RM) -f $(DestA)
119
120
121##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
122
123all-local:: build-cmis
124clean-local:: clean-cmis
125install-local:: install-cmis
126uninstall-local:: uninstall-cmis
127
Gordon Henriksena8c36602007-09-20 16:47:41 +0000128build-cmis: $(OutputsCMI)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000129
Gordon Henriksena8c36602007-09-20 16:47:41 +0000130$(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
131 $(Verb) $(CP) -f $< $@
132
133$(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
Gordon Henriksen0908d492007-09-18 12:26:17 +0000134 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
135 $(Verb) $(Compile.CMI) $@ $<
136
137clean-cmis::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000138 -$(Verb) $(RM) -f $(OutputsCMI)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000139
140# Also install the .mli's (headers) as documentation.
Gordon Henriksena8c36602007-09-20 16:47:41 +0000141install-cmis: $(OutputsCMI) $(OcamlHeaders)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000142 $(Verb) $(MKDIR) $(PROJ_libocamldir)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000143 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000144 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
145 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
146 done
Gordon Henriksena8c36602007-09-20 16:47:41 +0000147 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000148 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
Gordon Henriksena8c36602007-09-20 16:47:41 +0000149 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000150 done
151
152uninstall-cmis::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000153 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000154 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
155 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
156 done
Gordon Henriksena8c36602007-09-20 16:47:41 +0000157 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000158 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
159 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
160 done
161
162
163##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
164
Gordon Henriksena8c36602007-09-20 16:47:41 +0000165all-local:: $(OutputCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000166clean-local:: clean-cma
167install-local:: install-cma
168uninstall-local:: uninstall-cma
169
Gordon Henriksena8c36602007-09-20 16:47:41 +0000170$(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
171 $(Verb) $(CP) -f $< $@
172
Gordon Henriksen0908d492007-09-18 12:26:17 +0000173$(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
174 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
175 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
176 $(Verb) for i in $(UsedLibNames); do \
177 ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
178 done
179
Gordon Henriksena8c36602007-09-20 16:47:41 +0000180$(ObjDir)/%.cmo: $(ObjDir)/%.ml
Gordon Henriksen0908d492007-09-18 12:26:17 +0000181 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
182 $(Verb) $(Compile.CMO) $@ $<
183
184clean-cma::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000185 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000186
Gordon Henriksena8c36602007-09-20 16:47:41 +0000187install-cma:: $(OutputCMA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000188 $(Echo) "Installing $(BuildMode) $(DestCMA)"
189 $(Verb) $(MKDIR) $(PROJ_libocamldir)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000190 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
Gordon Henriksen0908d492007-09-18 12:26:17 +0000191 $(Verb) for i in $(UsedLibNames); do \
192 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
193 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
194 done
195
196uninstall-cma::
197 $(Echo) "Uninstalling $(DestCMA)"
198 -$(Verb) $(RM) -f $(DestCMA)
199 $(Verb) for i in $(UsedLibNames); do \
200 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
201 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
202 done
203
204
205##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
206
207# The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
208# If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
209ifdef OCAMLOPT
210
Gordon Henriksena8c36602007-09-20 16:47:41 +0000211all-local:: $(OutputCMXA) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000212clean-local:: clean-cmxa
213install-local:: install-cmxa
214uninstall-local:: uninstall-cmxa
215
Gordon Henriksena8c36602007-09-20 16:47:41 +0000216$(OutputCMXA): $(LibraryCMXA)
217 $(Verb) $(CP) -f $< $@
218 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
219
220$(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
221 $(Verb) $(CP) -f $< $@
222
Gordon Henriksen0908d492007-09-18 12:26:17 +0000223$(LibraryCMXA): $(ObjectsCMX)
224 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
225 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
226 $(Verb) $(RM) -f $(@:.cmxa=.o)
227
Gordon Henriksena8c36602007-09-20 16:47:41 +0000228$(ObjDir)/%.cmx: $(ObjDir)/%.ml
Gordon Henriksen0908d492007-09-18 12:26:17 +0000229 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
230 $(Verb) $(Compile.CMX) $@ $<
231
232clean-cmxa::
Gordon Henriksena8c36602007-09-20 16:47:41 +0000233 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000234
Gordon Henriksena8c36602007-09-20 16:47:41 +0000235install-cmxa:: $(OutputCMXA) $(OutputsCMX)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000236 $(Verb) $(MKDIR) $(PROJ_libocamldir)
237 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
Gordon Henriksena8c36602007-09-20 16:47:41 +0000238 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
Gordon Henriksen0908d492007-09-18 12:26:17 +0000239 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
Gordon Henriksena8c36602007-09-20 16:47:41 +0000240 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
241 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000242 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
243 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
244 done
245
Gordon Henriksena8c36602007-09-20 16:47:41 +0000246uninstall-cmxa::
Gordon Henriksen0908d492007-09-18 12:26:17 +0000247 $(Echo) "Uninstalling $(DestCMXA)"
248 $(Verb) $(RM) -f $(DestCMXA)
249 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
250 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
Gordon Henriksena8c36602007-09-20 16:47:41 +0000251 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
Gordon Henriksen0908d492007-09-18 12:26:17 +0000252 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
253 $(RM) -f $(PROJ_libocamldir)/$$i; \
254 done
255
256endif
257
258
259##===- Debugging gunk -----------------------------------------------------===##
260printvars:: printcamlvars
261
262printcamlvars::
263 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
264 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
265 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
266 $(Echo) "OCAMLC : " '$(OCAMLC)'
267 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000268 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000269 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
270 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
271 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
272 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
273 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
274 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
275 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
276 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000277 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000278 $(Echo) "OcamlSources : " '$(OcamlSources)'
Gordon Henriksena8c36602007-09-20 16:47:41 +0000279 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
Gordon Henriksen0908d492007-09-18 12:26:17 +0000280 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
281 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
282 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
283 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
284 $(Echo) "DestA : " '$(DestA)'
285 $(Echo) "DestCMA : " '$(DestCMA)'
286 $(Echo) "DestCMXA : " '$(DestCMXA)'
287 $(Echo) "UsedLibs : " '$(UsedLibs)'
288 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
289
290.PHONY: printcamlvars build-cmis \
291 clean-a clean-cmis clean-cma clean-cmxa \
292 install-a install-cmis install-cma install-cmxa \
293 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa