Merge "Initial README.md"
diff --git a/android/androidmk.go b/android/androidmk.go
index 8d2951d..7d7707f 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -146,7 +146,7 @@
 	}
 
 	if data.SubName != "" {
-		name += "_" + data.SubName
+		name += data.SubName
 	}
 
 	if data.Custom != nil {
diff --git a/android/arch.go b/android/arch.go
index 08b7b1f..13fcb29 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -814,7 +814,7 @@
 		{"mips", "mips32-fp", "", []string{"mips"}},
 		{"mips", "mips32r2-fp", "", []string{"mips"}},
 		{"mips", "mips32r2-fp-xburst", "", []string{"mips"}},
-		{"mips", "mips32r6", "", []string{"mips"}},
+		//{"mips", "mips32r6", "", []string{"mips"}},
 		// mips32r2dsp[r2]-fp fails in the assembler for divdf3.c in compiler-rt:
 		// (same errors in make and soong)
 		//   Error: invalid operands `mtlo $ac0,$11'
diff --git a/android/config.go b/android/config.go
index 0f65410..ae04756 100644
--- a/android/config.go
+++ b/android/config.go
@@ -20,6 +20,7 @@
 	"os"
 	"path/filepath"
 	"runtime"
+	"strconv"
 	"strings"
 	"sync"
 
@@ -278,7 +279,7 @@
 }
 
 func (c *config) PlatformSdkVersion() string {
-	return "22"
+	return strconv.Itoa(*c.ProductVariables.Platform_sdk_version)
 }
 
 func (c *config) BuildNumber() string {
diff --git a/android/defs.go b/android/defs.go
index be28e8b..9c6527d 100644
--- a/android/defs.go
+++ b/android/defs.go
@@ -52,6 +52,13 @@
 		},
 		"cpFlags")
 
+	// A timestamp touch rule.
+	Touch = pctx.StaticRule("Touch",
+		blueprint.RuleParams{
+			Command:     "touch $out",
+			Description: "touch $out",
+		})
+
 	// A symlink rule.
 	Symlink = pctx.StaticRule("Symlink",
 		blueprint.RuleParams{
diff --git a/android/variable.go b/android/variable.go
index a2313d5..b0639ae 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -115,7 +115,7 @@
 
 func (v *productVariables) SetDefaultConfig() {
 	*v = productVariables{
-		Platform_sdk_version:       intPtr(22),
+		Platform_sdk_version:       intPtr(23),
 		HostArch:                   stringPtr("x86_64"),
 		HostSecondaryArch:          stringPtr("x86"),
 		DeviceName:                 stringPtr("flounder"),
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 7f18155..70e1f47 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -134,7 +134,7 @@
 func (test *testBinaryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
 	test.binaryLinker.AndroidMk(ctx, ret)
 	if Bool(test.testLinker.Properties.Test_per_src) {
-		ret.SubName = test.binaryLinker.Properties.Stem
+		ret.SubName = "_" + test.binaryLinker.Properties.Stem
 	}
 }
 
diff --git a/cc/arm64_device.go b/cc/arm64_device.go
index 8e7c57b..b951c1a 100644
--- a/cc/arm64_device.go
+++ b/cc/arm64_device.go
@@ -103,6 +103,7 @@
 		"-isystem ${LibcRoot}/arch-arm64/include",
 		"-isystem ${LibcRoot}/include",
 		"-isystem ${LibcRoot}/kernel/uapi",
+		"-isystem ${LibcRoot}/kernel/android/uapi",
 		"-isystem ${LibcRoot}/kernel/common",
 		"-isystem ${LibcRoot}/kernel/uapi/asm-arm64",
 	}, " "))
diff --git a/cc/arm_device.go b/cc/arm_device.go
index 1624cfc..e985a38 100644
--- a/cc/arm_device.go
+++ b/cc/arm_device.go
@@ -172,6 +172,7 @@
 		"-isystem ${LibcRoot}/arch-arm/include",
 		"-isystem ${LibcRoot}/include",
 		"-isystem ${LibcRoot}/kernel/uapi",
+		"-isystem ${LibcRoot}/kernel/android/uapi",
 		"-isystem ${LibcRoot}/kernel/common",
 		"-isystem ${LibcRoot}/kernel/uapi/asm-arm",
 	}, " "))
