Merging r259381:
[oota-llvm.git] / Makefile.rules
index a1edb6b7dd835c1c4ab0d77721e5e3fe31606821..a67aef7c97aa161dd48fe1d51035293bf7f071f9 100644 (file)
@@ -42,7 +42,7 @@ VPATH=$(PROJ_SRC_DIR)
 # Reset the list of suffixes we know how to build.
 #--------------------------------------------------------------------
 .SUFFIXES:
-.SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll .m .mm
+.SUFFIXES: .c .cpp .cc .h .hpp .o .a .td .ps .dot .m .mm
 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
 
 #--------------------------------------------------------------------
@@ -78,6 +78,12 @@ LLVMBuildTool        := $(PROJ_SRC_ROOT)/utils/llvm-build/llvm-build
 
 # The files we are going to generate using llvm-build.
 LLVMBuildMakeFrag := $(PROJ_OBJ_ROOT)/Makefile.llvmbuild
+LLVMBuildCMakeFrag := $(PROJ_OBJ_ROOT)/LLVMBuild.cmake
+LLVMBuildCMakeExportsFrag := $(PROJ_OBJ_ROOT)/cmake/modules/LLVMBuildExports.cmake
+LLVMBuildMakeFrags := \
+       $(LLVMBuildMakeFrag) \
+       $(LLVMBuildCMakeFrag) \
+       $(LLVMBuildCMakeExportsFrag)
 LLVMConfigLibraryDependenciesInc := \
        $(PROJ_OBJ_ROOT)/tools/llvm-config/LibraryDependencies.inc
 
@@ -94,17 +100,20 @@ endif
 #
 # We include a dependency on this Makefile to ensure that changes to the
 # generation command get picked up.
-$(LLVMBuildMakeFrag): $(PROJ_SRC_ROOT)/Makefile.rules \
-                     $(PROJ_OBJ_ROOT)/Makefile.config
+$(LLVMBuildMakeFrags): $(PROJ_SRC_ROOT)/Makefile.rules \
+                      $(PROJ_OBJ_ROOT)/Makefile.config
        $(Echo) Constructing LLVMBuild project information.
-       $(Verb) $(LLVMBuildTool) \
+       $(Verb)$(PYTHON) $(LLVMBuildTool) \
          --native-target "$(TARGET_NATIVE_ARCH)" \
          --enable-targets "$(TARGETS_TO_BUILD)" \
+         --enable-optional-components "$(OPTIONAL_COMPONENTS)" \
          --write-library-table $(LLVMConfigLibraryDependenciesInc) \
-         --write-make-fragment $(LLVMBuildMakeFrag)
+         --write-make-fragment $(LLVMBuildMakeFrag) \
+         --write-cmake-fragment $(LLVMBuildCMakeFrag) \
+         --write-cmake-exports-fragment $(LLVMBuildCMakeExportsFrag)
 
 # For completeness, let Make know how the extra files are generated.
-$(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrag)
+$(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrags)
 
 # Include the generated Makefile fragment.
 #
@@ -119,7 +128,7 @@ LLVMBUILD_INCLUDE_DEPENDENCIES := 1
 
 # Clean the generated makefile fragment at the top-level.
 clean-local::
-       -$(Verb) $(RM) -f $(LLVMBuildMakeFrag)
+       -$(Verb) $(RM) -f $(LLVMBuildMakeFrags)
 endif
 -include $(LLVMBuildMakeFrag)
 
@@ -273,18 +282,10 @@ CPP.Defines :=
 ifeq ($(ENABLE_OPTIMIZED),1)
   BuildMode := Release
   # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
-  ifneq ($(HOST_OS),FreeBSD)
-  ifneq ($(HOST_OS),Darwin)
+  ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin Darwin DragonFly FreeBSD GNU/kFreeBSD))
     OmitFramePointer := -fomit-frame-pointer
   endif
-  endif
 
-  # Darwin requires -fstrict-aliasing to be explicitly enabled.
-  # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
-  # with -fstrict-aliasing and ipa-type-escape radr://6756684
-  #ifeq ($(HOST_OS),Darwin)
-  #  EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
-  #endif
   CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
   C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
   LD.Flags  += $(OPTIMIZE_OPTION)
@@ -292,7 +293,6 @@ ifeq ($(ENABLE_OPTIMIZED),1)
     BuildMode := $(BuildMode)+Debug
     CXX.Flags += -g
     C.Flags   += -g
-    LD.Flags  += -g
     KEEP_SYMBOLS := 1
   endif
 else
@@ -300,13 +300,16 @@ else
     BuildMode := Unoptimized
     CXX.Flags +=
     C.Flags   +=
-    LD.Flags  +=
     KEEP_SYMBOLS := 1
   else
     BuildMode := Debug
