Build standalone UI program (emulator-ui).

This changes introduces a new program, called emulator-ui
that only contains parts necessary to display the UI (and
removes anything related to CPU emulation).

This is only a skeleton right now, since it is not capable
of launching a core, or displaying anything meaningful,
except the skin, trackball, respond to commands (e.g.
change layouts with KP-7 and KP-9).

Later changes will introduce core launching, communication,
etc...

Change-Id: Icef9deb8a3a256532655e1cd409b4aab52565d03
diff --git a/Makefile.android b/Makefile.android
index 49dfd1a..3020429 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -538,7 +538,7 @@
 LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
 LOCAL_CC                        := $(MY_CC)
 LOCAL_LDLIBS                    := $(MY_LDLIBS)
-LOCAL_MODULE                    := emulator-ui
+LOCAL_MODULE                    := emulator-uilib
 
 EMULATOR_UI_CFLAGS :=
 
@@ -573,6 +573,8 @@
 
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS) $(EMULATOR_CORE_CFLAGS) $(EMULATOR_UI_CFLAGS)
 
+LOCAL_MODULE_TAGS := debug
+
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 ##############################################################################
@@ -633,7 +635,7 @@
 
 # misc. sources
 #
-CORE_MISC_SOURCES = vl-android.c \
+CORE_MISC_SOURCES = \
                     console.c \
                     loader.c \
                     monitor.c \
@@ -808,7 +810,7 @@
 LOCAL_MODULE                    := emulator
 LOCAL_STATIC_LIBRARIES          := emulator-memcheck emulator-hw emulator-arm emulator-tcg
 LOCAL_STATIC_LIBRARIES          += emulator-elff
-LOCAL_STATIC_LIBRARIES          += emulator-core emulator-ui
+LOCAL_STATIC_LIBRARIES          += emulator-core emulator-uilib
 LOCAL_LDLIBS                    := $(MY_LDLIBS)
 
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS) $(EMULATOR_CORE_CFLAGS) $(EMULATOR_UI_CFLAGS)
@@ -849,6 +851,7 @@
               android/cmdline-option.c \
               android/config.c \
               android/main.c \
+              vl-android.c
 
 # Add common system libraries
 #
@@ -976,7 +979,7 @@
 
 LOCAL_MODULE := emulator
 
-# See comment about SDLMAIN_SOURCES in the 'emulator-ui' module declarations.
+# See comment about SDLMAIN_SOURCES in the 'emulator-uilib' module declarations.
 LOCAL_SRC_FILES += $(SDLMAIN_SOURCES)
 
 include $(BUILD_HOST_EXECUTABLE)
@@ -1023,6 +1026,7 @@
 #
 VL_SOURCES := framebuffer.c \
               user-events-qemu.c \
+              vl-android.c
 
 # Add common system libraries
 #
@@ -1142,4 +1146,97 @@
 
 include $(BUILD_HOST_EXECUTABLE)
 
+##############################################################################
+# now build the emulator UI
+#
+include $(CLEAR_VARS)
+
+LOCAL_GENERATED_SOURCES :=
+LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
+LOCAL_CC                        := $(MY_CC)
+LOCAL_MODULE                    := emulator-ui
+LOCAL_STATIC_LIBRARIES          := emulator-uilib
+LOCAL_LDLIBS                    := $(MY_LDLIBS)
+
+LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS) $(EMULATOR_CORE_CFLAGS) $(EMULATOR_UI_CFLAGS)
+
+# add the build ID to the default macro definitions
+LOCAL_CFLAGS += $(UI_AND_CORE_CFLAGS) -DCONFIG_STANDALONE_UI
+
+ifeq ($(HOST_ARCH),x86)
+# enable MMX code for our skin scaler
+LOCAL_CFLAGS += -DUSE_MMX=1 -mmmx
+endif
+
+# include other sources
+#
+VL_SOURCES := framebuffer.c \
+              user-events-ui.c \
+              android/cmdline-option.c \
+              android/config.c \
+              android/display.c \
+              android/main.c \
+	      console-ui.c \
+              qemu-timer-ui.c \
+              vl-android-ui.c
+
+# Add common system libraries
+#
+LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)
+
+LOCAL_SRC_FILES += $(VL_SOURCES) $(UI_SOURCES) $(UI_AND_CORE_SOURCES)
+
+# add SDL-specific flags
+#
+LOCAL_CFLAGS += $(SDL_CFLAGS)
+LOCAL_LDLIBS += $(SDL_LDLIBS)
+LOCAL_STATIC_LIBRARIES += $(SDL_STATIC_LIBRARIES)
+
+# on Windows, link the icon file as well into the executable
+# unfortunately, our build system doesn't help us much, so we need
+# to use some weird pathnames to make this work...
+#
+ifeq ($(HOST_OS),windows)
+
+# Locate windres executable
+WINDRES := windres
+ifneq ($(USE_MINGW),)
+  # When building the Windows emulator under Linux, use the MinGW one
+  WINDRES := i586-mingw32msvc-windres
+endif
+
+INTERMEDIATE     := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),true)
+ANDROID_ICON_OBJ := android_icon.o
+ANDROID_ICON_PATH := $(LOCAL_PATH)/images
+$(ANDROID_ICON_PATH)/$(ANDROID_ICON_OBJ): $(ANDROID_ICON_PATH)/android_icon.rc
+	$(WINDRES) $< -I $(ANDROID_ICON_PATH) -o $@
+
+# seems to be the only way to add an object file that was not generated from
+# a C/C++/Java source file to our build system. and very unfortunately,
+# $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
+# us to put the object file in the source directory...
+#
+LOCAL_PREBUILT_OBJ_FILES += images/$(ANDROID_ICON_OBJ)
+endif
+
+# this is already done by the Android build system, but is done for the
+# benefit of the stand-alone one.
+#
+ifeq ($(BUILD_STANDALONE_EMULATOR),true)
+  LOCAL_CFLAGS += -I$(intermediates)
+endif
+
+# Generate a completely static executable if needed.
+# Note that this means no sound and graphics on Linux.
+#
+ifeq ($(CONFIG_STATIC_EXECUTABLE),true)
+    LOCAL_SRC_FILES += dynlink-static.c
+    LOCAL_LDLIBS    += -static
+endif
+
+# See comment about SDLMAIN_SOURCES in the 'emulator-uilib' module declarations.
+LOCAL_SRC_FILES += $(SDLMAIN_SOURCES)
+
+include $(BUILD_HOST_EXECUTABLE)
+
 endif  # TARGET_ARCH == arm