diff --git a/cc/builder.go b/cc/builder.go
index 4efcc27..49f8871 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -369,11 +369,11 @@
 
 	libFlagsList = append(libFlagsList, staticLibs.Strings()...)
 
-	if groupLate && len(lateStaticLibs) > 0 {
+	if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 {
 		libFlagsList = append(libFlagsList, "-Wl,--start-group")
 	}
 	libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...)
-	if groupLate && len(lateStaticLibs) > 0 {
+	if groupLate && !ctx.Darwin() && len(lateStaticLibs) > 0 {
 		libFlagsList = append(libFlagsList, "-Wl,--end-group")
 	}
 
diff --git a/cc/cc.go b/cc/cc.go
index f8723bb..b5545fc 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -193,7 +193,7 @@
 		if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
 			return override, nil
 		}
-		return "clang-2812033", nil
+		return "clang-3016494", nil
 	})
 	pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}")
 	pctx.StaticVariable("clangBin", "${clangPath}/bin")
@@ -1337,7 +1337,7 @@
 	deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
 
 	if !ctx.sdk() && ctx.ModuleName() != "libcompiler_rt-extras" {
-		deps.StaticLibs = append(deps.StaticLibs, "libcompiler_rt-extras")
+		deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt-extras")
 	}
 
 	if ctx.Device() {
diff --git a/cc/clang.go b/cc/clang.go
index e9dca32..be2bfe1 100644
--- a/cc/clang.go
+++ b/cc/clang.go
@@ -88,6 +88,9 @@
 		// Force clang to always output color diagnostics. Ninja will strip the ANSI
 		// color codes if it is not running in a terminal.
 		"-fcolor-diagnostics",
+
+		// http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374
+		"-Wno-expansion-to-defined",
 	}, " "))
 
 	pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
@@ -98,6 +101,10 @@
 		// Disable -Winconsistent-missing-override until we can clean up the existing
 		// codebase for it.
 		"-Wno-inconsistent-missing-override",
+
+		// Bug: http://b/29823425 Disable -Wnull-dereference until the
+		// new instances detected by this warning are fixed.
+		"-Wno-null-dereference",
 	}, " "))
 
 	pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
@@ -106,7 +113,10 @@
 
 	pctx.StaticVariable("clangExtraNoOverrideCflags", strings.Join([]string{
 		"-Werror=address-of-temporary",
-		"-Werror=null-dereference",
+		// Bug: http://b/29823425 Disable -Wnull-dereference until the
+		// new cases detected by this warning in Clang r271374 are
+		// fixed.
+		//"-Werror=null-dereference",
 		"-Werror=return-type",
 	}, " "))
 }
diff --git a/cc/mips64_device.go b/cc/mips64_device.go
index 474f284..19f9caf 100644
--- a/cc/mips64_device.go
+++ b/cc/mips64_device.go
@@ -104,6 +104,7 @@
 		"-isystem ${LibcRoot}/arch-mips64/include",
 		"-isystem ${LibcRoot}/include",
 		"-isystem ${LibcRoot}/kernel/uapi",
+		"-isystem ${LibcRoot}/kernel/android/uapi",
 		"-isystem ${LibcRoot}/kernel/common",
 		"-isystem ${LibcRoot}/kernel/uapi/asm-mips",
 	}, " "))
