Updates from make

Contains equivalent changes for:

  561b4c1 Set mcpu targets based on cpu variant.
  6a66a88 Stop encoding absolute paths in symbols
  63e3b02 Enable color output from gcc and clang
  eb3e3fa Use exported includes for libc++.
  3a0a891 Link libgtest_main before libgtest

Change-Id: I45a06c02e9af1d40f0c52f1e6a20d6cd382a27fb
diff --git a/cc/builder.go b/cc/builder.go
index 9c9bddd..f217082 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -44,10 +44,10 @@
 		blueprint.RuleParams{
 			Depfile:     "${out}.d",
 			Deps:        blueprint.DepsGCC,
-			Command:     "$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
+			Command:     "$relPwd $ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
 			Description: "cc $out",
 		},
-		"ccCmd", "cFlags")
+		"relPwd", "ccCmd", "cFlags")
 
 	ld = pctx.StaticRule("ld",
 		blueprint.RuleParams{
@@ -128,6 +128,15 @@
 	srcRoot := ctx.AConfig().SrcDir()
 	intermediatesRoot := ctx.AConfig().IntermediatesDir()
 
+	// We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the
+	// debug output. That way two builds in two different directories will
+	// create the same output.
+	relPwd := "PWD=/proc/self/cwd"
+	if ctx.Darwin() {
+		// /proc doesn't exist on Darwin
+		relPwd = ""
+	}
+
 	objFiles = make([]string, len(srcFiles))
 	objDir := common.ModuleObjDir(ctx)
 	if subdir != "" {
@@ -200,6 +209,7 @@
 			Args: map[string]string{
 				"cFlags": moduleCflags,
 				"ccCmd":  ccCmd,
+				"relPwd": relPwd,
 			},
 		})
 	}