blob: e7605c8f4e3765fdc4a50c58281ef6bfdd48b16a [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
10LEVEL = ../..
11
12LIBRARYNAME = LLVM-$(LLVMVersion)
13
14NO_BUILD_ARCHIVE = 1
15LINK_LIBS_IN_SHARED = 1
16SHARED_LIBRARY = 1
17
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
33# their own dynamic libraries.
34Archives := $(wildcard $(LibDir)/libLLVM*.a)
35SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
36IncludeInLibLlvm := $(filter-out $(basename $(SharedLibraries)).a, $(Archives))
37LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
38LLVMLibsPaths := $(IncludeInLibLlvm)
39
40$(LibName.SO): $(LLVMLibsPaths)
41
42ifeq ($(HOST_OS),Darwin)
43 # set dylib internal version number to llvmCore submission number
44 ifdef LLVM_SUBMIT_VERSION
45 LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \
46 -Wl,$(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION) \
47 -Wl,-compatibility_version -Wl,1
48 endif
49 # Include everything from the .a's into the shared library.
50 LLVMLibsOptions := $(LLVMLibsOptions) -all_load
51 # extra options to override libtool defaults
52 LLVMLibsOptions := $(LLVMLibsOptions) \
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000053 -Wl,-dead_strip \
54 -Wl,-seg1addr -Wl,0xE0000000
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,"@executable_path/../lib/lib$(LIBRARYNAME)$(SHLIBEXT)"
62 endif
63endif
64
NAKAMURA Takumi1c483772010-10-28 06:45:57 +000065ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD))
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000066 # Include everything from the .a's into the shared library.
67 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
68 -Wl,--no-whole-archive
NAKAMURA Takumi1c483772010-10-28 06:45:57 +000069endif
70
71ifeq ($(HOST_OS),Linux)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000072 # Don't allow unresolved symbols.
73 LLVMLibsOptions += -Wl,--no-undefined
74endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000075
76ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
77
78SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
79SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
80LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
81
82$(LibName.SO): $(SHLIB_STUBS)
83
84%.syms.txt: %.a.o
85 $(Echo) Collecting global symbols of $(notdir $*)
86 $(Verb) $(NM_PATH) -g $< > $@
87
88$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
89 $(Echo) Generating exports for $(LIBRARYNAME)
90 $(Verb) ($(SED) -n \
91 -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
92 -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
93 $(SHLIB_FRAGS) \
94 | sort -u) > $@
95
96$(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
97 $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
98 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
99 -Wl,--whole-archive $(LLVMLibsPaths) \
100 -Wl,--no-whole-archive
101
102$(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
103 $(Echo) Linking all libs together for static libstdc++.a
104 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
105 -Wl,--whole-archive -lstdc++ \
106 -Wl,--no-whole-archive
107# FIXME: workaround to invalidate -lstdc++
108 $(Echo) Making dummy -lstdc++ to lib
109 $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
110# FIXME: Is install-local needed?
111
112clean-local::
113 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
114
115endif