Add support for preferred arch symlinks

Add a symlink_preferred_arch property to binaries to allow compiling the
binary for multiple architectures and then creating a symlink to the
preferred archicture, for example dalvikvm32 and dalvikvm64, with
dalvikvm symlinked to dalvikvm64.

Test: mmma -j art/dalvikvm
Change-Id: Ied15f2be9d52c01006fe8ac207c175b78558eab1
diff --git a/cc/binary.go b/cc/binary.go
index 2dbce66..38fc938 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -34,6 +34,9 @@
 
 	// if set, add an extra objcopy --prefix-symbols= step
 	Prefix_symbols string
+
+	// if set, install a symlink to the preferred architecture
+	Symlink_preferred_arch bool
 }
 
 func init() {
@@ -59,6 +62,7 @@
 
 type binaryDecorator struct {
 	*baseLinker
+	*baseInstaller
 	stripper
 
 	Properties BinaryLinkerProperties
@@ -137,11 +141,12 @@
 func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
 	module := newModule(hod, android.MultilibFirst)
 	binary := &binaryDecorator{
-		baseLinker: NewBaseLinker(),
+		baseLinker:    NewBaseLinker(),
+		baseInstaller: NewBaseInstaller("bin", "", InstallInSystem),
 	}
 	module.compiler = NewBaseCompiler()
 	module.linker = binary
-	module.installer = NewBaseInstaller("bin", "", InstallInSystem)
+	module.installer = binary
 	return module, binary
 }
 
@@ -158,6 +163,22 @@
 			binary.Properties.Static_executable = nil
 		}
 	}
+
+	if binary.Properties.Symlink_preferred_arch {
+		if binary.Properties.Stem == "" && binary.Properties.Suffix == "" {
+			ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix")
+		}
+		var prefer bool
+		if ctx.Host() {
+			prefer = ctx.AConfig().HostPrefer32BitExecutables()
+		} else {
+			prefer = ctx.AConfig().DevicePrefer32BitExecutables()
+		}
+		if ctx.PrimaryArch() != prefer {
+			binary.baseInstaller.Properties.Symlinks = append(binary.baseInstaller.Properties.Symlinks,
+				ctx.ModuleName())
+		}
+	}
 }
 
 func (binary *binaryDecorator) static() bool {