• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1##===- tools/shlib/Makefile --------------------------------*- Makefile -*-===##
2#
3#                     The LLVM Compiler Infrastructure
4#
5# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
7#
8##===----------------------------------------------------------------------===##
9
10LEVEL := ../..
11
12LIBRARYNAME = LLVM-$(LLVMVersion)
13
14NO_BUILD_ARCHIVE := 1
15LINK_LIBS_IN_SHARED := 1
16SHARED_LIBRARY := 1
17
18include $(LEVEL)/Makefile.config
19
20ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
21  EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
22
23  ifeq (1,$(ENABLE_EMBED_STDCXX))
24    # It is needed to force static-stdc++.a linked.
25    SHLIB_FRAG_NAMES += stdc++.a.o
26  endif
27
28endif
29
30include $(LEVEL)/Makefile.common
31
32# Include all archives in libLLVM.(so|dylib) except the ones that have
33# their own dynamic libraries and TableGen.
34Archives := $(wildcard $(LibDir)/libLLVM*.a)
35SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
36ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a
37IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives))
38LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
39LLVMLibsPaths   := $(IncludeInLibLlvm)
40
41$(LibName.SO): $(LLVMLibsPaths)
42
43ifeq ($(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
49    endif
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)  \
54                         -Wl,-dead_strip
55
56    # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line
57    DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/')
58    ifneq ($(DARWIN_VERS),8)
59       LLVMLibsOptions    := $(LLVMLibsOptions)  \
60                            -Wl,-install_name \
61                            -Wl,"@rpath/lib$(LIBRARYNAME)$(SHLIBEXT)"
62    endif
63endif
64
65ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD GNU/kFreeBSD OpenBSD GNU Bitrig))
66    # Include everything from the .a's into the shared library.
67    LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
68                       -Wl,--no-whole-archive
69endif
70
71ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD GNU/kFreeBSD GNU))
72    # Add soname to the library.
73    LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT)
74endif
75
76ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD))
77    # Don't allow unresolved symbols.
78    LLVMLibsOptions += -Wl,--no-undefined
79endif
80
81ifeq ($(HOST_OS),SunOS)
82    # add -z allextract ahead of other libraries on Solaris
83    LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
84endif
85
86ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
87
88SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
89SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
90LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
91
92$(LibName.SO): $(SHLIB_STUBS)
93
94%.syms.txt: %.a.o
95	$(Echo) Collecting global symbols of $(notdir $*)
96	$(Verb) $(NM_PATH) -g $< > $@
97
98$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
99	$(Echo) Generating exports for $(LIBRARYNAME)
100	$(Verb) ($(SED) -n \
101			-e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
102			-e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
103			$(SHLIB_FRAGS) \
104		 | sort -u) > $@
105
106$(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
107	$(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
108	$(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
109			-Wl,--whole-archive $(LLVMLibsPaths) \
110			-Wl,--no-whole-archive
111
112$(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
113	$(Echo) Linking all libs together for static libstdc++.a
114	$(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
115			-Wl,--whole-archive -lstdc++ \
116			-Wl,--no-whole-archive
117# FIXME: workaround to invalidate -lstdc++
118	$(Echo) Making dummy -lstdc++ to lib
119	$(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
120# FIXME: Is install-local needed?
121
122clean-local::
123	$(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
124
125endif
126