blob: 52381304bb93e0acb41f3e002ebdad53613dec9e [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
64ifeq ($(HOST_OS), Linux)
65 # Include everything from the .a's into the shared library.
66 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
67 -Wl,--no-whole-archive
68 # Don't allow unresolved symbols.
69 LLVMLibsOptions += -Wl,--no-undefined
70endif
Anton Korobeynikov59a430f2010-08-17 19:03:03 +000071
72ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
73
74SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
75SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
76LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
77
78$(LibName.SO): $(SHLIB_STUBS)
79
80%.syms.txt: %.a.o
81 $(Echo) Collecting global symbols of $(notdir $*)
82 $(Verb) $(NM_PATH) -g $< > $@
83
84$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
85 $(Echo) Generating exports for $(LIBRARYNAME)
86 $(Verb) ($(SED) -n \
87 -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
88 -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
89 $(SHLIB_FRAGS) \
90 | sort -u) > $@
91
92$(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
93 $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
94 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
95 -Wl,--whole-archive $(LLVMLibsPaths) \
96 -Wl,--no-whole-archive
97
98$(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
99 $(Echo) Linking all libs together for static libstdc++.a
100 $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
101 -Wl,--whole-archive -lstdc++ \
102 -Wl,--no-whole-archive
103# FIXME: workaround to invalidate -lstdc++
104 $(Echo) Making dummy -lstdc++ to lib
105 $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
106# FIXME: Is install-local needed?
107
108clean-local::
109 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
110
111endif