Build arm and x86 binaries at the same time.

Change-Id: I105c5a097c988cb964b47b40b71c7a08af0d9210
diff --git a/android/avd/info.c b/android/avd/info.c
index 3d91a30..dc53849 100644
--- a/android/avd/info.c
+++ b/android/avd/info.c
@@ -124,6 +124,7 @@
     char      inAndroidBuild;
     char*     androidOut;
     char*     androidBuildRoot;
+    char*     targetArch;
 
     /* for the normal virtual device case */
     char*     deviceName;
@@ -558,7 +559,7 @@
 }
 
 
-/* copy image file from a given source 
+/* copy image file from a given source
  * assumes locking is needed.
  */
 static void
@@ -606,7 +607,7 @@
 
     /* set image state */
     l->pState[0] = (flags & IMAGE_DONT_LOCK) == 0
-                 ? IMAGE_STATE_MUSTLOCK 
+                 ? IMAGE_STATE_MUSTLOCK
                  : IMAGE_STATE_READONLY;
 
     /* check user-provided path */
@@ -651,7 +652,7 @@
         if (flags & IMAGE_REQUIRED) {
             AvdInfo*  i = l->info;
 
-            derror("could not find required %s image (%s).", 
+            derror("could not find required %s image (%s).",
                    l->imageText, l->imageFile);
 
             if (i->inAndroidBuild) {
@@ -1190,14 +1191,8 @@
     if ( !imageLoader_load( l, IMAGE_OPTIONAL |
                                IMAGE_DONT_LOCK ) )
     {
-#ifdef TARGET_ARM
-#define  PREBUILT_KERNEL_PATH   "prebuilt/android-arm/kernel/kernel-qemu"
-#endif
-#ifdef TARGET_I386
-#define  PREBUILT_KERNEL_PATH   "prebuilt/android-x86/kernel/kernel-qemu"
-#endif
-        p = bufprint(temp, end, "%s/%s", i->androidBuildRoot,
-                        PREBUILT_KERNEL_PATH);
+        p = bufprint(temp, end, "%s/prebuilt/android-%s/kernel/kernel-qemu",
+                     i->androidBuildRoot, i->targetArch);
         if (p >= end || !path_exists(temp)) {
             derror("bad workspace: cannot find prebuilt kernel in: %s", temp);
             exit(1);
@@ -1280,7 +1275,7 @@
 
         /* if the user provided one cache image, lock & use it */
         if ( params->forcePaths[l->id] != NULL ) {
-            imageLoader_load(l, IMAGE_REQUIRED | 
+            imageLoader_load(l, IMAGE_REQUIRED |
                                 IMAGE_IGNORE_IF_LOCKED);
         }
     }
@@ -1398,6 +1393,7 @@
 AvdInfo*
 avdInfo_newForAndroidBuild( const char*     androidBuildRoot,
                             const char*     androidOut,
+                            const char*     targetArch,
                             AvdInfoParams*  params )
 {
     AvdInfo*  i;
@@ -1408,6 +1404,7 @@
     i->androidBuildRoot = ASTRDUP(androidBuildRoot);
     i->androidOut       = ASTRDUP(androidOut);
     i->contentPath      = ASTRDUP(androidOut);
+    i->targetArch       = ASTRDUP(targetArch);
 
     /* TODO: find a way to provide better information from the build files */
     i->deviceName = ASTRDUP("<build>");
diff --git a/android/avd/info.h b/android/avd/info.h
index 2b2899f..1a65355 100644
--- a/android/avd/info.h
+++ b/android/avd/info.h
@@ -126,6 +126,7 @@
  */
 AvdInfo*  avdInfo_newForAndroidBuild( const char*     androidBuildRoot,
                                       const char*     androidOut,
+                                      const char*     targetArch,
                                       AvdInfoParams*  params );
 
 /* Frees an AvdInfo object and the corresponding strings that may be
diff --git a/android/cmdline-options.h b/android/cmdline-options.h
index 273d151..70e5f6c 100644
--- a/android/cmdline-options.h
+++ b/android/cmdline-options.h
@@ -131,7 +131,9 @@
 
 OPT_PARAM( report_console, "<socket>", "report console port to remote socket" )
 OPT_PARAM( gps, "<device>", "redirect NMEA GPS to character device" )
+#ifndef CONFIG_STANDALONE_CORE
 OPT_PARAM( keyset, "<name>", "specify keyset file name" )
+#endif
 OPT_PARAM( shell_serial, "<device>", "specific character device for root shell" )
 OPT_FLAG ( old_system, "support old (pre 1.4) system images" )
 OPT_PARAM( tcpdump, "<file>", "capture network packets to file" )
diff --git a/android/config/config.h b/android/config/config.h
index fdfbe31..e07cc2c 100644
--- a/android/config/config.h
+++ b/android/config/config.h
@@ -1,4 +1,9 @@
-/* Automatically generated by configure - do not modify */
+/* This file is included by target-specific files under
+ * android/config/target-$ARCH/config.h, but contains all config
+ * definitions that are independent of the target CPU.
+ *
+ * Do not include directly.
+ */
 #include "config-host.h"
 
 #define TARGET_PHYS_ADDR_BITS  32
@@ -11,13 +16,4 @@
 #define CONFIG_NAND_LIMITS 1
 #endif
 #define CONFIG_ANDROID_SNAPSHOTS 1
-
-#ifdef ARCH_FLAGS_x86
-#define TARGET_ARCH "x86"
-#define TARGET_I386 1
-#else
-#define TARGET_ARCH "arm"
-#define TARGET_ARM 1
-#define CONFIG_SOFTFLOAT 1
-#endif
-
+#define CONFIG_MEMCHECK 1
diff --git a/android/config/target-arm/config.h b/android/config/target-arm/config.h
new file mode 100644
index 0000000..d6da04f
--- /dev/null
+++ b/android/config/target-arm/config.h
@@ -0,0 +1,5 @@
+/* ARM-specific configuration */
+#include "android/config/config.h"
+
+#define TARGET_ARM 1
+#define CONFIG_SOFTFLOAT 1
diff --git a/android/config/target-x86/config.h b/android/config/target-x86/config.h
new file mode 100644
index 0000000..ea31c39
--- /dev/null
+++ b/android/config/target-x86/config.h
@@ -0,0 +1,3 @@
+/* x86-specific configuration */
+#include "android/config/config.h"
+#define TARGET_I386 1
diff --git a/android/help.c b/android/help.c
index 7df6704..a2180ef 100644
--- a/android/help.c
+++ b/android/help.c
@@ -213,6 +213,7 @@
     datadir );
 }
 
+#ifndef CONFIG_STANDALONE_CORE
 static void
 help_keys(stralloc_t*  out)
 {
@@ -253,7 +254,7 @@
     PRINTF( "\n" );
     PRINTF( "  note that NumLock must be deactivated for keypad keys to work\n\n" );
 }
-
+#endif /* !CONFIG_STANDALONE_CORE */
 
 static void
 help_environment(stralloc_t*  out)
@@ -285,7 +286,7 @@
     );
 }
 
-
+#ifndef CONFIG_STANDALONE_CORE
 static void
 help_keyset_file(stralloc_t*  out)
 {
@@ -355,7 +356,7 @@
     "\n"
     );
 }
-
+#endif /* !CONFIG_STANDALONE_CORE */
 
 static void
 help_debug_tags(stralloc_t*  out)
@@ -1304,6 +1305,7 @@
 }
 
 
