When loading from a constant, fold inttoptr if the integer type and the resulting...
[oota-llvm.git] / Makefile.rules
index b1744f13bfa31175de7a45d12bb5715825419284..eab886190cce6deb3a9cf9fe571fb7ea4dd37037 100644 (file)
@@ -129,11 +129,8 @@ reconfigure:
          $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
          $(ConfigStatusScript)
 
-# FIXME: The {PIC16,MSP430}/AsmPrinter line here is a hack to force a reconfigure to pick
-# up AsmPrinter changes. Remove it after a reasonable delay from 2009-08-13.
-
 .PRECIOUS: $(ConfigStatusScript)
-$(ConfigStatusScript): $(ConfigureScript) $(LLVM_SRC_ROOT)/lib/Target/PIC16/AsmPrinter/Makefile $(LLVM_SRC_ROOT)/lib/Target/MSP430/AsmPrinter/Makefile
+$(ConfigStatusScript): $(ConfigureScript)
        $(Echo) Reconfiguring with $<
        $(Verb) cd $(PROJ_OBJ_ROOT) && \
          if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
@@ -161,9 +158,13 @@ endif
 # If the Makefile in the source tree has been updated, copy it over into the
 # build tree. But, only do this if the source and object makefiles differ
 #------------------------------------------------------------------------
+ifndef PROJ_MAKEFILE
+PROJ_MAKEFILE := $(PROJ_SRC_DIR)/Makefile
+endif
+
 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
 
-Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
+Makefile: $(PROJ_MAKEFILE) $(ExtraMakefiles)
        $(Echo) "Updating Makefile"
        $(Verb) $(MKDIR) $(@D)
        $(Verb) $(CP) -f $< $@
@@ -171,7 +172,7 @@ Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
 # Copy the Makefile.* files unless we're in the root directory which avoids
 # the copying of Makefile.config.in or other things that should be explicitly
 # taken care of.
-$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
+$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_MAKEFILE)%
        @case '$?' in \
           *Makefile.rules) ;; \
           *.in) ;; \
@@ -196,102 +197,15 @@ install-local:: all-local
 install-bytecode:: install-bytecode-local
 
 ###############################################################################
-# LLVMC: Provide rules for compiling llvmc plugins
+# LLVMC: Provide rules for compiling llvmc-based driver
 ###############################################################################
 
-ifdef LLVMC_PLUGIN
-
-LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
-CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
-
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-  LD.Flags += -lCompilerDriver
-endif
-
-# Build a dynamic library if the user runs `make` directly from the plugin
-# directory.
-ifndef LLVMC_BUILTIN_PLUGIN
-  LOADABLE_MODULE = 1
-endif
-
-# TableGen stuff...
-ifneq ($(BUILT_SOURCES),)
-  LLVMC_BUILD_AUTOGENERATED_INC=1
-endif
-
-endif # LLVMC_PLUGIN
-
 ifdef LLVMC_BASED_DRIVER
 
 TOOLNAME = $(LLVMC_BASED_DRIVER)
 
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-  LD.Flags += -lCompilerDriver
-else
-  LLVMLIBS = CompilerDriver.a
-  LINK_COMPONENTS = support system
-endif
-
-# Preprocessor magic that generates references to static variables in built-in
-# plugins.
-ifneq ($(LLVMC_BUILTIN_PLUGINS),)
-
-USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
-
-LLVMC_BUILTIN_PLUGIN_1 = $(word 1, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_2 = $(word 2, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_3 = $(word 3, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_4 = $(word 4, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_5 = $(word 5, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_6 = $(word 6, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_7 = $(word 7, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_8 = $(word 8, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_9 = $(word 9, $(LLVMC_BUILTIN_PLUGINS))
-LLVMC_BUILTIN_PLUGIN_10 = $(word 10, $(LLVMC_BUILTIN_PLUGINS))
-
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_1),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_1=$(LLVMC_BUILTIN_PLUGIN_1)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_2),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_2=$(LLVMC_BUILTIN_PLUGIN_2)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_3),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_3=$(LLVMC_BUILTIN_PLUGIN_3)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_4),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_4=$(LLVMC_BUILTIN_PLUGIN_4)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_5),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_5)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_6),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_6)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_7),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_7)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_8),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_8)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_9),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_9)
-endif
-
-ifneq ($(LLVMC_BUILTIN_PLUGIN_10),)
-CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_10)
-endif
-
-
-endif
+LLVMLIBS = CompilerDriver.a
+LINK_COMPONENTS = support
 
 endif # LLVMC_BASED_DRIVER
 