+    ifeq ($(ENABLE_SPLIT_DWARF), 1)
+    CXX.Flags += -gsplit-dwarf
+    C.Flags   += -gsplit-dwarf
+    else
     CXX.Flags += -g
     C.Flags   += -g
-    LD.Flags  += -g
+    endif
     KEEP_SYMBOLS := 1
   endif
 endif
@@ -316,11 +319,28 @@ ifeq ($(ENABLE_LIBCPP),1)
   LD.Flags +=  -stdlib=libc++
 endif
 
+ifeq ($(ENABLE_CXX1Y),1)
+  CXX.Flags += -std=c++1y
+else
+  ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+    # MinGW and Cygwin are a bit stricter and lack things like
+    # 'strdup', 'stricmp', etc in c++11 mode.
+    CXX.Flags += -std=gnu++11
+ else
+    CXX.Flags += -std=c++11
+ endif
+endif
+
+ifeq ($(ENABLE_WERROR),1)
+  CXX.Flags += -Werror
+  C.Flags += -Werror
+endif
+
 ifeq ($(ENABLE_PROFILING),1)
   BuildMode := $(BuildMode)+Profile
   CXX.Flags := $(filter-out -fomit-frame-pointer,$(CXX.Flags)) -pg -g
   C.Flags   := $(filter-out -fomit-frame-pointer,$(C.Flags)) -pg -g
-  LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg -g
+  LD.Flags  := $(filter-out -fomit-frame-pointer,$(LD.Flags)) -pg
   KEEP_SYMBOLS := 1
 endif
 
@@ -357,6 +377,7 @@ ifeq ($(ENABLE_COVERAGE),1)
   BuildMode := $(BuildMode)+Coverage
   CXX.Flags += -ftest-coverage -fprofile-arcs
   C.Flags   += -ftest-coverage -fprofile-arcs
+  LD.Flags   += -ftest-coverage -fprofile-arcs
 endif
 
 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
@@ -428,7 +449,6 @@ ifeq ($(HOST_OS),MingW)
   endif
 endif
 
-CXX.Flags     += -Woverloaded-virtual
 CPP.BaseFlags += $(CPP.Defines)
 AR.Flags      := cru
 
@@ -466,6 +486,8 @@ endif
 ObjRootDir  := $(PROJ_OBJ_DIR)/$(BuildMode)
 ObjDir      := $(ObjRootDir)
 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
+LibexecDir  := $(PROJ_OBJ_ROOT)/$(BuildMode)/libexec
+ShareDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/share
 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
@@ -492,27 +514,6 @@ ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
   endif
 endif
 
-#--------------------------------------------------------------------
-# LLVM Capable Compiler
-#--------------------------------------------------------------------
-
-ifneq ($(findstring llvm-gcc,$(LLVMCC_OPTION)),)
-  LLVMCC := $(LLVMGCC)
-  LLVMCXX := $(LLVMGXX)
-else
-  ifneq ($(findstring clang,$(LLVMCC_OPTION)),)
-    ifneq ($(CLANGPATH),)
-      LLVMCC := $(CLANGPATH)
-      LLVMCXX := $(CLANGXXPATH)
-    else
-      ifeq ($(ENABLE_BUILT_CLANG),1)
-        LLVMCC := $(LLVMToolDir)/clang
-        LLVMCXX := $(LLVMToolDir)/clang++
-      endif
-    endif
-  endif
-endif
-
 #--------------------------------------------------------------------
 # Full Paths To Compiled Tools and Utilities
 #--------------------------------------------------------------------
@@ -537,9 +538,6 @@ ifeq ($(LLVM_CROSS_COMPILING),1)
 else
   LLVM_CONFIG := $(LLVMToolDir)/llvm-config$(EXEEXT)
 endif
-ifndef LLVMLD
-LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
-endif
 ifndef LLVMDIS
 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
 endif
@@ -555,30 +553,45 @@ endif
 ifndef LBUGPOINT
 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
 endif
+ifndef LLVMLINK
+LLVMLINK      := $(LLVMToolDir)/llvm-link$(EXEEXT)
+endif
 
 #--------------------------------------------------------------------
 # Adjust to user's request
 #--------------------------------------------------------------------
 
 ifeq ($(HOST_OS),Darwin)
+ ifdef MACOSX_DEPLOYMENT_TARGET
+  DARWIN_VERSION := $(MACOSX_DEPLOYMENT_TARGET)
+ else
   DARWIN_VERSION := `sw_vers -productVersion`
+ endif
   # Strip a number like 10.4.7 to 10.4
-  DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
+  DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]+).*/\1/')
   # Get "4" out of 10.4 for later pieces in the makefile.
-  DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]).*/\1/')
+  DARWIN_MAJVERS := $(shell echo $(DARWIN_VERSION)| sed -E 's/10.([0-9]+).*/\1/')
 
   LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
   SharedLinkOptions := -dynamiclib
