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-$(LLVMVersion)
15 LINK_LIBS_IN_SHARED := 1
18 include $(LEVEL)/Makefile.config
20 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
21 EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
23 ifeq (1,$(ENABLE_EMBED_STDCXX))
24 # It is needed to force static-stdc++.a linked.
25 SHLIB_FRAG_NAMES += stdc++.a.o
30 include $(LEVEL)/Makefile.common
32 # Include all archives in libLLVM.(so|dylib) except the ones that have
33 # their own dynamic libraries and TableGen.
34 Archives := $(wildcard $(LibDir)/libLLVM*.a)
35 SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
36 ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a
37 IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives))
38 LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
39 LLVMLibsPaths := $(IncludeInLibLlvm)
41 $(LibName.SO): $(LLVMLibsPaths)
43 ifeq ($(HOST_OS),Darwin)
44 # set dylib internal version number to llvmCore submission number
45 ifdef LLVM_SUBMIT_VERSION
46 LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \
47 -Wl,$(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION) \
48 -Wl,-compatibility_version -Wl,1
50 # Include everything from the .a's into the shared library.
51 LLVMLibsOptions := $(LLVMLibsOptions) -all_load
52 # extra options to override libtool defaults
53 LLVMLibsOptions := $(LLVMLibsOptions) \
55 -Wl,-seg1addr -Wl,0xE0000000
57 # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line
58 DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/')
59 ifneq ($(DARWIN_VERS),8)
60 LLVMLibsOptions := $(LLVMLibsOptions) \
62 -Wl,"@executable_path/../lib/lib$(LIBRARYNAME)$(SHLIBEXT)"
66 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD))
67 # Include everything from the .a's into the shared library.
68 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
69 -Wl,--no-whole-archive
72 ifeq ($(HOST_OS),Linux)
73 # Don't allow unresolved symbols.
74 LLVMLibsOptions += -Wl,--no-undefined
75 # Add soname to the library.
76 LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT)
79 ifeq ($(HOST_OS),SunOS)
80 # add -z allextract ahead of other libraries on Solaris
81 LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
84 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
86 SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
87 SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
88 LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
90 $(LibName.SO): $(SHLIB_STUBS)
93 $(Echo) Collecting global symbols of $(notdir $*)
94 $(Verb) $(NM_PATH) -g $< > $@
96 $(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
97 $(Echo) Generating exports for $(LIBRARYNAME)
99 -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
100 -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
104 $(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
105 $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
106 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
107 -Wl,--whole-archive $(LLVMLibsPaths) \
108 -Wl,--no-whole-archive
110 $(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
111 $(Echo) Linking all libs together for static libstdc++.a
112 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
113 -Wl,--whole-archive -lstdc++ \
114 -Wl,--no-whole-archive
115 # FIXME: workaround to invalidate -lstdc++
116 $(Echo) Making dummy -lstdc++ to lib
117 $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
118 # FIXME: Is install-local needed?
121 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a