Create a default symver on Linux like ELF OSes.
[oota-llvm.git] / tools / llvm-shlib / Makefile
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
10 LEVEL := ../..
11
12 LIBRARYNAME = LLVM-$(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX)
13 LIBRARYALIASNAME = LLVM-$(LLVMVersion)
14
15 NO_BUILD_ARCHIVE := 1
16 LINK_LIBS_IN_SHARED := 1
17 SHARED_LIBRARY := 1
18 SHARED_ALIAS := 1
19
20 include $(LEVEL)/Makefile.config
21
22 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
23   EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
24
25   ifeq (1,$(ENABLE_EMBED_STDCXX))
26     # It is needed to force static-stdc++.a linked.
27     SHLIB_FRAG_NAMES += stdc++.a.o
28   endif
29
30 endif
31
32 include $(LEVEL)/Makefile.common
33
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)
42
43 $(LibName.SO): $(LLVMLibsPaths)
44
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
51     endif
52     # Include everything from the .a's into the shared library.
53     LLVMLibsOptions    := $(LLVMLibsOptions) -all_load
54 endif
55
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
60 endif
61
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)
65 endif
66
67 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD))
68     # Don't allow unresolved symbols.
69     LLVMLibsOptions += -Wl,--no-undefined
70 endif
71
72 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD))
73     # Define a default symbol version
74     LLVMLibsOptions += -Wl,--default-symver
75 endif
76
77 ifeq ($(HOST_OS),SunOS)
78     # add -z allextract ahead of other libraries on Solaris
79     LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
80 endif
81
82 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
83
84 SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
85 SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
86 LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
87
88 $(LibName.SO): $(SHLIB_STUBS)
89
90 %.syms.txt: %.a.o
91         $(Echo) Collecting global symbols of $(notdir $*)
92         $(Verb) $(NM_PATH) -g $< > $@
93
94 $(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
95         $(Echo) Generating exports for $(LIBRARYNAME)
96         $(Verb) ($(SED) -n \
97                         -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
98                         -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
99                         $(SHLIB_FRAGS) \
100                  | sort -u) > $@
101
102 $(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
103         $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
104         $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
105                         -Wl,--whole-archive $(LLVMLibsPaths) \
106                         -Wl,--no-whole-archive
107
108 $(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
109         $(Echo) Linking all libs together for static libstdc++.a
110         $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
111                         -Wl,--whole-archive -lstdc++ \
112                         -Wl,--no-whole-archive
113 # FIXME: workaround to invalidate -lstdc++
114         $(Echo) Making dummy -lstdc++ to lib
115         $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
116 # FIXME: Is install-local needed?
117
118 clean-local::
119         $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
120
121 endif