diff --git a/cc/mips_device.go b/cc/mips_device.go
index 7204e36..ac6f2b1 100644
--- a/cc/mips_device.go
+++ b/cc/mips_device.go
@@ -141,6 +141,7 @@
 		"-isystem ${LibcRoot}/arch-mips/include",
 		"-isystem ${LibcRoot}/include",
 		"-isystem ${LibcRoot}/kernel/uapi",
+		"-isystem ${LibcRoot}/kernel/android/uapi",
 		"-isystem ${LibcRoot}/kernel/common",
 		"-isystem ${LibcRoot}/kernel/uapi/asm-mips",
 	}, " "))
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 172aae7..08ffff4 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -141,9 +141,10 @@
 			ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0])
 		}
 	}
-	if Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) ||
-		Bool(s.Thread) || Bool(s.Coverage) || Bool(s.Safestack) {
-		sanitize.Properties.SanitizerEnabled = true
+
+	if ctx.staticBinary() {
+		s.Address = nil
+		s.Thread = nil
 	}
 
 	if Bool(s.All_undefined) {
@@ -157,6 +158,11 @@
 		// TODO(ccross): error for compile_multilib = "32"?
 	}
 
+	if Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) ||
+		Bool(s.Thread) || Bool(s.Coverage) || Bool(s.Safestack) {
+		sanitize.Properties.SanitizerEnabled = true
+	}
+
 	if Bool(s.Coverage) {
 		if !Bool(s.Address) {
 			ctx.ModuleErrorf(`Use of "coverage" also requires "address"`)
diff --git a/cc/x86_64_device.go b/cc/x86_64_device.go
index 986dc86..a795ba7 100644
--- a/cc/x86_64_device.go
+++ b/cc/x86_64_device.go
@@ -152,6 +152,7 @@
 		"-isystem ${LibcRoot}/arch-x86_64/include",
 		"-isystem ${LibcRoot}/include",
 		"-isystem ${LibcRoot}/kernel/uapi",
+		"-isystem ${LibcRoot}/kernel/android/uapi",
 		"-isystem ${LibcRoot}/kernel/common",
 		"-isystem ${LibcRoot}/kernel/uapi/asm-x86",
 	}, " "))
diff --git a/cc/x86_darwin_host.go b/cc/x86_darwin_host.go
index 2894f7e..d514c14 100644
--- a/cc/x86_darwin_host.go
+++ b/cc/x86_darwin_host.go
@@ -81,6 +81,7 @@
 		"c",
 		"dl",
 		"m",
+		"ncurses",
 		"pthread",
 		"z",
 	}, "-l")
diff --git a/cc/x86_device.go b/cc/x86_device.go
index f16e68b..72689fb 100644
--- a/cc/x86_device.go
+++ b/cc/x86_device.go
@@ -171,6 +171,7 @@
 		"-isystem ${LibcRoot}/arch-x86/include",
 		"-isystem ${LibcRoot}/include",
 		"-isystem ${LibcRoot}/kernel/uapi",
+		"-isystem ${LibcRoot}/kernel/android/uapi",
 		"-isystem ${LibcRoot}/kernel/common",
 		"-isystem ${LibcRoot}/kernel/uapi/asm-x86",
 	}, " "))
diff --git a/cc/x86_windows_host.go b/cc/x86_windows_host.go
index cc0ef66..3a55dbf 100644
--- a/cc/x86_windows_host.go
+++ b/cc/x86_windows_host.go
@@ -76,6 +76,16 @@
 		"-m64",
 		"-L${windowsGccRoot}/${windowsGccTriple}/lib64",
 	}
+
+	windowsAvailableLibraries = addPrefix([]string{
+		"gdi32",
+		"imagehlp",
+		"ole32",
+		"psapi",
+		"userenv",
+		"uuid",
+		"ws2_32",
+	}, "-l")
 )
 
 const (
@@ -187,6 +197,10 @@
 	return ".exe"
 }
 
+func (t *toolchainWindows) AvailableLibraries() []string {
+	return windowsAvailableLibraries
+}
+
 var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
 var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}