+#ifndef CONFIG_STANDALONE_CORE
 static void
 help_keyset(stralloc_t*  out)
 {
@@ -1343,6 +1345,7 @@
     "\n"
     );
 }
+#endif /* !CONFIG_STANDALONE_CORE */
 
 static void
 help_old_system(stralloc_t*  out)
@@ -1494,11 +1497,15 @@
 
 static const TopicHelp    topic_help[] = {
     { "disk-images",  "about disk images",      help_disk_images },
+#ifndef CONFIG_STANDALONE_CORE
     { "keys",         "supported key bindings", help_keys },
+#endif
     { "debug-tags",   "debug tags for -debug <tags>", help_debug_tags },
     { "char-devices", "character <device> specification", help_char_devices },
     { "environment",  "environment variables",  help_environment },
+#ifndef CONFIG_STANDALONE_CORE
     { "keyset-file",  "key bindings configuration file", help_keyset_file },
+#endif
     { "virtual-device", "virtual device management", help_virtual_device },
     { "sdk-images",   "about disk images when using the SDK", help_sdk_images },
     { "build-images", "about disk images when building Android", help_build_images },
diff --git a/android/main-common.c b/android/main-common.c
index bb07943..3c8b320 100644
--- a/android/main-common.c
+++ b/android/main-common.c
@@ -19,8 +19,16 @@
 #include <process.h>
 #endif
 
+#ifndef CONFIG_STANDALONE_CORE
 #include <SDL.h>
 #include <SDL_syswm.h>
+#include "android/qemulator.h"
+#include "android/skin/image.h"
+#include "android/skin/trackball.h"
+#include "android/skin/keyboard.h"
+#include "android/skin/file.h"
+#include "android/skin/window.h"
+#endif
 
 #include "console.h"
 
@@ -31,13 +39,7 @@
 #include "android/globals.h"
 #include "android/resource.h"
 #include "android/user-config.h"
-#include "android/qemulator.h"
 #include "android/display.h"
-#include "android/skin/image.h"
-#include "android/skin/trackball.h"
-#include "android/skin/keyboard.h"
-#include "android/skin/file.h"
-#include "android/skin/window.h"
 
 
 
@@ -54,6 +56,20 @@
 /***  CONFIGURATION
  ***/
 
+#ifdef CONFIG_STANDALONE_CORE
+
+void
+user_config_init( void )
+{
+}
+
+/* only call this function on normal exits, so that ^C doesn't save the configuration */
+void
+user_config_done( void )
+{
+}
+
+#else /* !CONFIG_STANDALONE_CORE */
 static AUserConfig*  userConfig;
 
 void
@@ -86,6 +102,7 @@
     if (userConfig)
         auserConfig_getWindowPos(userConfig, window_x, window_y);
 }
