android-rebuild.sh: Add --out-dir=<path> option.

This patch adds an option to android-rebuild.sh and
android-configure.sh which allows one to specify a specific
output directory for all objects / binaries, instead of using
the default of 'objs' under the current source directory.

Tested for both regular and mingw builds.

Change-Id: I8c5ddfac8fb9899a2ff59a43e6cb5b9d8c45cef1
diff --git a/android-configure.sh b/android-configure.sh
index 64f2f96..bb09011 100755
--- a/android-configure.sh
+++ b/android-configure.sh
@@ -20,6 +20,7 @@
 OPTION_DEBUG=no
 OPTION_IGNORE_AUDIO=no
 OPTION_NO_PREBUILTS=no
+OPTION_OUT_DIR=
 OPTION_HELP=no
 OPTION_STATIC=no
 OPTION_MINGW=no
@@ -57,6 +58,8 @@
   ;;
   --no-strip) OPTION_NO_STRIP=yes
   ;;
+  --out-dir=*) OPTION_OUT_DIR=$optarg
+  ;;
   --ignore-audio) OPTION_IGNORE_AUDIO=yes
   ;;
   --no-prebuilts) OPTION_NO_PREBUILTS=yes
@@ -92,6 +95,7 @@
     echo "  --debug                  enable debug (-O0 -g) build"
     echo "  --ignore-audio           ignore audio messages (may build sound-less emulator)"
     echo "  --no-prebuilts           do not use prebuilt libraries and compiler"
+    echo "  --out-dir=<path>         use specific output directory [objs/]"
     echo "  --mingw                  build Windows executable on Linux"
     echo "  --static                 build a completely static executable"
     echo "  --verbose                verbose configuration"
@@ -169,6 +173,14 @@
     enable_cygwin
 fi
 
+if [ "$OPTION_OUT_DIR" ]; then
+    OUT_DIR="$OPTION_OUT_DIR"
+    mkdir -p "$OUT_DIR" || panic "Could not create output directory: $OUT_DIR"
+else
+    OUT_DIR=objs
+    log "Auto-config: --out-dir=objs"
+fi
+
 # Are we running in the Android build system ?
 check_android_build
 
@@ -262,10 +274,10 @@
     if [ ! -d "$PCBIOS_DIR" ]; then
         log "PC Bios    : Could not find prebuilts directory."
     else
-        mkdir -p objs/lib/pc-bios
+        mkdir -p $OUT_DIR/lib/pc-bios
         for BIOS_FILE in bios.bin vgabios-cirrus.bin; do
             log "PC Bios    : Copying $BIOS_FILE"
-            cp -f $PCBIOS_DIR/$BIOS_FILE objs/lib/pc-bios/$BIOS_FILE
+            cp -f $PCBIOS_DIR/$BIOS_FILE $OUT_DIR/lib/pc-bios/$BIOS_FILE
         done
     fi
 fi
@@ -458,7 +470,7 @@
 # create the objs directory that is going to contain all generated files
 # including the configuration ones
 #
-mkdir -p objs
+mkdir -p $OUT_DIR
 
 ###
 ###  Compiler probe
@@ -546,7 +558,7 @@
     esac
 fi
 
-create_config_mk
+create_config_mk "$OUT_DIR"
 echo "" >> $config_mk
 echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
 echo "HOST_EXEEXT       := $TARGET_EXEEXT" >> $config_mk
@@ -607,7 +619,7 @@
 
 # Build the config-host.h file
 #
-config_h=objs/config-host.h
+config_h=$OUT_DIR/config-host.h
 cat > $config_h <<EOF
 /* This file was autogenerated by '$PROGNAME' */