Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 1 | ##===- 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 Dunbar | 8c39c96 | 2011-10-18 19:27:24 +0000 | [diff] [blame] | 10 | LEVEL := ../.. |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 11 | |
| 12 | LIBRARYNAME = LLVM-$(LLVMVersion) |
| 13 | |
Daniel Dunbar | 8c39c96 | 2011-10-18 19:27:24 +0000 | [diff] [blame] | 14 | NO_BUILD_ARCHIVE := 1 |
| 15 | LINK_LIBS_IN_SHARED := 1 |
| 16 | SHARED_LIBRARY := 1 |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 17 | |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 18 | include $(LEVEL)/Makefile.config |
| 19 | |
| 20 | ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) |
NAKAMURA Takumi | 8eac886 | 2010-12-29 03:59:14 +0000 | [diff] [blame] | 21 | EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 22 | |
NAKAMURA Takumi | 8eac886 | 2010-12-29 03:59:14 +0000 | [diff] [blame] | 23 | ifeq (1,$(ENABLE_EMBED_STDCXX)) |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 24 | # It is needed to force static-stdc++.a linked. |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 25 | SHLIB_FRAG_NAMES += stdc++.a.o |
NAKAMURA Takumi | 8eac886 | 2010-12-29 03:59:14 +0000 | [diff] [blame] | 26 | endif |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 27 | |
| 28 | endif |
| 29 | |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 30 | include $(LEVEL)/Makefile.common |
| 31 | |
| 32 | # Include all archives in libLLVM.(so|dylib) except the ones that have |
Peter Collingbourne | e97552e | 2011-10-04 00:30:34 +0000 | [diff] [blame] | 33 | # their own dynamic libraries and TableGen. |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 34 | Archives := $(wildcard $(LibDir)/libLLVM*.a) |
| 35 | SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT)) |
Peter Collingbourne | e97552e | 2011-10-04 00:30:34 +0000 | [diff] [blame] | 36 | ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a |
| 37 | IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives)) |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 38 | LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%) |
| 39 | LLVMLibsPaths := $(IncludeInLibLlvm) |
| 40 | |
| 41 | $(LibName.SO): $(LLVMLibsPaths) |
| 42 | |
| 43 | ifeq ($(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 Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 54 | -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 |
| 64 | endif |
| 65 | |
Eric Christopher | b0f6759 | 2012-08-06 20:52:18 +0000 | [diff] [blame] | 66 | ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD GNU Bitrig)) |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 67 | # Include everything from the .a's into the shared library. |
| 68 | LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \ |
| 69 | -Wl,--no-whole-archive |
Chris Lattner | fa1059f | 2012-04-25 06:37:20 +0000 | [diff] [blame] | 70 | endif |
| 71 | |
| 72 | ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD GNU)) |
Anton Korobeynikov | 1895fc9 | 2012-04-03 19:48:31 +0000 | [diff] [blame] | 73 | # Add soname to the library. |
| 74 | LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) |
NAKAMURA Takumi | 1c48377 | 2010-10-28 06:45:57 +0000 | [diff] [blame] | 75 | endif |
| 76 | |
Sylvestre Ledru | 6fc30c2 | 2012-04-11 15:35:36 +0000 | [diff] [blame] | 77 | ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU)) |
Jeffrey Yasskin | c901719 | 2010-02-25 06:34:33 +0000 | [diff] [blame] | 78 | # Don't allow unresolved symbols. |
| 79 | LLVMLibsOptions += -Wl,--no-undefined |
| 80 | endif |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 81 | |
Chris Lattner | c55f58b | 2011-02-13 08:38:44 +0000 | [diff] [blame] | 82 | ifeq ($(HOST_OS),SunOS) |
| 83 | # add -z allextract ahead of other libraries on Solaris |
| 84 | LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions) |
| 85 | endif |
| 86 | |
Anton Korobeynikov | 59a430f | 2010-08-17 19:03:03 +0000 | [diff] [blame] | 87 | ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) |
| 88 | |
| 89 | SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES)) |
| 90 | SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES)) |
| 91 | LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions) |
| 92 | |
| 93 | $(LibName.SO): $(SHLIB_STUBS) |
| 94 | |
| 95 | %.syms.txt: %.a.o |
| 96 | $(Echo) Collecting global symbols of $(notdir $*) |
| 97 | $(Verb) $(NM_PATH) -g $< > $@ |
| 98 | |
| 99 | $(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir |
| 100 | $(Echo) Generating exports for $(LIBRARYNAME) |
| 101 | $(Verb) ($(SED) -n \ |
| 102 | -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \ |
| 103 | -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \ |
| 104 | $(SHLIB_FRAGS) \ |
| 105 | | sort -u) > $@ |
| 106 | |
| 107 | $(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir |
| 108 | $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME) |
| 109 | $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \ |
| 110 | -Wl,--whole-archive $(LLVMLibsPaths) \ |
| 111 | -Wl,--no-whole-archive |
| 112 | |
| 113 | $(ObjDir)/stdc++.a.o: $(ObjDir)/.dir |
| 114 | $(Echo) Linking all libs together for static libstdc++.a |
| 115 | $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \ |
| 116 | -Wl,--whole-archive -lstdc++ \ |
| 117 | -Wl,--no-whole-archive |
| 118 | # FIXME: workaround to invalidate -lstdc++ |
| 119 | $(Echo) Making dummy -lstdc++ to lib |
| 120 | $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a |
| 121 | # FIXME: Is install-local needed? |
| 122 | |
| 123 | clean-local:: |
| 124 | $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a |
| 125 | |
| 126 | endif |