+#endif /* !CONFIG_STANDALONE_CORE */
 
 unsigned convertBytesToMB( uint64_t  size )
 {
@@ -105,6 +122,7 @@
 }
 
 
+#ifndef CONFIG_STANDALONE_CORE
 /***********************************************************************/
 /***********************************************************************/
 /*****                                                             *****/
@@ -199,7 +217,7 @@
     }
 }
 
-
+#endif /* !CONFIG_STANDALONE_CORE */
 
 /***********************************************************************/
 /***********************************************************************/
@@ -209,6 +227,8 @@
 /***********************************************************************/
 /***********************************************************************/
 
+#ifndef CONFIG_STANDALONE_CORE
+
 void *readpng(const unsigned char*  base, size_t  size, unsigned *_width, unsigned *_height);
 
 #ifdef CONFIG_DARWIN
@@ -269,15 +289,19 @@
             }
         }
 
+#ifndef CONFIG_STANDALONE_CORE
         SDL_Surface* icon = sdl_surface_from_argb32( icon_pixels, icon_w, icon_h );
         if (icon != NULL) {
             SDL_WM_SetIcon(icon, NULL);
             SDL_FreeSurface(icon);
             free( icon_pixels );
         }
+#endif
+
 #endif  /* !_WIN32 */
     }
 }
+#endif /* !CONFIG_STANDALONE_CORE */
 
 /***********************************************************************/
 /***********************************************************************/
@@ -290,7 +314,7 @@
 const char*  skin_network_speed = NULL;
 const char*  skin_network_delay = NULL;
 
-
+#ifndef CONFIG_STANDALONE_CORE
 static void sdl_at_exit(void)
 {
     user_config_done();
@@ -319,6 +343,7 @@
     android_display_init(ds, qframebuffer_fifo_get());
 #endif
 }
+#endif
 
 /* list of skin aliases */
 static const struct {
@@ -462,6 +487,26 @@
 }
 
 