-  ifneq ($(ARCH),ARM)
-    SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
+  ifdef DEPLOYMENT_TARGET
+    SharedLinkOptions += $(DEPLOYMENT_TARGET)
+  else
+    ifneq ($(ARCH),ARM)
+      SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
+    endif
   endif
 else
   SharedLinkOptions=-shared
 endif
 
 ifeq ($(TARGET_OS),Darwin)
-  ifneq ($(ARCH),ARM)
-    TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
+  ifdef DEPLOYMENT_TARGET
+    TargetCommonOpts += $(DEPLOYMENT_TARGET)
+  else
+    ifneq ($(ARCH),ARM)
+      TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
+    endif
   endif
 endif
 
@@ -586,6 +599,8 @@ ifdef SHARED_LIBRARY
 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
 ifneq ($(HOST_OS),Darwin)
   LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
+else
+  LD.Flags += -Wl,-install_name  -Wl,"@rpath/lib$(LIBRARYNAME)$(SHLIBEXT)"
 endif
 endif
 endif
@@ -613,29 +628,50 @@ ifndef KEEP_SYMBOLS
   Install.StripFlag += -s
 endif
 
-ifdef TOOL_NO_EXPORTS
-  DynamicFlags :=
-else
-  DynamicFlag := $(RDYNAMIC)
+# By default, strip dead symbols at link time
+ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+ifneq ($(HOST_OS),Darwin)
+ifneq ($(HOST_ARCH),Mips)
+  CXX.Flags += -ffunction-sections -fdata-sections
+  ifeq ($(HOST_OS),SunOS)
+      CXX.Flags += -falign-functions=8
+  endif
+endif
+endif
+endif
+ifndef NO_DEAD_STRIP
+  ifeq ($(HOST_OS),Darwin)
+    LD.Flags += -Wl,-dead_strip
+  else
+    ifeq ($(HOST_OS),SunOS)
+      LD.Flags += -Wl,-z -Wl,discard-unused=sections
+    else
+      ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+        LD.Flags += -Wl,--gc-sections
+      endif
+    endif
+  endif
 endif
 
 # Adjust linker flags for building an executable
 ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
-ifneq ($(HOST_OS), Darwin)
-ifdef TOOLNAME
-  LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
-  ifdef EXAMPLE_TOOL
-    LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
+  ifndef TOOL_NO_EXPORTS
+    LD.Flags += $(RDYNAMIC)
+  endif
+  ifneq ($(HOST_OS), Darwin)
+    ifdef TOOLNAME
+      LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
+    endif
   else
-    LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
+    ifneq ($(DARWIN_MAJVERS),4)
+      LD.Flags += $(RPATH) -Wl,@executable_path/../lib
+    endif
+    ifeq ($(RC_XBS),YES)
+      TempFile := $(shell mkdir -p ${OBJROOT}/dSYMs ; mktemp ${OBJROOT}/dSYMs/llvm-lto.XXXXXX)
+      LD.Flags += -Wl,-object_path_lto -Wl,$(TempFile)
+    endif
   endif
 endif
-else
-ifneq ($(DARWIN_MAJVERS),4)
-  LD.Flags += $(RPATH) -Wl,@executable_path/../lib
-endif
-endif
-endif
 
 
 #----------------------------------------------------------
@@ -650,7 +686,9 @@ ifndef NO_PEDANTIC
 CompileCommonOpts += -pedantic -Wno-long-long
 endif
 CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
-                     $(EXTRA_OPTIONS)
+                     $(EXTRA_OPTIONS) $(COVERED_SWITCH_DEFAULT) \
+                     $(NO_UNINITIALIZED) $(NO_MAYBE_UNINITIALIZED) \
+                     $(MISSING_FIELD_INITIALIZERS) $(NO_COMMENT)
 # Enable cast-qual for C++; the workaround is to use const_cast.
 CXX.Flags += -Wcast-qual
 
@@ -658,13 +696,13 @@ ifeq ($(HOST_OS),HP-UX)
   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
 endif
 
-# If we are building a universal binary on Mac OS/X, pass extra options.  This
+# If we are building a universal binary on Mac OS X, pass extra options.  This
 # is useful to people that want to link the LLVM libraries into their universal
 # apps.
 #
 # The following can be optionally specified:
 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
-#      For Mac OS/X 10.4 Intel machines, the traditional one is:
+#      For Mac OS X 10.4 Intel machines, the traditional one is:
 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
@@ -674,9 +712,9 @@ ifdef UNIVERSAL
     UNIVERSAL_ARCH := i386 ppc
   endif
   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
-  CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
+  TargetCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
   ifdef UNIVERSAL_SDK_PATH
-    CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
+    TargetCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
   endif
 
   # Building universal cannot compute dependencies automatically.
@@ -697,10 +735,6 @@ ifeq ($(HOST_OS),SunOS)
 CPP.BaseFlags += -include llvm/Support/Solaris.h
 endif
 
