Fix the implementation of ConstantRange::sub(ConstantRange). Patch by Xi Wang!
[llvm/stm8.git] / bindings / ocaml / Makefile.ocaml
blob40ecc9c08e0912f50647f935b9b25d84958da1f7
1 ##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===##
2 #
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # 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.
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 CXX.Flags += -I"$(shell $(OCAMLC) -where)"
24 C.Flags += -I"$(shell $(OCAMLC) -where)"
26 include $(LEVEL)/Makefile.common
28 # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
29 # user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
30 PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
31 OcamlDir := $(LibDir)/ocaml
33 # Info from llvm-config and similar
34 ifndef IS_CLEANING_TARGET
35 ifdef UsedComponents
36 UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
37 UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
38 endif
39 endif
41 # Tools
42 OCAMLCFLAGS += -I $(ObjDir) -I $(OcamlDir)
43 ifndef IS_CLEANING_TARGET
44 ifneq ($(ObjectsO),)
45 OCAMLAFLAGS += $(patsubst %,-cclib %, \
46 $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \
47 $(shell $(LLVM_CONFIG) --ldflags)) \
48 $(UsedLibs))
49 else
50 OCAMLAFLAGS += $(patsubst %,-cclib %, \
51 $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
52 $(UsedLibs))
53 endif
54 endif
56 # -g was introduced in 3.10.0.
57 #ifneq ($(ENABLE_OPTIMIZED),1)
58 # OCAMLDEBUGFLAG := -g
59 #endif
61 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
62 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
63 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
64 -o)
66 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
67 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
69 ifdef OCAMLOPT
70 Archive.EXE := $(strip $(OCAMLOPT) -cc $(CXX) $(OCAMLCFLAGS) $(UsedOcamLibs:%=%.cmxa) $(OCAMLDEBUGFLAG) -o)
71 else
72 Archive.EXE := $(strip $(OCAMLC) -cc $(CXX) $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG:%=%.cma) -o)
73 endif
75 # Source files
76 ifndef OcamlSources1
77 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
78 endif
80 ifndef OcamlHeaders1
81 OcamlHeaders1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.mli))
82 endif
84 OcamlSources2 := $(filter-out $(ExcludeSources),$(OcamlSources1))
85 OcamlHeaders2 := $(filter-out $(ExcludeHeaders),$(OcamlHeaders1))
87 OcamlSources := $(OcamlSources2:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
88 OcamlHeaders := $(OcamlHeaders2:$(PROJ_SRC_DIR)/%=$(ObjDir)/%)
90 # Intermediate files
91 ObjectsCMI := $(OcamlSources:%.ml=%.cmi)
92 ObjectsCMO := $(OcamlSources:%.ml=%.cmo)
93 ObjectsCMX := $(OcamlSources:%.ml=%.cmx)
95 ifdef LIBRARYNAME
96 LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma
97 LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa
98 endif
100 ifdef TOOLNAME
101 ToolEXE := $(ObjDir)/$(TOOLNAME)$(EXEEXT)
102 endif
104 # Output files
105 # The .cmo files are the only intermediates; all others are to be installed.
106 OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
107 OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
108 OutputLibs := $(UsedLibNames:%=$(OcamlDir)/%)
110 ifdef LIBRARYNAME
111 LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a
112 OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma)
113 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
114 endif
116 ifdef TOOLNAME
117 ifdef EXAMPLE_TOOL
118 OutputEXE := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
119 else
120 OutputEXE := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
121 endif
122 endif
124 # Installation targets
125 DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%)
127 ifdef LIBRARYNAME
128 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
129 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
130 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
131 endif
133 ##===- Dependencies -------------------------------------------------------===##
134 # Copy the sources into the intermediate directory because older ocamlc doesn't
135 # support -o except when linking (outputs are placed next to inputs).
137 $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir
138 $(Verb) $(CP) -f $< $@
140 $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir
141 $(Verb) $(CP) -f $< $@
143 $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
145 ifdef LIBRARYNAME
146 $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
147 $(OcamlDir)/.dir $(ObjDir)/.dir
148 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@
150 -include $(ObjDir)/$(LIBRARYNAME).ocamldep
151 endif
153 ifdef TOOLNAME
154 $(ObjDir)/$(TOOLNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
155 $(OcamlDir)/.dir $(ObjDir)/.dir
156 $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@
158 -include $(ObjDir)/$(TOOLNAME).ocamldep
159 endif
161 ##===- Build static library from C sources --------------------------------===##
163 ifdef LibraryA
164 all-local:: $(LibraryA)
165 clean-local:: clean-a
166 install-local:: install-a
167 uninstall-local:: uninstall-a
169 $(LibraryA): $(ObjectsO) $(OcamlDir)/.dir
170 $(Echo) "Building $(BuildMode) $(notdir $@)"
171 -$(Verb) $(RM) -f $@
172 $(Verb) $(Archive) $@ $(ObjectsO)
173 $(Verb) $(Ranlib) $@
175 clean-a::
176 -$(Verb) $(RM) -f $(LibraryA)
178 install-a:: $(LibraryA)
179 $(Echo) "Installing $(BuildMode) $(DestA)"
180 $(Verb) $(MKDIR) $(PROJ_libocamldir)
181 $(Verb) $(INSTALL) $(LibraryA) $(DestA)
182 $(Verb)
184 uninstall-a::
185 $(Echo) "Uninstalling $(DestA)"
186 -$(Verb) $(RM) -f $(DestA)
187 endif
190 ##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===##
192 all-local:: build-deplibs
193 clean-local:: clean-deplibs
194 install-local:: install-deplibs
195 uninstall-local:: uninstall-deplibs
197 build-deplibs: $(OutputLibs)
199 $(OcamlDir)/%.a: $(LibDir)/%.a
200 $(Verb) ln -sf $< $@
202 $(OcamlDir)/%.o: $(LibDir)/%.o
203 $(Verb) ln -sf $< $@
205 clean-deplibs:
206 $(Verb) $(RM) -f $(OutputLibs)
208 install-deplibs:
209 $(Verb) $(MKDIR) $(PROJ_libocamldir)
210 $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \
211 ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
212 done
214 uninstall-deplibs:
215 $(Verb) $(RM) -f $(DestLibs)
218 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
220 ifneq ($(OcamlHeaders),)
221 all-local:: build-cmis
222 clean-local:: clean-cmis
223 install-local:: install-cmis
224 uninstall-local:: uninstall-cmis
226 build-cmis: $(OutputsCMI)
228 $(OcamlDir)/%.cmi: $(ObjDir)/%.cmi $(OcamlDir)/.dir
229 $(Verb) $(CP) -f $< $@
231 $(ObjDir)/%.cmi: $(ObjDir)/%.mli $(ObjDir)/.dir
232 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
233 $(Verb) $(Compile.CMI) $@ $<
235 clean-cmis::
236 -$(Verb) $(RM) -f $(OutputsCMI)
238 # Also install the .mli's (headers) as documentation.
239 install-cmis: $(OutputsCMI) $(OcamlHeaders)
240 $(Verb) $(MKDIR) $(PROJ_libocamldir)
241 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
242 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
243 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
244 done
245 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
246 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
247 $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \
248 done
250 uninstall-cmis::
251 $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \
252 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
253 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
254 done
255 $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \
256 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
257 $(RM) -f "$(PROJ_libocamldir)/$$i"; \
258 done
259 endif
262 ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===##
264 $(ObjDir)/%.cmo: $(ObjDir)/%.ml
265 $(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
266 $(Verb) $(Compile.CMO) $@ $<
268 ifdef LIBRARYNAME
269 all-local:: $(OutputCMA)
270 clean-local:: clean-cma
271 install-local:: install-cma
272 uninstall-local:: uninstall-cma
274 $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir
275 $(Verb) $(CP) -f $< $@
277 $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
278 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
279 $(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
281 clean-cma::
282 $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%)
284 install-cma:: $(OutputCMA)
285 $(Echo) "Installing $(BuildMode) $(DestCMA)"
286 $(Verb) $(MKDIR) $(PROJ_libocamldir)
287 $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
289 uninstall-cma::
290 $(Echo) "Uninstalling $(DestCMA)"
291 -$(Verb) $(RM) -f $(DestCMA)
292 endif
294 ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##
296 # The ocamlopt compiler is supported on a set of targets disjoint from LLVM's.
297 # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config.
298 ifdef OCAMLOPT
300 $(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
301 $(Verb) $(CP) -f $< $@
303 $(ObjDir)/%.cmx: $(ObjDir)/%.ml
304 $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build"
305 $(Verb) $(Compile.CMX) $@ $<
307 ifdef LIBRARYNAME
308 all-local:: $(OutputCMXA) $(OutputsCMX)
309 clean-local:: clean-cmxa
310 install-local:: install-cmxa
311 uninstall-local:: uninstall-cmxa
313 $(OutputCMXA): $(LibraryCMXA)
314 $(Verb) $(CP) -f $< $@
315 $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a)
317 $(LibraryCMXA): $(ObjectsCMX)
318 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
319 $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX)
320 $(Verb) $(RM) -f $(@:.cmxa=.o)
322 clean-cmxa::
323 $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.a) $(OutputsCMX)
325 install-cmxa:: $(OutputCMXA) $(OutputsCMX)
326 $(Verb) $(MKDIR) $(PROJ_libocamldir)
327 $(Echo) "Installing $(BuildMode) $(DestCMXA)"
328 $(Verb) $(DataInstall) $(OutputCMXA) $(DestCMXA)
329 $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)"
330 $(Verb) $(DataInstall) $(OutputCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a)
331 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
332 $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
333 $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \
334 done
336 uninstall-cmxa::
337 $(Echo) "Uninstalling $(DestCMXA)"
338 $(Verb) $(RM) -f $(DestCMXA)
339 $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)"
340 $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a)
341 $(Verb) for i in $(OutputsCMX:$(OcamlDir)/%=%); do \
342 $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
343 $(RM) -f $(PROJ_libocamldir)/$$i; \
344 done
345 endif
346 endif
348 ##===- Build executables --------------------------------------------------===##
350 ifdef TOOLNAME
351 all-local:: $(OutputEXE)
352 clean-local:: clean-exe
354 $(OutputEXE): $(ToolEXE) $(OcamlDir)/.dir
355 $(Verb) $(CP) -f $< $@
357 ifndef OCAMLOPT
358 $(ToolEXE): $(ObjectsCMO) $(OcamlDir)/.dir
359 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
360 $(Verb) $(Archive.EXE) $@ $(ObjectsCMO)
361 else
362 $(ToolEXE): $(ObjectsCMX) $(OcamlDir)/.dir
363 $(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
364 $(Verb) $(Archive.EXE) $@ $(ObjectsCMX)
365 endif
366 endif
368 ##===- Generate documentation ---------------------------------------------===##
370 $(ObjDir)/$(LIBRARYNAME).odoc: $(ObjectsCMI)
371 $(Echo) "Documenting $(notdir $@)"
372 $(Verb) $(OCAMLDOC) -I $(ObjDir) -I $(OcamlDir) -dump $@ $(OcamlHeaders)
374 ocamldoc: $(ObjDir)/$(LIBRARYNAME).odoc
376 ##===- Debugging gunk -----------------------------------------------------===##
377 printvars:: printcamlvars
379 printcamlvars::
380 $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
381 $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
382 $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
383 $(Echo) "OCAMLC : " '$(OCAMLC)'
384 $(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
385 $(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
386 $(Echo) "Compile.CMI : " '$(Compile.CMI)'
387 $(Echo) "Compile.CMO : " '$(Compile.CMO)'
388 $(Echo) "Archive.CMA : " '$(Archive.CMA)'
389 $(Echo) "Compile.CMX : " '$(Compile.CMX)'
390 $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
391 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
392 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
393 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
394 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
395 $(Echo) "OcamlSources2: " '$(OcamlSources2)'
396 $(Echo) "OcamlSources : " '$(OcamlSources)'
397 $(Echo) "OcamlHeaders1: " '$(OcamlHeaders1)'
398 $(Echo) "OcamlHeaders2: " '$(OcamlHeaders2)'
399 $(Echo) "OcamlHeaders : " '$(OcamlHeaders)'
400 $(Echo) "ObjectsCMI : " '$(ObjectsCMI)'
401 $(Echo) "ObjectsCMO : " '$(ObjectsCMO)'
402 $(Echo) "ObjectsCMX : " '$(ObjectsCMX)'
403 $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)'
404 $(Echo) "DestA : " '$(DestA)'
405 $(Echo) "DestCMA : " '$(DestCMA)'
406 $(Echo) "DestCMXA : " '$(DestCMXA)'
407 $(Echo) "UsedLibs : " '$(UsedLibs)'
408 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
410 .PHONY: printcamlvars build-cmis \
411 clean-a clean-cmis clean-cma clean-cmxa \
412 install-a install-cmis install-cma install-cmxa \
413 install-exe \
414 uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa \
415 uninstall-exe