Fixed some bugs.
[llvm/zpu.git] / tools / llvm-shlib / Makefile
blob60b54350ee9837d234df38df785af88a5be92d78
1 ##===- tools/shlib/Makefile --------------------------------*- Makefile -*-===##
2 #
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7 #
8 ##===----------------------------------------------------------------------===##
10 LEVEL = ../..
12 LIBRARYNAME = LLVM-$(LLVMVersion)
14 NO_BUILD_ARCHIVE = 1
15 LINK_LIBS_IN_SHARED = 1
16 SHARED_LIBRARY = 1
18 include $(LEVEL)/Makefile.config
20 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
21 EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
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
27 endif
29 include $(LEVEL)/Makefile.common
31 # Include all archives in libLLVM.(so|dylib) except the ones that have
32 # their own dynamic libraries.
33 Archives := $(wildcard $(LibDir)/libLLVM*.a)
34 SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
35 IncludeInLibLlvm := $(filter-out $(basename $(SharedLibraries)).a, $(Archives))
36 LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
37 LLVMLibsPaths := $(IncludeInLibLlvm)
39 $(LibName.SO): $(LLVMLibsPaths)
41 ifeq ($(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) \
52 -Wl,-dead_strip \
53 -Wl,-seg1addr -Wl,0xE0000000
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
62 endif
64 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD))
65 # Include everything from the .a's into the shared library.
66 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
67 -Wl,--no-whole-archive
68 endif
70 ifeq ($(HOST_OS),Linux)
71 # Don't allow unresolved symbols.
72 LLVMLibsOptions += -Wl,--no-undefined
73 endif
75 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
77 SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
78 SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
79 LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
81 $(LibName.SO): $(SHLIB_STUBS)
83 %.syms.txt: %.a.o
84 $(Echo) Collecting global symbols of $(notdir $*)
85 $(Verb) $(NM_PATH) -g $< > $@
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) > $@
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
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?
111 clean-local::
112 $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
114 endif