-ifeq ($(HOST_OS),AuroraUX)
-CPP.BaseFlags += -include llvm/Support/Solaris.h
-endif # !HOST_OS - AuroraUX.
-
 # On Windows, SharedLibDir != LibDir. The order is important.
 ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
   LD.Flags    += -L$(SharedLibDir) -L$(LibDir) -L$(LLVMToolDir) -L$(LLVMLibDir)
@@ -738,17 +772,12 @@ Preprocess.CXX= $(Compile.Wrapper) \
                  $(CXX) $(CPP.Flags) $(TargetCommonOpts) $(CPPFLAGS) \
                 $(CompileCommonOpts) $(CXX.Flags) -E
 Link          = $(Compile.Wrapper) \
-                 $(CXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(LD.Flags) \
-                $(LDFLAGS) $(TargetCommonOpts)  $(CompileCommonOpts) $(Strip)
+                 $(CXX) $(CXXFLAGS) $(LD.Flags) $(LDFLAGS) \
+                $(TargetCommonOpts) $(Strip)
 
-BCCompile.C   = $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) \
-                $(TargetCommonOpts) $(CompileCommonOpts)
 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CPPFLAGS) \
                 $(TargetCommonOpts) $(CompileCommonOpts) -E
 
-BCCompile.CXX = $(LLVMCXX) $(CPP.Flags) $(CXX.Flags) $(CXXFLAGS) $(CPPFLAGS) \
-                $(TargetCommonOpts) $(CompileCommonOpts)
-
 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
 ScriptInstall = $(INSTALL) -m 0755
 DataInstall   = $(INSTALL) -m 0644
@@ -763,14 +792,13 @@ TableGen.Flags= -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
 LLVMTableGen  = $(LLVM_TBLGEN) $(TableGen.Flags)
 
 Archive       = $(AR) $(AR.Flags)
-LArchive      = $(LLVMToolDir)/llvm-ar rcsf
 ifdef RANLIB
 Ranlib        = $(RANLIB)
 else
 Ranlib        = ranlib
 endif
 
-AliasTool     = ln -s
+AliasTool     = ln -sf
 
 #----------------------------------------------------------
 # Get the list of source files and compute object file
@@ -789,9 +817,10 @@ Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
 endif
 
 BaseNameSources := $(sort $(basename $(Sources)))
+SourceDirs := $(sort $(dir $(Sources)))
 
 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
-ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
+ObjectDirs := $(SourceDirs:%=$(ObjDir)/%)
 
 #----------------------------------------------------------
 # For Mingw MSYS bash and Python/w32:
@@ -806,7 +835,7 @@ ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
 #----------------------------------------------------------
 
 ifeq (-mingw32,$(findstring -mingw32,$(BUILD_TRIPLE)))
-  ECHOPATH := $(Verb)python -u -c "import sys;print ' '.join(sys.argv[1:])"
+  ECHOPATH := $(Verb)$(PYTHON) -u -c "import sys;print ' '.join(sys.argv[1:])"
 else
   ECHOPATH := $(Verb)$(ECHO)
 endif
@@ -828,8 +857,18 @@ $(DESTDIR)$(PROJ_bindir) $(DESTDIR)$(PROJ_libdir) $(DESTDIR)$(PROJ_includedir) $
        $(Verb) $(MKDIR) $* > /dev/null
        $(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
 
-.PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
+.PRECIOUS: $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
+.PRECIOUS: $(LibexecDir)/.dir $(ShareDir)/.dir
+
+#---------------------------------------------------------
+# Collect the object directories (as there may be more
+# than one if the source code is spread across
+# subdirectories).
+#---------------------------------------------------------
+
+OBJECT_DIRS := $(ObjDir)/.dir $(ObjectDirs:%=%/.dir)
+.PRECIOUS: $(OBJECT_DIRS)
 
 #---------------------------------------------------------
 # Handle the DIRS options for sequential construction
@@ -1030,8 +1069,9 @@ ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
 LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
                    -L $(SharedLibDir)
 endif
-LLVMLibsOptions += -lLLVM-$(LLVMVersion)
-LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
+LLVM_SO_NAME = LLVM-$(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX)
+LLVMLibsOptions += -l$(LLVM_SO_NAME)
+LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)$(LLVM_SO_NAME)$(SHLIBEXT)
 else
 
 ifndef NO_LLVM_CONFIG
@@ -1070,7 +1110,7 @@ ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
 NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE)).map
 $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
        $(Verb) echo "{" > $@
-       $(Verb) grep -q "\<" $< && echo "  global:" >> $@ || :
+       $(Verb) grep -q '[[:alnum:]_]' $< && echo "  global:" >> $@ || :
        $(Verb) sed -e 's/$$/;/' -e 's/^/    /' < $< >> $@
 ifneq ($(HOST_OS),OpenBSD)
        $(Verb) echo "  local: *;" >> $@
