Home | History | Annotate | Download | only in llvm-shlib
      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 
     10 LEVEL = ../..
     11 
     12 LIBRARYNAME = LLVM-$(LLVMVersion)
     13 
     14 NO_BUILD_ARCHIVE = 1
     15 LINK_LIBS_IN_SHARED = 1
     16 SHARED_LIBRARY = 1
     17 
     18 include $(LEVEL)/Makefile.config
     19 
     20 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
     21   EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports
     22 
     23   ifeq (1,$(ENABLE_EMBED_STDCXX))
     24     # It is needed to force static-stdc++.a linked.
     25     SHLIB_FRAG_NAMES += stdc++.a.o
     26   endif
     27 
     28 endif
     29 
     30 include $(LEVEL)/Makefile.common
     31 
     32 # Include all archives in libLLVM.(so|dylib) except the ones that have
     33 # their own dynamic libraries.
     34 Archives := $(wildcard $(LibDir)/libLLVM*.a)
     35 SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
     36 IncludeInLibLlvm := $(filter-out $(basename $(SharedLibraries)).a, $(Archives))
     37 LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
     38 LLVMLibsPaths   := $(IncludeInLibLlvm)
     39 
     40 $(LibName.SO): $(LLVMLibsPaths)
     41 
     42 ifeq ($(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)  \
     53                          -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
     63 endif
     64 
     65 ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD))
     66     # Include everything from the .a's into the shared library.
     67     LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
     68                        -Wl,--no-whole-archive
     69 endif
     70 
     71 ifeq ($(HOST_OS),Linux)
     72     # Don't allow unresolved symbols.
     73     LLVMLibsOptions += -Wl,--no-undefined
     74 endif
     75 
     76 ifeq ($(HOST_OS),SunOS)
     77     # add -z allextract ahead of other libraries on Solaris
     78     LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions)
     79 endif
     80 
     81 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
     82 
     83 SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES))
     84 SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES))
     85 LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions)
     86 
     87 $(LibName.SO): $(SHLIB_STUBS)
     88 
     89 %.syms.txt: %.a.o
     90 	$(Echo) Collecting global symbols of $(notdir $*)
     91 	$(Verb) $(NM_PATH) -g $< > $@
     92 
     93 $(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
     94 	$(Echo) Generating exports for $(LIBRARYNAME)
     95 	$(Verb) ($(SED) -n \
     96 			-e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
     97 			-e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
     98 			$(SHLIB_FRAGS) \
     99 		 | sort -u) > $@
    100 
    101 $(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir
    102 	$(Echo) Linking all LLVMLibs together for $(LIBRARYNAME)
    103 	$(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
    104 			-Wl,--whole-archive $(LLVMLibsPaths) \
    105 			-Wl,--no-whole-archive
    106 
    107 $(ObjDir)/stdc++.a.o: $(ObjDir)/.dir
    108 	$(Echo) Linking all libs together for static libstdc++.a
    109 	$(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \
    110 			-Wl,--whole-archive -lstdc++ \
    111 			-Wl,--no-whole-archive
    112 # FIXME: workaround to invalidate -lstdc++
    113 	$(Echo) Making dummy -lstdc++ to lib
    114 	$(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a
    115 # FIXME: Is install-local needed?
    116 
    117 clean-local::
    118 	$(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a
    119 
    120 endif
    121