+#ifdef CONFIG_STANDALONE_CORE
+void
+init_sdl_ui(AConfig*         skinConfig,
+            const char*      skinPath,
+            AndroidOptions*  opts)
+{
+    signal(SIGINT, SIG_DFL);
+#ifndef _WIN32
+    signal(SIGQUIT, SIG_DFL);
+   /* prevent SIGTTIN and SIGTTOUT from stopping us. this is necessary to be
+    * able to run the emulator in the background (e.g. "emulator &").
+    * despite the fact that the emulator should not grab input or try to
+    * write to the output in normal cases, we're stopped on some systems
+    * (e.g. OS X)
+    */
+    signal(SIGTTIN, SIG_IGN);
+    signal(SIGTTOU, SIG_IGN);
+#endif
+}
+#else /* !CONFIG_STANDALONE_CORE */
 void
 init_sdl_ui(AConfig*         skinConfig,
             const char*      skinPath,
@@ -536,6 +581,7 @@
         qemulator_get()->onion_rotation = rotate;
     }
 }
+#endif /* !CONFIG_STANDALONE_CORE */
 
 int64_t  get_screen_pixels(AConfig*  skinConfig)
 {
diff --git a/android/main-ui.c b/android/main-ui.c
index ca83a9a..c31cfef 100644
--- a/android/main-ui.c
+++ b/android/main-ui.c
@@ -812,6 +812,7 @@
         android_avdInfo = avdInfo_newForAndroidBuild(
                             android_build_root,
                             android_build_out,
+                            "arm",
                             android_avdParams );
 
         if(android_avdInfo == NULL) {
diff --git a/android/main.c b/android/main.c
index 919810b..15adaf4 100644
--- a/android/main.c
+++ b/android/main.c
@@ -26,8 +26,11 @@
 #include "console.h"
 #include "user-events.h"
 
+#ifndef CONFIG_STANDALONE_CORE
 #include <SDL.h>
 #include <SDL_syswm.h>
+#include "android/qemulator.h"
+#endif
 
 #include "math.h"
 
@@ -48,7 +51,6 @@
 
 #include "android/globals.h"
 
-#include "android/qemulator.h"
 #include "android/display.h"
 
 #include "android/snapshot.h"
@@ -260,7 +262,7 @@
     if (imageMB > defaultMB) {
         snprintf(temp, sizeof temp, "(%d MB > %d MB)", imageMB, defaultMB);
     } else {
-        snprintf(temp, sizeof temp, "(%lld bytes > %lld bytes)", imageBytes, defaultBytes);
+        snprintf(temp, sizeof temp, "(%" PRUd64" bytes > %" PRUd64" bytes)", imageBytes, defaultBytes);
     }
 
     if (inAndroidBuild) {
@@ -603,6 +605,7 @@
         android_avdInfo = avdInfo_newForAndroidBuild(
                             android_build_root,
                             android_build_out,
+                            TARGET_ARCH,
                             android_avdParams );
 
         if(android_avdInfo == NULL) {
@@ -631,6 +634,7 @@
         exit(1);
     }
 
+#ifndef CONFIG_STANDALONE_CORE
     if (opts->keyset) {
         parse_keyset(opts->keyset, opts);
         if (!android_keyset) {
@@ -653,6 +657,7 @@
                 write_default_keyset();
         }
     }
+#endif /* !CONFIG_STANDALONE_CORE */
 
     if (opts->shared_net_id) {
         char*  end;
@@ -1090,7 +1095,7 @@
     }
 
     /* Pass LCD density value to the core. */
-    snprintf(lcd_density, sizeof(lcd_density), "%d", get_device_dpi(opts));
+    snprintf(lcd_density, sizeof(lcd_density), "%d", hw->hw_lcd_density);
     args[n++] = "-lcd-density";
     args[n++] = lcd_density;
 
diff --git a/android/utils/system.h b/android/utils/system.h
index c8163c6..464957d 100644
--- a/android/utils/system.h
+++ b/android/utils/system.h
@@ -173,6 +173,12 @@
 #ifndef PRIx64
 #  define PRIx64  "llx"
 #endif
+#ifndef PRUd64
+#  define PRUd64  "llu"
+#endif
+#ifndef PRUx64
+#  define PRUx64  "llx"
+#endif
 
 /* */