@@ -1119,83 +1159,25 @@ endif
 # Library Build Rules: Four ways to build a library
 ###############################################################################
 
-#---------------------------------------------------------
-# Bytecode Module Targets:
-#   If the user set MODULE_NAME then they want to build a
-#   bytecode module from the sources. We compile all the
-#   sources and link it together into a single bytecode
-#   module.
-#---------------------------------------------------------
-
-ifdef MODULE_NAME
-ifeq ($(strip $(LLVMCC)),)
-$(warning Modules require LLVM capable compiler but none is available ****)
-else
-
-Module     := $(LibDir)/$(MODULE_NAME).bc
-LinkModule := $(LLVMLD) -r
-
-
-ifdef EXPORTED_SYMBOL_FILE
-LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
-endif
-
-$(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
-       $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
-       $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
-
-all-local:: $(Module)
-
-clean-local::
-ifneq ($(strip $(Module)),)
-       -$(Verb) $(RM) -f $(Module)
-endif
-
-ifdef BYTECODE_DESTINATION
-ModuleDestDir := $(BYTECODE_DESTINATION)
-else
-ModuleDestDir := $(DESTDIR)$(PROJ_libdir)
-endif
-
-ifdef NO_INSTALL
-install-local::
-       $(Echo) Install circumvented with NO_INSTALL
-uninstall-local::
-       $(Echo) Uninstall circumvented with NO_INSTALL
-else
-DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
-
-install-module:: $(DestModule)
-install-local:: $(DestModule)
-
-$(DestModule): $(ModuleDestDir) $(Module)
-       $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
-       $(Verb) $(DataInstall) $(Module) $(DestModule)
-
-uninstall-local::
-       $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
-       -$(Verb) $(RM) -f $(DestModule)
-endif
-
-endif
-endif
-
 # if we're building a library ...
 ifdef LIBRARYNAME
 
 # Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
 LIBRARYNAME := $(strip $(LIBRARYNAME))
+LIBRARYALIASNAME := $(strip $(LIBRARYALIASNAME))
 ifdef LOADABLE_MODULE
 BaseLibName.A  := $(LIBRARYNAME).a
 BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
+BaseAliasName.SO := $(LIBRARYALIASNAME)$(SHLIBEXT)
 else
 BaseLibName.A  := lib$(LIBRARYNAME).a
 BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
+BaseAliasName.SO := $(SharedPrefix)$(LIBRARYALIASNAME)$(SHLIBEXT)
 endif
 LibName.A  := $(LibDir)/$(BaseLibName.A)
 LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
+AliasName.SO := $(SharedLibDir)/$(BaseAliasName.SO)
 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
-LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
 
 #---------------------------------------------------------
 # Shared Library Targets:
@@ -1205,7 +1187,12 @@ LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
 #---------------------------------------------------------
 ifdef SHARED_LIBRARY
 
-all-local:: $(LibName.SO)
+all-local:: $(AliasName.SO)
+
+$(AliasName.SO): $(LibName.SO)
+ifdef SHARED_ALIAS
+       $(Verb) $(AliasTool) $(BaseLibName.SO) $(AliasName.SO)
+endif
 
 ifdef EXPORTED_SYMBOL_FILE
 $(LibName.SO): $(NativeExportsFile)
@@ -1248,81 +1235,23 @@ else
 DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
 endif
 DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
+DestSharedAlias := $(DestSharedLibDir)/$(BaseAliasName.SO)
 
 install-local:: $(DestSharedLib)
 
 $(DestSharedLib): $(LibName.SO) $(DestSharedLibDir)
        $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
        $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
-
-uninstall-local::
-       $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
-       -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
-endif
-endif
-
-#---------------------------------------------------------
-# Bytecode Library Targets:
-#   If the user asked for a bytecode library to be built
-#   with the BYTECODE_LIBRARY variable, then we provide
-#   targets for building them.
-#---------------------------------------------------------
-ifdef BYTECODE_LIBRARY
-ifeq ($(strip $(LLVMCC)),)
-$(warning Bytecode libraries require LLVM capable compiler but none is available ****)
-else
-
-all-local:: $(LibName.BCA)
-
-ifdef EXPORTED_SYMBOL_FILE
-BCLinkLib = $(LLVMLD) -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
-
-$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
-                $(LLVMToolDir)/llvm-ar
-       $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
-         "(internalize)"
-       $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).internalize $(ObjectsBC)
-       $(Verb) $(RM) -f $@
-       $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).internalize.bc
-else
-$(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
-                $(LLVMToolDir)/llvm-ar
-       $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
-       $(Verb) $(RM) -f $@
-       $(Verb) $(LArchive) $@ $(ObjectsBC)
-
+ifdef SHARED_ALIAS
+       $(Echo) Creating alias from $(DestSharedLib) to $(DestSharedAlias)
+       $(Verb) $(AliasTool) $(BaseLibName.SO) $(DestSharedAlias)
 endif
 
-clean-local::
-ifneq ($(strip $(LibName.BCA)),)
-       -$(Verb) $(RM) -f $(LibName.BCA)
-endif
-
-ifdef BYTECODE_DESTINATION
-BytecodeDestDir := $(BYTECODE_DESTINATION)
-else
-BytecodeDestDir := $(DESTDIR)$(PROJ_libdir)
-endif
-
-DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).bca
-
-install-bytecode-local:: $(DestBytecodeLib)
-
-ifdef NO_INSTALL
-install-local::
-       $(Echo) Install circumvented with NO_INSTALL
 uninstall-local::
