Separate emulator build into three parts: core lib, UI lib, and the executable.

Change-Id: I792ed4d14686acc3f9379f4ac6200fa2046ccfce
diff --git a/Makefile.android b/Makefile.android
index 2e51d5f..7cd692b 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -455,6 +455,106 @@
 endif  # !QEMU_AUDIO_LIB
 
 ##############################################################################
+# Build emulator core library.
+# This library contains "pure" emulation code separated from the intricacies
+# of the UI.
+#
+include $(CLEAR_VARS)
+
+LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
+LOCAL_CC                        := $(MY_CC)
+LOCAL_LDLIBS                    := $(MY_LDLIBS)
+LOCAL_MODULE                    := emulator-core
+
+# don't remove the -fno-strict-aliasing, or you'll break things
+# (e.g. slirp-android/network support)
+#
+LOCAL_CFLAGS := -fno-PIC -Wno-sign-compare \
+                -fno-strict-aliasing -g -W -Wall -Wno-unused-parameter
+
+LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS)
+
+# Common includes for the emulator
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/ \
+                   -I$(LOCAL_PATH)/target-arm \
+                   -I$(LOCAL_PATH)/fpu \
+                   $(TCG_CFLAGS) \
+                   $(HW_CFLAGS) \
+
+# include slirp-android code, i.e. the user-level networking stuff
+#
+SLIRP_SOURCES := bootp.c     cksum.c      debug.c  if.c     ip_icmp.c  ip_input.c   ip_output.c  \
+                 mbuf.c      misc.c       sbuf.c   slirp.c  socket.c   tcp_input.c  tcp_output.c \
+                 tcp_subr.c  tcp_timer.c  tftp.c   udp.c
+
+LOCAL_SRC_FILES += $(SLIRP_SOURCES:%=slirp-android/%)
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/slirp-android
+
+# socket proxy support
+#
+PROXY_SOURCES := \
+    proxy_common.c \
+    proxy_http.c \
+    proxy_http_connector.c \
+    proxy_http_rewriter.c \
+
+LOCAL_SRC_FILES += $(PROXY_SOURCES:%=proxy/%)
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/proxy
+
+# include telephony stuff
+#
+TELEPHONY_SOURCES := android_modem.c modem_driver.c gsm.c sim_card.c sysdeps_qemu.c sms.c remote_call.c
+LOCAL_SRC_FILES += $(TELEPHONY_SOURCES:%=telephony/%)
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/telephony
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+##############################################################################
+# Build emulator UI library.
+# This library contains some emulator related UI components.
+#
+include $(CLEAR_VARS)
+
+LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
+LOCAL_CC                        := $(MY_CC)
+LOCAL_LDLIBS                    := $(MY_LDLIBS)
+LOCAL_MODULE                    := emulator-ui
+
+LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS)
+
+# Common includes for the emulator
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/ \
+                   -I$(LOCAL_PATH)/target-arm \
+                   -I$(LOCAL_PATH)/fpu \
+                   $(TCG_CFLAGS) \
+                   $(HW_CFLAGS) \
+
+# include the SDL sources
+#
+LOCAL_SRC_FILES += $(SDL_SOURCES) $(SDLMAIN_SOURCES)
+LOCAL_CFLAGS    += $(SDL_CFLAGS) -I$(LOCAL_PATH)/$(SDL_DIR)/include
+
+# the skin support sources
+#
+SKIN_SOURCES := rect.c \
+                region.c \
+                image.c \
+                trackball.c \
+                keyboard.c \
+                keyset.c \
+                file.c \
+                window.c \
+                scaler.c \
+                composer.c \
+                surface.c \
+
+LOCAL_SRC_FILES += $(SKIN_SOURCES:%=android/skin/%)
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/skin
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+
+##############################################################################
 # now build the emulator itself
 #
 include $(CLEAR_VARS)
@@ -464,6 +564,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_LDLIBS                    := $(MY_LDLIBS)
 
 # don't remove the -fno-strict-aliasing, or you'll break things
@@ -500,7 +601,7 @@
 
 # include the SDL sources
 #
-LOCAL_SRC_FILES += $(SDL_SOURCES) $(SDLMAIN_SOURCES)
+#LOCAL_SRC_FILES += $(SDL_SOURCES) $(SDLMAIN_SOURCES)
 LOCAL_CFLAGS    += $(SDL_CFLAGS) -I$(LOCAL_PATH)/$(SDL_DIR)/include
 
 #
@@ -513,10 +614,9 @@
 # Needed by the upstream code
 LOCAL_CFLAGS += -DNEED_CPU_H
 
-# include telephony stuff
-#
-TELEPHONY_SOURCES := android_modem.c modem_driver.c gsm.c sim_card.c sysdeps_qemu.c sms.c remote_call.c
-LOCAL_SRC_FILES += $(TELEPHONY_SOURCES:%=telephony/%)
+# Include emulator-core definitions
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/slirp-android
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/proxy
 LOCAL_CFLAGS    += -I$(LOCAL_PATH)/telephony
 
 # include sound support source files. we first try to see if we have a prebuilt audio
@@ -535,48 +635,11 @@
 LOCAL_CFLAGS  += $(AUDIO_CFLAGS)
 LOCAL_LDLIBS  += $(AUDIO_LDLIBS)
 
-# include slirp-android code, i.e. the user-level networking stuff
-#
-SLIRP_SOURCES := bootp.c     cksum.c      debug.c  if.c     ip_icmp.c  ip_input.c   ip_output.c  \
-                 mbuf.c      misc.c       sbuf.c   slirp.c  socket.c   tcp_input.c  tcp_output.c \
-                 tcp_subr.c  tcp_timer.c  tftp.c   udp.c
-
-LOCAL_SRC_FILES += $(SLIRP_SOURCES:%=slirp-android/%)
-LOCAL_CFLAGS    += -I$(LOCAL_PATH)/slirp-android
-
-# socket proxy support
-#
-PROXY_SOURCES := \
-    proxy_common.c \
-    proxy_http.c \
-    proxy_http_connector.c \
-    proxy_http_rewriter.c \
-
-LOCAL_SRC_FILES += $(PROXY_SOURCES:%=proxy/%)
-LOCAL_CFLAGS    += -I$(LOCAL_PATH)/proxy
-
 # the linux-user sources, I doubt we really need these
 #
 #LINUX_SOURCES := main.c elfload.c mmap.c signal.c path.c syscall.c
 #LOCAL_SRC_FILES += $(LINUX_SOURCES:%=linux-user/%)
 
-# the skin support sources
-#
-SKIN_SOURCES := rect.c \
-                region.c \
-                image.c \
-                trackball.c \
-                keyboard.c \
-                keyset.c \
-                file.c \
-                window.c \
-                scaler.c \
-                composer.c \
-                surface.c \
-
-LOCAL_SRC_FILES += $(SKIN_SOURCES:%=android/skin/%)
-#LOCAL_CFLAGS    += -I$(LOCAL_PATH)/skin
-
 ifeq ($(HOST_ARCH),x86)
 # enable MMX code for our skin scaler
 LOCAL_CFLAGS += -DUSE_MMX=1 -mmmx