llvm.org GIT mirror llvm / 1ba15ab
[OCaml] Dynamically link LLVM on --enable-shared builds This commit significantly speeds up both bytecode and native builds of LLVM clients (from ~20 second to sub-second link time), and allows to invoke LLVM functions from OCaml toplevel. The behavior for --disable-shared builds is unchanged. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194509 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Zotov 7 years ago
2 changed file(s) with 69 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2121 # CFLAGS needs to be set before Makefile.rules is included.
2222 CXX.Flags += -I"$(shell $(OCAMLC) -where)"
2323 C.Flags += -I"$(shell $(OCAMLC) -where)"
24
25 ifeq ($(ENABLE_SHARED),1)
26 LINK_COMPONENTS := all
27 endif
2428
2529 include $(LEVEL)/Makefile.common
2630
3438 ifdef UsedComponents
3539 UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))
3640 UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))
41 endif
42 endif
43
44 # How do we link OCaml executables with LLVM?
45 # 1) If this is a --enable-shared build, build stub libraries. This also allows
46 # to use LLVM from toplevels.
47 # 2) If this is a --disable-shared build, embed ocamlc options for building
48 # a custom runtime and a static executable. It is not possible to use LLVM
49 # from toplevels.
50 ifneq ($(ObjectsO),)
51 ifeq ($(ENABLE_SHARED),1)
52 OCAMLSTUBS := 1
3753 endif
3854 endif
3955
5975
6076 Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
6177 Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
78 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
79
80 ifdef OCAMLSTUBS
81 Archive.CMA := $(strip $(OCAMLC) -a -dllib -l$(LIBRARYNAME) $(OCAMLDEBUGFLAG) \
82 -o)
83 else
6284 Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
6385 -o)
64
65 Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
86 endif
87
88 ifdef OCAMLSTUBS
89 Archive.CMXA := $(strip $(OCAMLOPT) -a $(patsubst %,-cclib %, \
90 $(LLVMLibsOptions) -l$(LIBRARYNAME)) \
91 $(OCAMLDEBUGFLAG) -o)
92 else
6693 Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
94 endif
6795
6896 ifdef OCAMLOPT
6997 Archive.EXE := $(strip $(OCAMLOPT) -cc $(CXX) $(OCAMLCFLAGS) $(UsedOcamlLibs:%=%.cmxa) $(OCAMLDEBUGFLAG) -o)
112140 OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
113141 endif
114142
143 ifdef OCAMLSTUBS
144 SharedLib := $(OcamlDir)/dll$(LIBRARYNAME).$(SHLIBEXT)
145 endif
146
115147 ifdef TOOLNAME
116148 ifdef EXAMPLE_TOOL
117149 OutputEXE := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
127159 DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
128160 DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
129161 DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
162 endif
163
164 ifdef OCAMLSTUBS
165 DestSharedLib := $(PROJ_libocamldir)/dll$(LIBRARYNAME).$(SHLIBEXT)
130166 endif
131167
132168 ##===- Dependencies -------------------------------------------------------===##
183219 uninstall-a::
184220 $(Echo) "Uninstalling $(DestA)"
185221 -$(Verb) $(RM) -f $(DestA)
222 endif
223
224
225 ##===- Build stub library from C sources ----------------------------------===##
226
227 ifdef SharedLib
228 all-local:: $(SharedLib)
229 clean-local:: clean-shared
230 install-local:: install-shared
231 uninstall-local:: uninstall-shared
232
233 $(SharedLib): $(ObjectsO) $(OcamlDir)/.dir
234 $(Echo) "Building $(BuildMode) $(notdir $@)"
235 $(Verb) $(Link) $(SharedLinkOptions) $(LLVMLibsOptions) \
236 -o $@ $(ObjectsO)
237
238 clean-shared::
239 -$(Verb) $(RM) -f $(SharedLib)
240
241 install-shared:: $(SharedLib)
242 $(Echo) "Installing $(BuildMode) $(DestSharedLib)"
243 $(Verb) $(MKDIR) $(PROJ_libocamldir)
244 $(Verb) $(INSTALL) $(SharedLib) $(DestSharedLib)
245 $(Verb)
246
247 uninstall-shared::
248 $(Echo) "Uninstalling $(DestSharedLib)"
249 -$(Verb) $(RM) -f $(DestSharedLib)
186250 endif
187251
188252
390454 $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)'
391455 $(Echo) "LibraryCMA : " '$(LibraryCMA)'
392456 $(Echo) "LibraryCMXA : " '$(LibraryCMXA)'
457 $(Echo) "SharedLib : " '$(SharedLib)'
393458 $(Echo) "OcamlSources1: " '$(OcamlSources1)'
394459 $(Echo) "OcamlSources2: " '$(OcamlSources2)'
395460 $(Echo) "OcamlSources : " '$(OcamlSources)'
403468 $(Echo) "DestA : " '$(DestA)'
404469 $(Echo) "DestCMA : " '$(DestCMA)'
405470 $(Echo) "DestCMXA : " '$(DestCMXA)'
471 $(Echo) "DestSharedLib: " '$(DestSharedLib)'
406472 $(Echo) "UsedLibs : " '$(UsedLibs)'
407473 $(Echo) "UsedLibNames : " '$(UsedLibNames)'
408474
125125 @$(ECHOPATH) s=@SHLIBDIR@=$(SharedLibDir)=g >> lit.tmp
126126 @$(ECHOPATH) s=@SHLIBEXT@=$(SHLIBEXT)=g >> lit.tmp
127127 @$(ECHOPATH) s=@PYTHON_EXECUTABLE@=$(PYTHON)=g >> lit.tmp
128 @$(ECHOPATH) s=@OCAMLOPT@=$(OCAMLOPT) -cc $(subst *,'\\\"',*$(subst =,"\\=",$(CXX_FOR_OCAMLOPT))*) -I $(LibDir)/ocaml=g >> lit.tmp
128 @$(ECHOPATH) s=@OCAMLOPT@=$(OCAMLOPT) -cc $(subst *,'\\\"',*$(subst =,"\\=",$(CXX_FOR_OCAMLOPT))*) -cclib -L$(LibDir) -I $(LibDir)/ocaml=g >> lit.tmp
129129 @$(ECHOPATH) s=@ENABLE_SHARED@=$(ENABLE_SHARED)=g >> lit.tmp
130130 @$(ECHOPATH) s=@ENABLE_ASSERTIONS@=$(ENABLE_ASSERTIONS)=g >> lit.tmp
131131 @$(ECHOPATH) s=@TARGETS_TO_BUILD@=$(TARGETS_TO_BUILD)=g >> lit.tmp