From aa58d534e5f7d4db64c1bddd5d6b446e110ca7f3 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Tue, 18 Nov 2014 14:53:39 -0500
Subject: [PATCH 1/5] mk/stage0: complain instead of creating an empty file

If the expected rustc snapshot is not where we expect it to be,
complain and fail at that point rather than creating a empty rustc file
and continuing until we try to run it.
---
 mk/stage0.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mk/stage0.mk b/mk/stage0.mk
index e028bba73da..460a4a7f445 100644
--- a/mk/stage0.mk
+++ b/mk/stage0.mk
@@ -22,7 +22,7 @@ ifdef CFG_ENABLE_LOCAL_RUST
 else
 	$(Q)$(CFG_PYTHON) $(S)src/etc/get-snapshot.py $(CFG_BUILD) $(SNAPSHOT_FILE)
 endif
-	$(Q)touch $@
+	$(Q)if [ -e "$@" ]; then touch "$@"; else echo "ERROR: snapshot $@ not found"; exit 1; fi
 
 # For other targets, let the host build the target:
 

From 29cc7c2adf0bdbe00fc65ff0a7393668eead7a22 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Tue, 18 Nov 2014 16:32:03 -0500
Subject: [PATCH 2/5] mk/target: fix typo so we depend on the correct directory

Without this, if we we're using a non-standard host libdir, the target
bindir would not exist (and rustc would fail to write to the
non-existent directory).
---
 mk/target.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mk/target.mk b/mk/target.mk
index ed7d8bb497d..acdf780f105 100644
--- a/mk/target.mk
+++ b/mk/target.mk
@@ -116,7 +116,7 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
 		$$(foreach dep,$$(TOOL_DEPS_$(4)), \
 		    $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
 		$$(TSREQ$(1)_T_$(2)_H_$(3)) \
-		| $$(TBIN$(1)_T_$(4)_H_$(3))/
+		| $$(TBIN$(1)_T_$(2)_H_$(3))/
 	@$$(call E, rustc: $$@)
 	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg $(4)
 

From bc5a139baa928b8a440e9053a3d7e0d4cc932f98 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Tue, 18 Nov 2014 18:56:12 -0500
Subject: [PATCH 3/5] rustdoc: avoid supplying a bad default sysroot so the
 librustc code can calculate it properly

---
 src/librustdoc/core.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
index 21242e6f1e4..b040a4bfd2a 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -18,7 +18,6 @@ use rustc_trans::back::link;
 use syntax::{ast, ast_map, codemap, diagnostic};
 
 use std::cell::RefCell;
-use std::os;
 use std::collections::{HashMap, HashSet};
 use arena::TypedArena;
 
@@ -89,7 +88,7 @@ pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
     let warning_lint = lint::builtin::WARNINGS.name_lower();
 
     let sessopts = config::Options {
-        maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
+        maybe_sysroot: None,
         addl_lib_search_paths: RefCell::new(libs),
         crate_types: vec!(config::CrateTypeRlib),
         lint_opts: vec!((warning_lint, lint::Allow)),

From 9c320dd7afb1198247d8c3f92e4fe1a4ec464dfd Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Wed, 19 Nov 2014 19:54:24 -0500
Subject: [PATCH 4/5] configure: silence warning about LOCAL_RUST_ROOT being
 set

We have a default value for this ('/usr/local'), so this warning is
printed ALL the time unless one does --enable-local-rust. As a result,
it doesn't really help at all.
---
 configure | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/configure b/configure
index 35bba159208..749e296106a 100755
--- a/configure
+++ b/configure
@@ -701,11 +701,6 @@ then
     fi
     step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
     putvar CFG_LOCAL_RUST_ROOT
-else
-    if [ ! -z "$CFG_LOCAL_RUST_ROOT" ]
-    then
-       warn "Use of --local-rust-root without --enable-local-rust"
-    fi
 fi
 
 # Force freebsd to build with clang; gcc doesn't like us there

From 12749fc8ec3f110d3fb8057b955c7fab98f85730 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <dev@codyps.com>
Date: Thu, 20 Nov 2014 15:56:58 -0500
Subject: [PATCH 5/5] mk/rt: use CFG_LLVM_TARGET instead of plain target when
 calling llc

We add CFG_LLVM_TARGET_$(target) (which can be defined in any of the
mk/cfg/* files) and supply a default to the plain target name

CFG_LLVM_TARGET mirrors the value of llvm_target (aka llvm-target) in
the librustc_back runtime target specification.
---
 mk/main.mk | 7 +++++--
 mk/rt.mk   | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/mk/main.mk b/mk/main.mk
index 3df4d3bfa5e..2e759a15972 100644
--- a/mk/main.mk
+++ b/mk/main.mk
@@ -190,11 +190,14 @@ endif
 # Target-and-rule "utility variables"
 ######################################################################
 
-define DEF_X
+define DEF_FOR_TARGET
 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
+ifndef CFG_LLVM_TARGET_$(1)
+CFG_LLVM_TARGET_$(1) := $(1)
+endif
 endef
 $(foreach target,$(CFG_TARGET), \
-  $(eval $(call DEF_X,$(target))))
+  $(eval $(call DEF_FOR_TARGET,$(target))))
 
 # "Source" files we generate in builddir along the way.
 GENERATED :=
diff --git a/mk/rt.mk b/mk/rt.mk
index a7d6a6e825f..38aec836316 100644
--- a/mk/rt.mk
+++ b/mk/rt.mk
@@ -75,7 +75,7 @@ $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.ll $$(MKFILE_DEPS) \
 	@mkdir -p $$(@D)
 	@$$(call E, compile: $$@)
 	$$(Q)$$(LLC_$$(CFG_BUILD)) $$(CFG_LLC_FLAGS_$(1)) \
-	    -filetype=obj -mtriple=$(1) -relocation-model=pic -o $$@ $$<
+	    -filetype=obj -mtriple=$$(CFG_LLVM_TARGET_$(1)) -relocation-model=pic -o $$@ $$<
 
 $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.c $$(MKFILE_DEPS)
 	@mkdir -p $$(@D)