Change clang extra flags behavior

Move the clang extra flags into the *ClangGlobal*flags variables,
instead of adding them to every clang-based module. This means that
they're only applied when !no_default_compiler_flags, like make.

Change-Id: I43b1378d1d932d9aecfd8724a492d0d7716f7631
diff --git a/cc/cc.go b/cc/cc.go
index ce3a464..c8341d4 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -115,13 +115,13 @@
 	pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
 
 	pctx.StaticVariable("commonClangGlobalCflags",
-		strings.Join(clangFilterUnknownCflags(commonGlobalCflags), " "))
+		strings.Join(append(clangFilterUnknownCflags(commonGlobalCflags), "${clangExtraCflags}"), " "))
 	pctx.StaticVariable("deviceClangGlobalCflags",
-		strings.Join(clangFilterUnknownCflags(deviceGlobalCflags), " "))
+		strings.Join(append(clangFilterUnknownCflags(deviceGlobalCflags), "${clangExtraTargetCflags}"), " "))
 	pctx.StaticVariable("hostClangGlobalCflags",
 		strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
 	pctx.StaticVariable("commonClangGlobalCppflags",
-		strings.Join(clangFilterUnknownCflags(commonGlobalCppflags), " "))
+		strings.Join(append(clangFilterUnknownCflags(commonGlobalCppflags), "${clangExtraCppflags}"), " "))
 
 	// Everything in this list is a crime against abstraction and dependency tracking.
 	// Do not add anything to this list.
@@ -550,12 +550,6 @@
 		flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags)
 		flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags)
 
-		flags.CFlags = append(flags.CFlags, "${clangExtraCflags}")
-		flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
-		if ctx.Device() {
-			flags.CFlags = append(flags.CFlags, "${clangExtraTargetCflags}")
-		}
-
 		target := "-target " + toolchain.ClangTriple()
 		gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
 
@@ -577,6 +571,8 @@
 				toolchain.ClangCflags(),
 				"${commonClangGlobalCflags}",
 				fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice()))
+
+			flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
 		} else {
 			flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
 			flags.GlobalFlags = append(flags.GlobalFlags,
diff --git a/cc/clang.go b/cc/clang.go
index 6a01010..5e0302a 100644
--- a/cc/clang.go
+++ b/cc/clang.go
@@ -84,10 +84,6 @@
 		// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
 		"-Wno-unused-command-line-argument",
 
-		// Disable -Winconsistent-missing-override until we can clean up the existing
-		// codebase for it.
-		"-Wno-inconsistent-missing-override",
-
 		// Force clang to always output color diagnostics. Ninja will strip the ANSI
 		// color codes if it is not running in a terminal.
 		"-fcolor-diagnostics",
@@ -97,6 +93,12 @@
 		"-std=gnu99",
 	}, " "))
 
+	pctx.StaticVariable("clangExtraCppflags", strings.Join([]string{
+		// Disable -Winconsistent-missing-override until we can clean up the existing
+		// codebase for it.
+		"-Wno-inconsistent-missing-override",
+	}, " "))
+
 	pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
 		"-nostdlibinc",
 	}, " "))