blob: 60b54350ee9837d234df38df785af88a5be92d78 [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))
21 EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
22
23 # It is needed to force static-stdc++.a linked.
24 # FIXME: It should be omitted when configure detects system's stdc++.dll.
25 SHLIB_FRAG_NAMES += stdc++.a.o
26
27endif
28
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000029include $(LEVEL)/Makefile.common
30
31# Include all archives in libLLVM.(so|dylib) except the ones that have
32# their own dynamic libraries.
33Archives := $(wildcard $(LibDir)/libLLVM*.a)
34SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
35IncludeInLibLlvm := $(filter-out $(basename $(SharedLibraries)).a, $(Archives))
36LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
37LLVMLibsPaths := $(IncludeInLibLlvm)
38
39$(LibName.SO): $(LLVMLibsPaths)
40
41ifeq ($(HOST_OS),Darwin)
42 # set dylib internal version number to llvmCore submission number
43 ifdef LLVM_SUBMIT_VERSION
44 LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \
45 -Wl,$(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION) \
46 -Wl,-compatibility_version -Wl,1
47 endif
48 # Include everything from the .a's into the shared library.
49 LLVMLibsOptions := $(LLVMLibsOptions) -all_load
50 # extra options to override libtool defaults
51 LLVMLibsOptions := $(LLVMLibsOptions) \
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000052 -Wl,-dead_strip \
53 -Wl,-seg1addr -Wl,0xE0000000
54
55 # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line
56 DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/')
57 ifneq ($(DARWIN_VERS),8)
58 LLVMLibsOptions := $(LLVMLibsOptions) \
59 -Wl,-install_name \
60 -Wl,"@executable_path/../lib/lib$(LIBRARYNAME)$(SHLIBEXT)"
61 endif
62endif
63
NAKAMURA Takumi1c483772010-10-28 06:45:57 +000064ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD))
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000065 # Include everything from the .a's into the shared library.
66 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
67 -Wl,--no-whole-archive
NAKAMURA Takumi1c483772010-10-28 06:45:57 +000068endif
69
70ifeq ($(HOST_OS),Linux)
Jeffrey Yasskinc9017192010-02-25 06:34:33 +000071 # Don't allow unresolved symbols.
72 LLVMLibsOptions += -Wl,--no-undefined
73endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000074
75ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
76
77SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
78SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
79LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
80
81$(LibName.SO): $(SHLIB_STUBS)
82
83%.syms.txt: %.a.o
84 $(Echo) Collecting global symbols of $(notdir $*)
85 $(Verb) $(NM_PATH) -g $< > $@
86
87$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
88 $(Echo) Generating exports for $(LIBRARYNAME)
89 $(Verb) ($(SED) -n \
90 -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
91 -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
92 $(SHLIB_FRAGS) \
93 | sort -u) > $@
94
95$(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
96 $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
97 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
98 -Wl,--whole-archive $(LLVMLibsPaths) \
99 -Wl,--no-whole-archive
100
101$(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
102 $(Echo) Linking all libs together for static libstdc++.a
103 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
104 -Wl,--whole-archive -lstdc++ \
105 -Wl,--no-whole-archive
106# FIXME: workaround to invalidate -lstdc++
107 $(Echo) Making dummy -lstdc++ to lib
108 $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
109# FIXME: Is install-local needed?
110
111clean-local::
112 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
113
114endif