@@ -387,7 +301,7 @@ ifneq ($(REQUIRES_RTTI), 1)
   CXX.Flags += -fno-rtti
 endif
 
-ifdef ENABLE_COVERAGE
+ifeq ($(ENABLE_COVERAGE),1)
   BuildMode := $(BuildMode)+Coverage
   CXX.Flags += -ftest-coverage -fprofile-arcs
   C.Flags   += -ftest-coverage -fprofile-arcs
@@ -395,17 +309,17 @@ endif
 
 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
 # then disable assertions by defining the appropriate preprocessor symbols.
-ifndef DISABLE_ASSERTIONS
+ifeq ($(DISABLE_ASSERTIONS),1)
+  CPP.Defines += -DNDEBUG
+else
   BuildMode := $(BuildMode)+Asserts
   CPP.Defines += -D_DEBUG
-else
-  CPP.Defines += -DNDEBUG
 endif
 
 # If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
 # configured), then enable expensive checks by defining the
 # appropriate preprocessor symbols.
-ifdef ENABLE_EXPENSIVE_CHECKS
+ifeq ($(ENABLE_EXPENSIVE_CHECKS),1)
   BuildMode := $(BuildMode)+Checks
   CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
 endif
@@ -474,12 +388,21 @@ ifeq ($(ENABLE_PIC),0)
   CXX.Flags     += -fPIC
   CPP.BaseFlags += -fPIC
 endif
-endif
 
-ifeq ($(ARCH),Alpha)
   LD.Flags += -Wl,--no-relax
 endif
 
+# GNU ld/PECOFF accepts but ignores them below;
+#   --version-script
+#   --export-dynamic
+#   --rpath
+# FIXME: autoconf should be aware of them.
+ifneq (,$(filter $(HOST_OS),Cygwin MingW))
+  HAVE_LINK_VERSION_SCRIPT := 0
+  RPATH :=
+  RDYNAMIC := -Wl,--export-all-symbols
+endif
+
 #--------------------------------------------------------------------
 # Directory locations
 #--------------------------------------------------------------------
@@ -497,6 +420,26 @@ LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
 
+#--------------------------------------------------------------------
+# Locations of shared libraries
+#--------------------------------------------------------------------
+
+SharedPrefix     := lib
+SharedLibDir     := $(LibDir)
+LLVMSharedLibDir := $(LLVMLibDir)
+
+# Win32.DLL prefers to be located on the "PATH" of binaries.
+ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+  SharedLibDir     := $(ToolDir)
+  LLVMSharedLibDir := $(LLVMToolDir)
+
+  ifeq ($(HOST_OS),Cygwin)
+    SharedPrefix  := cyg
+  else
+    SharedPrefix  :=
+  endif
+endif
+
 #--------------------------------------------------------------------
 # LLVM Capable Compiler
 #--------------------------------------------------------------------
@@ -564,18 +507,13 @@ ifeq ($(HOST_OS),Darwin)
   # 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/')
 
-  SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined,suppress \
-                    -dynamiclib
+  LoadableModuleOptions := -Wl,-flat_namespace -Wl,-undefined,suppress
+  SharedLinkOptions := -dynamiclib
   ifneq ($(ARCH),ARM)
     SharedLinkOptions += -mmacosx-version-min=$(DARWIN_VERSION)
   endif
 else
-  ifeq ($(HOST_OS),Cygwin)
-    SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
-                      -Wl,--enable-auto-import -Wl,--enable-auto-image-base
-  else
-    SharedLinkOptions=-shared
-  endif
+  SharedLinkOptions=-shared
 endif
 
 ifeq ($(TARGET_OS),Darwin)
@@ -585,11 +523,9 @@ ifeq ($(TARGET_OS),Darwin)
 endif
 
 ifdef SHARED_LIBRARY
+ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
 ifneq ($(HOST_OS),Darwin)
   LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
