android-configure.sh: Add --qemu-prebuilts-dir=<path> option.

This adds a new option to android-configure.sh and android-rebuild.sh
that allows one to automatically prebuilt QEMU binaries under
objs/qemu/<system>/

This is necessary to properly emulate ARM64 system images at the
moment. The QEMU binaries must be rebuilt from the sources found
at https://qemu-android.googlesource.com/qemu-android, using the
'scripts/rebuild.sh' script from
https://qemu-android.googlesource.com/qemu-ranchu

Use the path to your qemu-ranchu checkout after calling
scripts/rebuild.sh successfully as the parameter to
--qemu-prebuilts-dir.

Change-Id: I103d5dd0f250d8a8ef9b269c5fd1d5e76ac1f2c8
diff --git a/android-configure.sh b/android-configure.sh
index 3e13cc2..5d5e725 100755
--- a/android-configure.sh
+++ b/android-configure.sh
@@ -31,6 +31,8 @@
 
 PCBIOS_PROBE=yes
 
+QEMU_PREBUILTS_DIR=
+
 HOST_CC=${CC:-gcc}
 OPTION_CC=
 
@@ -68,6 +70,8 @@
   ;;
   --gles-dir=*) GLES_DIR=$optarg
   ;;
+  --qemu-prebuilts-dir=*) QEMU_PREBUILTS_DIR=$optarg
+  ;;
   --no-gles) GLES_PROBE=no
   ;;
   --no-pcbios) PCBIOS_PROBE=no
@@ -90,23 +94,24 @@
 Options: [defaults in brackets after descriptions]
 EOF
     echo "Standard options:"
-    echo "  --help                   print this message"
-    echo "  --install=FILEPATH       copy emulator executable to FILEPATH [$TARGETS]"
-    echo "  --cc=PATH                specify C compiler [$HOST_CC]"
-    echo "  --sdl-config=FILE        use specific sdl-config script [$SDL_CONFIG]"
-    echo "  --no-strip               do not strip emulator executable"
-    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"
-    echo "  --debug                  build debug version of the emulator"
-    echo "  --gles-dir=PATH          specify path to GLES host emulation sources [auto-detected]"
-    echo "  --no-gles                disable GLES emulation support"
-    echo "  --no-pcbios              disable copying of PC Bios files"
-    echo "  --no-tests               don't run unit test suite"
+    echo "  --help                      Print this message"
+    echo "  --install=FILEPATH          Copy emulator executable to FILEPATH [$TARGETS]"
+    echo "  --cc=PATH                   Specify C compiler [$HOST_CC]"
+    echo "  --sdl-config=FILE           Use specific sdl-config script [$SDL_CONFIG]"
+    echo "  --no-strip                  Do not strip emulator executable"
+    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"
+    echo "  --debug                     Build debug version of the emulator"
+    echo "  --gles-dir=PATH             Specify path to GLES host emulation sources [auto-detected]"
+    echo "  --qemu-prebuilts-dir=PATH   Specify path to QEMU prebuilt binaries"
+    echo "  --no-gles                   Disable GLES emulation support"
+    echo "  --no-pcbios                 Disable copying of PC Bios files"
+    echo "  --no-tests                  Don't run unit test suite"
     echo ""
     exit 1
 fi
@@ -753,6 +758,15 @@
 python scripts/qapi-commands.py --output-dir=$AUTOGENERATED_DIR -m < qapi-schema.json
 log "Generate   : $AUTOGENERATED_DIR"
 
+if [ "$QEMU_PREBUILTS_DIR" ]; then
+    if [ ! -d "$QEMU_PREBUILTS_DIR/binaries" ]; then
+        panic "Missing QEMU prebuilts directory: $QEMU_PREBUILTS_DIR/binaries"
+    fi
+    log "Copying QEMU prebuilt binaries to: $OUT_DIR/qemu"
+    mkdir -p "$OUT_DIR"/qemu || panic "Could not create $OUT_DIR/qemu"
+    cp -rp "$QEMU_PREBUILTS_DIR/binaries"/* "$OUT_DIR/qemu"
+fi
+
 clean_temp
 
 echo "Ready to go. Type 'make' to build emulator"