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-$(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX)
13LIBRARYALIASNAME = LLVM-$(LLVMVersion)
14
15NO_BUILD_ARCHIVE := 1
16LINK_LIBS_IN_SHARED := 1
17SHARED_LIBRARY := 1
18SHARED_ALIAS := 1
19
20include $(LEVEL)/Makefile.config
21
22ifeq ($(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
30endif
31
32include $(LEVEL)/Makefile.common
33
34# Include all archives in libLLVM.(so|dylib) except the ones that have
35# their own dynamic libraries and TableGen.
36Archives := $(wildcard $(LibDir)/libLLVM*.a)
37SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
38ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a
39IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives))
40LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
41LLVMLibsPaths   := $(IncludeInLibLlvm)
42
43$(LibName.SO): $(LLVMLibsPaths)
44
45ifeq ($(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
54endif
55
56ifeq ($(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
60endif
61
62ifeq ($(HOST_OS), $(filter $(HOST_OS), DragonFly Linux FreeBSD GNU/kFreeBSD GNU))
63    # Add soname to the library.
64    LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT)
65endif
66
67ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD))
68    # Don't allow unresolved symbols.
69    LLVMLibsOptions += -Wl,--no-undefined
70endif
71
72ifeq ($(HOST_OS),SunOS)
73    # add -z allextract ahead of other libraries on Solaris
74    LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
75endif
76
77ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
78
79SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
80SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
81LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
82
83$(LibName.SO): $(SHLIB_STUBS)
84
85%.syms.txt: %.a.o
86	$(Echo) Collecting global symbols of $(notdir $*)
87	$(Verb) $(NM_PATH) -g $< > $@
88
89$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
90	$(Echo) Generating exports for $(LIBRARYNAME)
91	$(Verb) ($(SED) -n \
92			-e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
93			-e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
94			$(SHLIB_FRAGS) \
95		 | sort -u) > $@
96
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
102
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?
112
113clean-local::
114	$(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
115
116endif
117