blob: 1d3567018220a8a76a607044d92ddf0f21b6af5d [file] [log] [blame]
Jeffrey Yasskinc9017192010-02-25 06:34:33 +00001##===- 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
Daniel Dunbar8c39c962011-10-18 19:27:24 +000010LEVEL := ../..
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000011
12LIBRARYNAME = LLVM-$(LLVMVersion)
13
Daniel Dunbar8c39c962011-10-18 19:27:24 +000014NO_BUILD_ARCHIVE := 1
15LINK_LIBS_IN_SHARED := 1
16SHARED_LIBRARY := 1
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000017
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000018include $(LEVEL)/Makefile.config
19
20ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
NAKAMURA Takumi8eac8862010-12-29 03:59:14 +000021 EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000022
NAKAMURA Takumi8eac8862010-12-29 03:59:14 +000023 ifeq (1,$(ENABLE_EMBED_STDCXX))
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000024 # It is needed to force static-stdc++.a linked.
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000025 SHLIB_FRAG_NAMES += stdc++.a.o
NAKAMURA Takumi8eac8862010-12-29 03:59:14 +000026 endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000027
28endif
29
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000030include $(LEVEL)/Makefile.common
31
32# Include all archives in libLLVM.(so|dylib) except the ones that have
Peter Collingbournee97552e2011-10-04 00:30:34 +000033# their own dynamic libraries and TableGen.
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000034Archives := $(wildcard $(LibDir)/libLLVM*.a)
35SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
Peter Collingbournee97552e2011-10-04 00:30:34 +000036ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a
37IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives))
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000038LLVMLibsOptions := $(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) \
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000054 -Wl,-dead_strip \
55 -Wl,-seg1addr -Wl,0xE0000000
56
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) \
61 -Wl,-install_name \
62 -Wl,"@executable_path/../lib/lib$(LIBRARYNAME)$(SHLIBEXT)"
63 endif
64endif
65
NAKAMURA Takumi1c483772010-10-28 06:45:57 +000066ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD))
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000067 # Include everything from the .a's into the shared library.
68 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
69 -Wl,--no-whole-archive
NAKAMURA Takumi1c483772010-10-28 06:45:57 +000070endif
71
72ifeq ($(HOST_OS),Linux)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000073 # Don't allow unresolved symbols.
74 LLVMLibsOptions += -Wl,--no-undefined
75endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000076
Chris Lattnerc55f58b2011-02-13 08:38:44 +000077ifeq ($(HOST_OS),SunOS)
78 # add -z allextract ahead of other libraries on Solaris
79 LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
80endif
81
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000082ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
83
84SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
85SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
86LLVMLibsOptions := $(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
118clean-local::
119 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
120
121endif