-else
-ifneq ($(DARWIN_MAJVERS),4)
-  LD.Flags += $(RPATH) -Wl,$(LibDir)
 endif
 endif
 endif
@@ -617,14 +553,21 @@ ifndef KEEP_SYMBOLS
   Install.StripFlag += -s
 endif
 
+ifdef TOOL_NO_EXPORTS
+  DynamicFlags :=
+else
+  DynamicFlag := $(RDYNAMIC)
+endif
+
 # Adjust linker flags for building an executable
-ifneq ($(HOST_OS), $(filter $(HOST_OS), Darwin Cygwin MingW))
+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) $(RDYNAMIC)
+    LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(DynamicFlag)
   else
-    LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
+    LD.Flags += $(RPATH) -Wl,$(ToolDir) $(DynamicFlag)
   endif
 endif
 else
@@ -632,6 +575,7 @@ ifneq ($(DARWIN_MAJVERS),4)
   LD.Flags += $(RPATH) -Wl,@executable_path/../lib
 endif
 endif
+endif
 
 
 #----------------------------------------------------------
@@ -686,11 +630,11 @@ else
 endif
 
 ifeq ($(HOST_OS),SunOS)
-CPP.BaseFlags += -include llvm/System/Solaris.h
+CPP.BaseFlags += -include llvm/Support/Solaris.h
 endif
 
 ifeq ($(HOST_OS),AuroraUX)
-CPP.BaseFlags += -include llvm/System/Solaris.h
+CPP.BaseFlags += -include llvm/Support/Solaris.h
 endif # !HOST_OS - AuroraUX.
 
 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir)
@@ -958,6 +902,16 @@ LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
 endif
 
+# Loadable module for Win32 requires all symbols resolved for linking.
+# Then all symbols in LLVM.dll will be available.
+ifeq ($(ENABLE_SHARED),1)
+  ifdef LOADABLE_MODULE
+    ifneq (,$(filter $(HOST_OS),Cygwin MingW))
+      LINK_COMPONENTS += all
+    endif
+  endif
+endif
+
 ifndef IS_CLEANING_TARGET
 ifdef LINK_COMPONENTS
 
@@ -970,12 +924,28 @@ $(LLVM_CONFIG):
 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
 
 ifeq ($(ENABLE_SHARED), 1)
+# We can take the "auto-import" feature to get rid of using dllimport.
+ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+LLVMLibsOptions += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc \
+                   -L $(SharedLibDir)
+endif
 LLVMLibsOptions += -lLLVM-$(LLVMVersion)
-LLVMLibsPaths += $(LibDir)/libLLVM-$(LLVMVersion)$(SHLIBEXT)
+LLVMLibsPaths += $(SharedLibDir)/$(SharedPrefix)LLVM-$(LLVMVersion)$(SHLIBEXT)
 else
-LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
-LLVMLibsPaths   += $(LLVM_CONFIG) \
-                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
+
+ifndef NO_LLVM_CONFIG
+LLVMConfigLibs := $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)
+ifeq ($(LLVMConfigLibs),Error)
+$(error llvm-config --libs failed)
+endif
+LLVMLibsOptions += $(LLVMConfigLibs)
+LLVMConfigLibfiles := $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS) || echo Error)
+ifeq ($(LLVMConfigLibfiles),Error)
+$(error llvm-config --libfiles failed)
+endif
+LLVMLibsPaths += $(LLVM_CONFIG) $(LLVMConfigLibfiles)
+endif
+
 endif
 endif
 endif
