1 ##===- tools/shlib/Makefile --------------------------------*- Makefile -*-===##
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
8 ##===----------------------------------------------------------------------===##
12 LIBRARYNAME = LLVM-$(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX)
13 LIBRARYALIASNAME = LLVM-$(LLVMVersion)
16 LINK_LIBS_IN_SHARED := 1
20 include $(LEVEL)/Makefile.config
22 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
23 EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
25 ifeq (1,$(ENABLE_EMBED_STDCXX))
26 # It is needed to force static-stdc++.a linked.
27 SHLIB_FRAG_NAMES += stdc++.a.o
32 include $(LEVEL)/Makefile.common
34 # Include all archives in libLLVM.(so|dylib) except the ones that have
35 # their own dynamic libraries and TableGen.
36 Archives := $(wildcard $(LibDir)/libLLVM*.a)
37 SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
38 ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a
39 IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives))
40 LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
41 LLVMLibsPaths := $(IncludeInLibLlvm)
43 $(LibName.SO): $(LLVMLibsPaths)
45 ifeq ($(HOST_OS),Darwin)
46 # set dylib internal version number to llvmCore submission number
47 ifdef LLVM_SUBMIT_VERSION
48 LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \
49 -Wl,$(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION) \
50 -Wl,-compatibility_version -Wl,1
52 # Include everything from the .a's into the shared library.
53 LLVMLibsOptions := $(LLVMLibsOptions) -all_load
56 ifeq ($(HOST_OS), $(filter $(HOST_OS), DragonFly Linux FreeBSD GNU/kFreeBSD OpenBSD GNU Bitrig))
57 # Include everything from the .a's into the shared library.
58 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
59 -Wl,--no-whole-archive
62 ifeq ($(HOST_OS), $(filter $(HOST_OS), DragonFly Linux FreeBSD GNU/kFreeBSD GNU))
63 # Add soname to the library.
64 LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT)
67 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD))
68 # Don't allow unresolved symbols.
69 LLVMLibsOptions += -Wl,--no-undefined
72 ifeq ($(HOST_OS),SunOS)
73 # add -z allextract ahead of other libraries on Solaris
74 LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
77 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
79 SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
80 SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
81 LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
83 $(LibName.SO): $(SHLIB_STUBS)
86 $(Echo) Collecting global symbols of $(notdir $*)
87 $(Verb) $(NM_PATH) -g $< > $@
89 $(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
90 $(Echo) Generating exports for $(LIBRARYNAME)
92 -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
93 -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
97 $(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
98 $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
99 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
100 -Wl,--whole-archive $(LLVMLibsPaths) \
101 -Wl,--no-whole-archive
103 $(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
104 $(Echo) Linking all libs together for static libstdc++.a
105 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
106 -Wl,--whole-archive -lstdc++ \
107 -Wl,--no-whole-archive
108 # FIXME: workaround to invalidate -lstdc++
109 $(Echo) Making dummy -lstdc++ to lib
110 $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
111 # FIXME: Is install-local needed?
114 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a