Support stripping shared libraries and binaries

Strip all shared libraries and binaries by default.  Use a shell script
to wrap the long sequences of commands needed by some strip variants.

Change-Id: I465bf7cc48330913e60e24762fd55fa2a7731c26
diff --git a/cc/builder.go b/cc/builder.go
index ca8bc75..10c8508 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -101,6 +101,18 @@
 		},
 		"objcopyCmd", "prefix")
 
+	stripPath = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
+
+	strip = pctx.StaticRule("strip",
+		blueprint.RuleParams{
+			Depfile:     "${out}.d",
+			Deps:        blueprint.DepsGCC,
+			Command:     "CROSS_COMPILE=$crossCompile $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
+			CommandDeps: []string{"$stripPath"},
+			Description: "strip $out",
+		},
+		"args", "crossCompile")
+
 	copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
 
 	copyGccLib = pctx.StaticRule("copyGccLib",
@@ -138,6 +150,10 @@
 	nocrt       bool
 	toolchain   Toolchain
 	clang       bool
+
+	stripKeepSymbols       bool
+	stripKeepMiniDebugInfo bool
+	stripAddGnuDebuglink   bool
 }
 
 // Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
@@ -397,6 +413,32 @@
 	})
 }
 
+func TransformStrip(ctx common.AndroidModuleContext, inputFile common.Path,
+	outputFile common.WritablePath, flags builderFlags) {
+
+	crossCompile := gccCmd(flags.toolchain, "")
+	args := ""
+	if flags.stripAddGnuDebuglink {
+		args += " --add-gnu-debuglink"
+	}
+	if flags.stripKeepMiniDebugInfo {
+		args += " --keep-mini-debug-info"
+	}
+	if flags.stripKeepSymbols {
+		args += " --keep-symbols"
+	}
+
+	ctx.ModuleBuild(pctx, common.ModuleBuildParams{
+		Rule:   strip,
+		Output: outputFile,
+		Input:  inputFile,
+		Args: map[string]string{
+			"crossCompile": crossCompile,
+			"args":         args,
+		},
+	})
+}
+
 func CopyGccLib(ctx common.AndroidModuleContext, libName string,
 	flags builderFlags, outputFile common.WritablePath) {