@@ -1006,12 +976,25 @@ $(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
 clean-local::
        -$(Verb) $(RM) -f $(NativeExportsFile)
 else
+ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+# GNU ld Win32 accepts .DEF files that contain "DATA" entries.
+NativeExportsFile := $(ObjDir)/$(notdir $(EXPORTED_SYMBOL_FILE:.exports=.def))
+$(NativeExportsFile): $(EXPORTED_SYMBOL_FILE) $(ObjDir)/.dir
+       $(Echo) Generating $(notdir $@)
+       $(Verb) $(ECHO) "EXPORTS" > $@
+       $(Verb) $(CAT) $< >> $@
+clean-local::
+       -$(Verb) $(RM) -f $(NativeExportsFile)
+else
+# Default behavior: just use the exports file verbatim.
 NativeExportsFile := $(EXPORTED_SYMBOL_FILE)
 endif
 endif
+endif
 
 # Now add the linker command-line options to use the native export file.
 
+# Darwin
 ifeq ($(HOST_OS),Darwin)
 LLVMLibsOptions += -Wl,-exported_symbols_list,$(NativeExportsFile)
 endif
@@ -1021,6 +1004,12 @@ ifeq ($(HAVE_LINK_VERSION_SCRIPT),1)
 LLVMLibsOptions += -Wl,--version-script,$(NativeExportsFile)
 endif
 
+# Windows
+ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+# LLVMLibsOptions is invalidated at processing tools/llvm-shlib.
+SharedLinkOptions += $(NativeExportsFile)
+endif
+
 endif
 
 ###############################################################################
@@ -1094,12 +1083,14 @@ ifdef LIBRARYNAME
 # Make sure there isn't any extraneous whitespace on the LIBRARYNAME option
 LIBRARYNAME := $(strip $(LIBRARYNAME))
 ifdef LOADABLE_MODULE
-LibName.A  := $(LibDir)/$(LIBRARYNAME).a
-LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
+BaseLibName.A  := $(LIBRARYNAME).a
+BaseLibName.SO := $(LIBRARYNAME)$(SHLIBEXT)
 else
-LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
-LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
+BaseLibName.A  := lib$(LIBRARYNAME).a
+BaseLibName.SO := $(SharedPrefix)$(LIBRARYNAME)$(SHLIBEXT)
 endif
+LibName.A  := $(LibDir)/$(BaseLibName.A)
+LibName.SO := $(SharedLibDir)/$(BaseLibName.SO)
 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
 
@@ -1120,16 +1111,17 @@ endif
 ifdef LINK_LIBS_IN_SHARED
 ifdef LOADABLE_MODULE
 SharedLibKindMessage := "Loadable Module"
+SharedLinkOptions := $(LoadableModuleOptions) $(SharedLinkOptions)
 else
 SharedLibKindMessage := "Shared Library"
 endif
-$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
+$(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(SharedLibDir)/.dir
        $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
          $(notdir $@)
        $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
          $(ProjLibsOptions) $(LLVMLibsOptions) $(LIBS)
 else
-$(LibName.SO): $(ObjectsO) $(LibDir)/.dir
+$(LibName.SO): $(ObjectsO) $(SharedLibDir)/.dir
        $(Echo) Linking $(BuildMode) Shared Library $(notdir $@)
        $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
 endif
@@ -1146,21 +1138,23 @@ uninstall-local::
        $(Echo) Uninstall circumvented with NO_INSTALL
 else
 
-ifdef LOADABLE_MODULE
-DestSharedLib = $(DESTDIR)$(PROJ_libdir)/$(LIBRARYNAME)$(SHLIBEXT)
+# Win32.DLL prefers to be located on the "PATH" of binaries.
+ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+DestSharedLibDir := $(DESTDIR)$(PROJ_bindir)
 else
-DestSharedLib = $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
+DestSharedLibDir := $(DESTDIR)$(PROJ_libdir)
 endif
+DestSharedLib := $(DestSharedLibDir)/$(BaseLibName.SO)
 
 install-local:: $(DestSharedLib)
 
-$(DestSharedLib): $(LibName.SO) $(DESTDIR)$(PROJ_libdir)
+$(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 $(DESTDIR)$(PROJ_libdir)/lib$(LIBRARYNAME).*
+       -$(Verb) $(RM) -f $(DestSharedLibDir)/$(SharedPrefix)$(LIBRARYNAME).*
 endif
 endif
 
@@ -1342,6 +1336,18 @@ endif
 endif
 endif
 
+#---------------------------------------------------------
+# Tool Order File Support
+#---------------------------------------------------------
+
+ifeq ($(HOST_OS),Darwin)
+ifdef TOOL_ORDER_FINE
+
+LD.Flags += -Wl,-order_file,$(TOOL_ORDER_FILE)
+
+endif
+endif
+
 #---------------------------------------------------------
 # Tool Version Info Support
 #---------------------------------------------------------
@@ -1395,7 +1401,7 @@ $(ToolAliasBuildPath): $(ToolBuildPath)
        $(Echo) Creating $(BuildMode) Alias $(TOOLALIAS) $(StripWarnMsg)
        $(Verb) $(RM) -f $(ToolAliasBuildPath)
        $(Verb) $(AliasTool) $(TOOLEXENAME) $(ToolAliasBuildPath)
-       $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLNAME) \
+       $(Echo) ======= Finished Creating $(BuildMode) Alias $(TOOLALIAS) \
           $(StripWarnMsg)
 endif
 
@@ -1460,27 +1466,27 @@ 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_SRC_DIR)/Makefile
+$(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
        $(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_SRC_DIR)/Makefile
+$(ObjDir)/%.o: %.mm $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
        $(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_SRC_DIR)/Makefile
+$(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
        $(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_SRC_DIR)/Makefile
+$(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
        $(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_SRC_DIR)/Makefile
+$(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES) $(PROJ_MAKEFILE)
        $(Echo) "Compiling $*.m for $(BuildMode) build" $(PIC_FLAG)
        $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
                $(DEPEND_MOVEFILE)
@@ -1500,31 +1506,31 @@ BC_DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.bc.d.tmp" "$(ObjDir)/$*.bc.d";
 $(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 -emit-llvm ; \
+                       $< -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 -emit-llvm ; \
+                       $< -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 -emit-llvm ; \
+                       $< -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 -emit-llvm ; \
+                       $< -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 -emit-llvm ; \
+                       $< -o $(ObjDir)/$*.ll -S -$(LLVMCC_EMITIR_FLAG) ; \
                $(BC_DEPEND_MOVEFILE)
 
 # Provide alternate rule sets if dependencies are disabled
@@ -1552,23 +1558,23 @@ $(ObjDir)/%.o: %.m $(ObjDir)/.dir $(BUILT_SOURCES)
 
 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMCXX)
        $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
-       $(BCCompile.CXX) $< -o $@ -S -emit-llvm
+       $(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 -emit-llvm
+       $(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 -emit-llvm
+       $(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 -emit-llvm
+       $(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 -emit-llvm
+       $(BCCompile.C) $< -o $@ -S -$(LLVMCC_EMITIR_FLAG)
 
 endif
 
@@ -1644,7 +1650,7 @@ ifdef TARGET
 TABLEGEN_INC_FILES_COMMON = 1
 endif
 
-ifdef LLVMC_BUILD_AUTOGENERATED_INC
+ifdef LLVMC_BASED_DRIVER
 TABLEGEN_INC_FILES_COMMON = 1
 endif
 
@@ -1718,6 +1724,11 @@ $(ObjDir)/%GenAsmMatcher.inc.tmp : %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) assembly matcher with tblgen"
        $(Verb) $(TableGen) -gen-asm-matcher -o $(call SYSPATH, $@) $<
 
+$(TARGET:%=$(ObjDir)/%GenMCCodeEmitter.inc.tmp): \
+$(ObjDir)/%GenMCCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
+       $(Echo) "Building $(<F) MC code emitter with tblgen"
+       $(Verb) $(TableGen) -gen-emitter -mc-emitter -o $(call SYSPATH, $@) $<
+
 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
        $(Echo) "Building $(<F) code emitter with tblgen"
@@ -1768,20 +1779,26 @@ clean-local::
 
 endif # TARGET
 
-ifdef LLVMC_BUILD_AUTOGENERATED_INC
+ifdef LLVMC_BASED_DRIVER
+
+TDSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
+               $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
 
-LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
-       $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
+TDCommon := $(strip $(wildcard \
+               $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
 
-TDFiles := $(LLVMCPluginSrc) \
-       $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
+TDFiles := $(TDSrc) $(TDCommon)
 
-$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
-                               $(TBLGEN) $(TD_COMMON)
-       $(Echo) "Building LLVMC configuration library with tblgen"
+$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
+
+$(ObjDir)/%.inc.tmp: %.td $(ObjDir)/.dir
+       $(Echo) "Building LLVMC compilation graph description with tblgen"
        $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
 
-endif # LLVMC_BUILD_AUTOGENERATED_INC
+clean-local::
+       -$(Verb) $(RM) -f $(INCFiles)
+
+endif # LLVMC_BASED_DRIVER
 
 ###############################################################################
 # OTHER RULES: Other rules needed