rebuild.sh: Add --system=<list> option.

This patch adds a new option to rebuild.sh that allows one to select
the target systems to build binaries for. This also changes the default
to 64-bit only for all platforms, since we don't intend to release
32-bit QEMU binaries in the future.
diff --git a/scripts/common.shi b/scripts/common.shi
index 8e94bc4..aec0754 100644
--- a/scripts/common.shi
+++ b/scripts/common.shi
@@ -296,3 +296,24 @@
             ;;
     esac
 }
+
+# Convert commas into spaces.
+# $1: input string
+# Out: input string, with each comma replaced by a space.
+commas_to_spaces () {
+    printf "%s" "$1" | tr ',' ' '
+}
+
+
+# Return success iff item |$2| is in list |$1|.
+# $1: input list
+# $2: item to find in list.
+list_contains () {
+    local ITEM
+    for ITEM in $(commas_to_spaces "$1"); do
+        if [ "$ITEM" = "$2" ]; then
+            return 0
+        fi
+    done
+    return 1
+}
diff --git a/scripts/rebuild.sh b/scripts/rebuild.sh
index f0c5020..6697bf1 100755
--- a/scripts/rebuild.sh
+++ b/scripts/rebuild.sh
@@ -3,10 +3,28 @@
 . $(dirname "$0")/common.shi
 shell_import build-defaults.shi
 
+case $(uname -s) in
+    Linux)
+        BUILD_OS=linux-x86_64
+        DEFAULT_SYSTEMS="linux-x86_64,windows-x86_64"
+        ;;
+    Darwin)
+        BUILD_OS=darwin-x86_64
+        DEFAULT_SYSTEMS="darwin-x86_64"
+        ;;
+    *)
+        panic "Your operating system is not supported!"
+        ;;
+esac
+
+# List of valid target systems.
+VALID_SYSTEMS="linux-x86,linux-x86_64,windows-x86,windows-x86_64,darwin-x86,darwin-x86_64"
+
 OPT_BUILD_DIR=
 OPT_HELP=
 OPT_NO_CCACHE=
 OPT_NUM_JOBS=
+OPT_SYSTEM=
 
 for OPT; do
     OPTARG=$(expr "x$OPT" : "x[^=]*=\(.*\)" || true)
@@ -29,6 +47,9 @@
         --quiet)
             decrement_verbosity
             ;;
+        --system=*)
+            OPT_SYSTEM=$OPTARG
+            ;;
         --verbose)
             increment_verbosity
             ;;
@@ -61,6 +82,7 @@
     --help|-?           Print this message.
     --verbose           Increase verbosity.
     --quiet             Decrease verbosity.
+    --system=<list>     List of target systems [$DEFAULT_SYSTEMS].
     --build-dir=<path>  Use specific build directory (default is temporary).
     --no-ccache         Don't try to probe and use ccache during build.
     -j<count>           Run <count> parallel build jobs.
@@ -70,6 +92,24 @@
     exit 0
 fi
 
+if [ "$OPT_SYSTEM" ]; then
+    SYSTEMS=$(commas_to_spaces "$OPT_SYSTEM")
+else
+    SYSTEMS=$(commas_to_spaces "$DEFAULT_SYSTEMS")
+    log "Auto-config: --system='$SYSTEMS'"
+fi
+
+# Sanity check
+BAD_SYSTEMS=
+for SYSTEM in $SYSTEMS; do
+    if ! list_contains "$VALID_SYSTEMS" "$SYSTEM"; then
+        BAD_SYSTEMS="$BAD_SYSTEMS $SYSTEM"
+    fi
+done
+if [ "$BAD_SYSTEMS" ]; then
+    panic "Invalid system name(s): [$BAD_SYSTEMS], use one of: $VALID_SYSTEMS"
+fi
+
 if [ "$PARAM_COUNT" != 2 ]; then
     panic "This script requires two arguments, see --help for details."
 fi
@@ -127,18 +167,6 @@
 ARCHIVE_DIR=$(cd "$ARCHIVE_DIR" && pwd -P)
 log "Using archive directory: $ARCHIVE_DIR"
 
-case $(uname -s) in
-    Linux)
-        BUILD_OS=linux-x86_64
-        ;;
-    Darwin)
-        BUILD_OS=darwin-x86_64
-        ;;
-    *)
-        panic "Your operating system is not supported!"
-        ;;
-esac
-
 case $BUILD_OS in
     darwin-*)
         # Force the use of the 10.8 SDK on OS X, this
@@ -751,19 +779,8 @@
     unset LIBFFI_CFLAGS LIBFFI_LIBS GLIB_CFLAGS GLIB_LIBS
 }
 
-case $BUILD_OS in
-    linux-*)
-        build_qemu_android linux-x86
-        build_qemu_android linux-x86_64
-        build_qemu_android windows-x86
-        build_qemu_android windows-x86_64
-        ;;
-    darwin-*)
-        build_qemu_android darwin-x86_64
-        ;;
-    *)
-        panic "Your operating system is not supported!"
-        ;;
-esac
+for SYSTEM in $SYSTEMS; do
+    build_qemu_android $SYSTEM
+done
 
 echo "Done!"