-       $(Echo) Uninstall circumvented with NO_INSTALL
-else
-install-local:: $(DestBytecodeLib)
-
-$(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
-       $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
-       $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
-
-uninstall-local::
-       $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
-       -$(Verb) $(RM) -f $(DestBytecodeLib)
+       $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
+       -$(Verb) $(RM) -f $(DestSharedLib)
+ifdef SHARED_ALIAS
+       -$(Verb) $(RM) -f $(DestSharedAlias)
 endif
 endif
 endif
@@ -1432,7 +1361,7 @@ LD.Flags += -Wl,-exported_symbol,_main
 endif
 endif
 
-ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
+ifeq ($(HOST_OS), $(filter $(HOST_OS), DragonFly Linux NetBSD FreeBSD GNU/kFreeBSD GNU))
 ifneq ($(ARCH), Mips)
   LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
 endif
@@ -1492,18 +1421,31 @@ else
 $(ToolBuildPath): $(ToolDir)/.dir
 endif
 
+ifdef CODESIGN_TOOLS
+TOOL_CODESIGN_IDENTITY ?= -
+
+$(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
+       $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
+       $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
+       $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
+       $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
+          $(StripWarnMsg)
+       $(Echo) ======= Code-Signing $(BuildMode) Executable $(TOOLNAME)
+       $(Verb) codesign -s $(TOOL_CODESIGN_IDENTITY) $@
+else
 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
        $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
        $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
        $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
        $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
           $(StripWarnMsg)
+endif
 
 ifneq ($(strip $(ToolAliasBuildPath)),)
 $(ToolAliasBuildPath): $(ToolBuildPath)
        $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
        $(Verb) $(RM) -f $(ToolAliasBuildPath)
-       $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
+       $(Verb) $(AliasTool) $(notdir $(ToolBuildPath)) $(ToolAliasBuildPath)
        $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
           $(StripWarnMsg)
 endif
@@ -1520,7 +1462,7 @@ ToolBinDir = $(DESTDIR)$(PROJ_internal_prefix)/bin
 else
 ToolBinDir = $(DESTDIR)$(PROJ_bindir)
 endif
-DestTool = $(ToolBinDir)/$(TOOLEXENAME)
+DestTool = $(ToolBinDir)/$(program_prefix)$(TOOLEXENAME)
 
 install-local:: $(DestTool)
 
@@ -1535,14 +1477,14 @@ uninstall-local::
 
 # TOOLALIAS install.
 ifdef TOOLALIAS
-DestToolAlias = $(ToolBinDir)/$(TOOLALIAS)$(EXEEXT)
+DestToolAlias = $(ToolBinDir)/$(program_prefix)$(TOOLALIAS)$(EXEEXT)
 
 install-local:: $(DestToolAlias)
 
 $(DestToolAlias): $(DestTool)
        $(Echo) Installing $(BuildMode) $(DestToolAlias)
        $(Verb) $(RM) -f $(DestToolAlias)
-       $(Verb) $(AliasTool) $(TOOLEXENAME) $(DestToolAlias)
+       $(Verb) $(AliasTool) $(notdir $(DestTool)) $(DestToolAlias)
 
 uninstall-local::
        $(Echo) Uninstalling $(BuildMode) $(DestToolAlias)
@@ -1561,6 +1503,8 @@ ifeq ($(HOST_OS),HP-UX)
   DISABLE_AUTO_DEPENDENCIES=1
 endif
 
+COMPILE_DEPS = $(OBJECT_DIRS) $(BUILT_SOURCES) $(PROJ_MAKEFILE)
+
 # Provide rule sets for when dependency generation is enabled
 ifndef DISABLE_AUTO_DEPENDENCIES
 
@@ -1576,182 +1520,98 @@ DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
 
-$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
+$(ObjDir)/%.o: %.cpp $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
        $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
                $(DEPEND_MOVEFILE)
 
-$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
+$(ObjDir)/%.o: %.mm $(COMPILE_DEPS)
        $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
        $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
                $(DEPEND_MOVEFILE)
 
-$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
+$(ObjDir)/%.o: %.cc $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
        $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
                $(DEPEND_MOVEFILE)
 
-$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
+$(ObjDir)/%.o: %.c $(COMPILE_DEPS)
        $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
        $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
                $(DEPEND_MOVEFILE)
 
-$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
+$(ObjDir)/%.o: %.m $(COMPILE_DEPS)
        $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
        $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
                $(DEPEND_MOVEFILE)
 
-#---------------------------------------------------------
-# Create .bc files in the ObjDir directory from .cpp .cc and .c files...
-#---------------------------------------------------------
-
-BC_DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.bc.d.tmp" \
-       -MT "$(ObjDir)/$*.ll" -MT "$(ObjDir)/$*.bc.d"
-
-# If the build succeeded, move the dependency file over, otherwise
-# remove it.
-BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d"; \
-                     else $(RM) "$(ObjDir)/$*.bc.d.tmp"; exit 1; fi
-
-$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
-       $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
-       $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
-                       $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
-               $(BC_DEPEND_MOVEFILE)
-
-$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
-       $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
-       $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
-                       $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
-               $(BC_DEPEND_MOVEFILE)
-
-$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
-       $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
-       $(Verb) if $(BCCompile.CXX) $(BC_DEPEND_OPTIONS) \
-                       $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
-               $(BC_DEPEND_MOVEFILE)
-
-$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
-       $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
-       $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
-                       $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
-               $(BC_DEPEND_MOVEFILE)
-
-$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
-       $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
-       $(Verb) if $(BCCompile.C) $(BC_DEPEND_OPTIONS) \
-                       $< -o $(ObjDir)/$*.ll -S $(LLVMCC_EMITIR_FLAG) ; \
-               $(BC_DEPEND_MOVEFILE)
-
 # Provide alternate rule sets if dependencies are disabled
 else
 
-$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.o: %.cpp $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.CXX) $< -o $@
 
-$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.o: %.mm $(COMPILE_DEPS)
        $(Echo) "Compiling $*.mm for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.CXX) $< -o $@
 
-$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.o: %.cc $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.CXX) $< -o $@
 
-$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.o: %.c $(COMPILE_DEPS)
        $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.C) $< -o $@
 
-$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.o: %.m $(COMPILE_DEPS)
        $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.C) $< -o $@
-
-$(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
-       $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
-       $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
-
-$(ObjDir)/%.ll: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
-       $(Echo) "Compiling $*.mm for $(BuildMode) build (bytecode)"
-       $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
-
-$(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
-       $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
-       $(BCCompile.CXX) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
-
-$(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
-       $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
-       $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
-
-$(ObjDir)/%.ll: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCC)
-       $(Echo) "Compiling $*.m for $(BuildMode) build (bytecode)"
-       $(BCCompile.C) $< -o $@ -S $(LLVMCC_EMITIR_FLAG)
-
 endif
 
 
 ## Rules for building preprocessed (.i/.ii) outputs.
-$(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
+$(BuildMode)/%.ii: %.cpp $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
        $(Verb) $(Preprocess.CXX) $< -o $@
 
-$(BuildMode)/%.ii: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
+$(BuildMode)/%.ii: %.mm $(COMPILE_DEPS)
        $(Echo) "Compiling $*.mm for $(BuildMode) build to .ii file"
        $(Verb) $(Preprocess.CXX) $< -o $@
 
-$(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
+$(BuildMode)/%.ii: %.cc $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
        $(Verb) $(Preprocess.CXX) $< -o $@
 
-$(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
+$(BuildMode)/%.i: %.c $(COMPILE_DEPS)
        $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
        $(Verb) $(Preprocess.C) $< -o $@
 
-$(BuildMode)/%.i: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
+$(BuildMode)/%.i: %.m $(COMPILE_DEPS)
        $(Echo) "Compiling $*.m for $(BuildMode) build to .i file"
        $(Verb) $(Preprocess.C) $< -o $@
 
 
-$(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.s: %.cpp $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.CXX) $< -o $@ -S
 
-$(ObjDir)/%.s: %.mm $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.s: %.mm $(COMPILE_DEPS)
        $(Echo) "Compiling $*.mm to asm for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.CXX) $< -o $@ -S
 
-$(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.s: %.cc $(COMPILE_DEPS)
        $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.CXX) $< -o $@ -S
 
-$(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.s: %.c $(COMPILE_DEPS)
        $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.C) $< -o $@ -S
 
-$(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
+$(ObjDir)/%.s: %.m $(COMPILE_DEPS)
        $(Echo) "Compiling $*.m to asm for $(BuildMode) build" $(PIC_FLAG)
        $(Compile.C) $< -o $@ -S
 
-
-# make the C and C++ compilers strip debug info out of bytecode libraries.
-ifdef DEBUG_RUNTIME
-$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
-       $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
-       $(Verb) $(LOPT) $< -std-compile-opts -o $@
-else
-$(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LOPT)
-       $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
-       $(Verb) $(LOPT) $< -std-compile-opts -strip-debug -o $@
-endif
-
-
-#---------------------------------------------------------
-# Provide rule to build .bc files from .ll sources,
-# regardless of dependencies
-#---------------------------------------------------------
-$(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
-       $(Echo) "Compiling $*.ll for $(BuildMode) build"
-       $(Verb) $(LLVMAS) $< -f -o $@
-
 ###############################################################################
 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
 ###############################################################################
@@ -1785,7 +1645,7 @@ TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
-           $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
+           $(wildcard $(LLVM_SRC_ROOT)/include/llvm/IR/Intrinsics*.td)
 
 # All .inc.tmp files depend on the .td files.
 $(INCTMPFiles) : $(TDFiles)
@@ -1818,18 +1678,13 @@ $(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
 $(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
 $(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
        $(Echo) "Building $(<F) MC code emitter with tblgen"
-       $(Verb) $(LLVMTableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
+       $(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
 
 $(TARGET:%=$(ObjDir)/%GenMCPseudoLowering.inc.tmp): \
 $(ObjDir)/%GenMCPseudoLowering.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
        $(Echo) "Building $(<F) MC Pseudo instruction expander with tblgen"
        $(Verb) $(LLVMTableGen) -gen-pseudo-lowering -o $(call SYSPATH, $@) $<
 
-$(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
-$(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
-       $(Echo) "Building $(<F) code emitter with tblgen"
-       $(Verb) $(LLVMTableGen) -gen-emitter -o $(call SYSPATH, $@) $<
-
 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
        $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
@@ -1840,11 +1695,6 @@ $(ObjDir)/%GenDisassemblerTables.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
        $(Echo) "Building $(<F) disassembly tables with tblgen"
        $(Verb) $(LLVMTableGen) -gen-disassembler -o $(call SYSPATH, $@) $<
 
-$(TARGET:%=$(ObjDir)/%GenEDInfo.inc.tmp): \
-$(ObjDir)/%GenEDInfo.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
-       $(Echo) "Building $(<F) enhanced disassembly information with tblgen"
-       $(Verb) $(LLVMTableGen) -gen-enhanced-disassembly-info -o $(call SYSPATH, $@) $<
-
 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
        $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
@@ -1873,8 +1723,14 @@ $(ObjDir)/%GenDFAPacketizer.inc.tmp : %.td $(ObjDir)/.dir $(LLVM_TBLGEN)
        $(Echo) "Building $(<F) DFA packetizer tables with tblgen"
        $(Verb) $(LLVMTableGen) -gen-dfa-packetizer -o $(call SYSPATH, $@) $<
 
+# Dump all the records to <target>.td.expanded.  This is useful for debugging.
+$(TARGET:%=%.td.expanded): \
+%.td.expanded : %.td $(LLVM_TBLGEN) $(TDFiles)
+       $(Echo) "Building a fully expanded version of $(<F)"
+       $(Verb) $(LLVMTableGen) -o $(call SYSPATH, $@) $<
+
 clean-local::
-       -$(Verb) $(RM) -f $(INCFiles)
+       -$(Verb) $(RM) -f $(INCFiles) $(TARGET).td.expanded
 
 endif # TARGET
 
@@ -1924,11 +1780,6 @@ ifndef IS_CLEANING_TARGET
 DependSourceFiles := $(basename $(filter %.cpp %.c %.cc %.m %.mm, $(Sources)))
 DependFiles := $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
 
-# Include bitcode dependency files if using bitcode libraries
-ifdef BYTECODE_LIBRARY
-DependFiles += $(DependSourceFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.bc.d)
-endif
-
 -include $(DependFiles) ""
 
 endif
@@ -1952,20 +1803,9 @@ check::
          $(EchoCmd) No test directory ; \
        fi
 
+# An alias dating from when both lit and DejaGNU test runners were used.
 check-lit:: check
 
-check-dg::
-       $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
-         if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
-           $(EchoCmd) Running test suite ; \
-           $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local-dg ; \
-         else \
-           $(EchoCmd) No Makefile in test directory ; \
-         fi ; \
-       else \
-         $(EchoCmd) No test directory ; \
-       fi
-
 check-all::
        $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
          if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
@@ -2307,6 +2147,8 @@ printvars::
        $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
        $(Echo) "ObjDir       : " '$(ObjDir)'
        $(Echo) "LibDir       : " '$(LibDir)'
+       $(Echo) "LibexecDir   : " '$(LibexecDir)'
+       $(Echo) "ShareDir     : " '$(ShareDir)'
        $(Echo) "ToolDir      : " '$(ToolDir)'
        $(Echo) "ExmplDir     : " '$(ExmplDir)'
        $(Echo) "Sources      : " '$(Sources)'