Merge "Compile Mac OS binaries with unwind tables for libcorkscrew."
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 481829a..b1b139a 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -122,6 +122,11 @@
 # Changing where ro.carrier value is instantiated for system/build.prop
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/build.prop)
 
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/APPS/*)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/app/*)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/app/*)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/build.prop)
+
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/core/Makefile b/core/Makefile
index 05bc057..bff5e80 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -31,7 +31,9 @@
     $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
         $(info PRODUCT_COPY_FILES $(cf) ignored.), \
         $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
-        $(eval $(call copy-one-file,$(_src),$(_fulldest))) \
+        $(if $(filter %.xml,$(_dest)),\
+            $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
+            $(eval $(call copy-one-file,$(_src),$(_fulldest)))) \
         $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
         $(eval unique_product_copy_files_destinations += $(_dest))))
 unique_product_copy_files_destinations :=
@@ -813,19 +815,31 @@
 .PHONY: stnod
 stnod: systemtarball-nodeps
 
+# For platform-java goal, add platform as well
+ifneq (,$(filter platform-java, $(MAKECMDGOALS)))
+PLATFORM_ZIP_ADD_JAVA := true
+endif
+
 #######
 ## platform.zip: system, plus other files to be used in PDK fusion build,
 ## in a zip file
-INSTALLED_PLATFROM_ZIP := $(PRODUCT_OUT)/platform.zip
-$(INSTALLED_PLATFROM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES)
-	$(call pretty,"Platform zip package: $(INSTALLED_PLATFROM_ZIP)")
+INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
+$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES)
+	$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
 	$(hide) rm -f $@
 	$(hide) cd $(dir $@) && zip -qry $(notdir $@) \
 		$(TARGET_COPY_OUT_SYSTEM) \
 		$(patsubst $(PRODUCT_OUT)/%, %, $(TARGET_OUT_NOTICE_FILES))
+ifeq (true,$(PLATFORM_ZIP_ADD_JAVA))
+	$(hide) cd $(OUT_DIR) && zip -qry ../$(INSTALLED_PLATFORM_ZIP) $(PDK_PLATFORM_JAVA_ZIP_CONTENTS)
+endif
+
 
 .PHONY: platform
-platform: $(INSTALLED_PLATFROM_ZIP)
+platform: $(INSTALLED_PLATFORM_ZIP)
+
+.PHONY: platform-java
+platform-java: platform
 
 # Dist the platform.zip
 ifneq (,$(filter platform, $(MAKECMDGOALS)))
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 38c2c10..09c2586 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -55,6 +55,7 @@
 #space := $(empty) $(empty)
 #$(shell echo $(lastword $(filter-out config/% out/%,$(MAKEFILE_LIST))),$(LOCAL_MODULE),$(strip $(LOCAL_MODULE_CLASS)),$(subst $(space),$(comma),$(sort $(LOCAL_MODULE_TAGS))) >> tag-list.csv)
 
+LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE))
 LOCAL_MODULE_TAGS := $(sort $(LOCAL_MODULE_TAGS))
 ifeq (,$(LOCAL_MODULE_TAGS))
 ifeq (true,$(LOCAL_UNINSTALLABLE_MODULE))
@@ -91,8 +92,7 @@
     $(warning *    Android.mk for the affected module, and add)
     $(warning *    the LOCAL_MODULE value for that component)
     $(warning *    into the PRODUCT_PACKAGES section of product)
-    $(warning *    makefile(s) where it's necessary, if)
-    $(warning *    appropriate.)
+    $(warning *    makefile(s) where necessary, if appropriate.)
     $(warning * )
     $(warning * If the component should be in EVERY build of ALL)
     $(warning * products, then add its LOCAL_MODULE value to the)
@@ -124,18 +124,6 @@
   LOCAL_MODULE_TAGS := $(sort $(LOCAL_MODULE_TAGS) user)
 endif
 
-ifdef LOCAL_IS_HOST_MODULE
-  partition_tag :=
-else
-ifeq (true,$(LOCAL_PROPRIETARY_MODULE))
-  partition_tag := _VENDOR
-else
-  # The definition of should-install-to-system will be different depending
-  # on which goal (e.g., sdk or just droid) is being built.
-  partition_tag := $(if $(call should-install-to-system,$(LOCAL_MODULE_TAGS)),,_DATA)
-endif
-endif
-
 LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS))
 ifneq ($(words $(LOCAL_MODULE_CLASS)),1)
   $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS must contain exactly one word, not "$(LOCAL_MODULE_CLASS)")
@@ -149,6 +137,19 @@
   endif
 endif
 
+ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
+ifdef LOCAL_IS_HOST_MODULE
+  partition_tag :=
+else
+ifeq (true,$(LOCAL_PROPRIETARY_MODULE))
+  partition_tag := _VENDOR
+else
+  # The definition of should-install-to-system will be different depending
+  # on which goal (e.g., sdk or just droid) is being built.
+  partition_tag := $(if $(call should-install-to-system,$(LOCAL_MODULE_TAGS)),,_DATA)
+endif
+endif
+
 LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH))
 ifeq ($(LOCAL_MODULE_PATH),)
   LOCAL_MODULE_PATH := $($(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS))
@@ -156,6 +157,7 @@
     $(error $(LOCAL_PATH): unhandled LOCAL_MODULE_CLASS "$(LOCAL_MODULE_CLASS)")
   endif
 endif
+endif # not LOCAL_UNINSTALLABLE_MODULE
 
 ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),)
   $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles)
@@ -200,7 +202,6 @@
 LOCAL_BUILT_MODULE := $(built_module_path)/$(LOCAL_BUILT_MODULE_STEM)
 built_module_path :=
 
-LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE))
 ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
   LOCAL_INSTALLED_MODULE := $(LOCAL_MODULE_PATH)/$(LOCAL_INSTALLED_MODULE_STEM)
 endif
@@ -226,7 +227,8 @@
 aidl_preprocess_import :=
 LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
 ifdef LOCAL_SDK_VERSION
-ifeq ($(LOCAL_SDK_VERSION),current)
+ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
+  # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS
   aidl_preprocess_import := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
 else
   aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
@@ -399,7 +401,8 @@
 ifeq ($(LOCAL_SDK_VERSION),)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,core)
 else
-ifeq ($(LOCAL_SDK_VERSION),current)
+ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
+# LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,android_stubs_current)
 else
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,sdk_v$(LOCAL_SDK_VERSION))
diff --git a/core/combo/TARGET_linux-arm.mk b/core/combo/TARGET_linux-arm.mk
index e263d0c..98868ae 100644
--- a/core/combo/TARGET_linux-arm.mk
+++ b/core/combo/TARGET_linux-arm.mk
@@ -228,12 +228,12 @@
 	$(libm_root)/include/arm \
 	$(libthread_db_root)/include
 
-TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
-TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
-TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
+TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
+TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
+TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
 
-TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
-TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
+TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
+TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
 
 TARGET_STRIP_MODULE:=true
 
@@ -280,6 +280,9 @@
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
 	$(PRIVATE_ALL_OBJECTS) \
+	-Wl,--whole-archive \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	-Wl,--no-whole-archive \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
@@ -299,6 +302,9 @@
 	$(TARGET_GLOBAL_LDFLAGS) \
 	$(PRIVATE_LDFLAGS) \
 	$(PRIVATE_ALL_OBJECTS) \
+	-Wl,--whole-archive \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	-Wl,--no-whole-archive \
 	$(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
 	-Wl,--start-group \
 	$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
diff --git a/core/combo/TARGET_linux-sh.mk b/core/combo/TARGET_linux-sh.mk
index 88c6215..cb16194 100644
--- a/core/combo/TARGET_linux-sh.mk
+++ b/core/combo/TARGET_linux-sh.mk
@@ -108,12 +108,12 @@
 	$(libm_root)/include/sh \
 	$(libthread_db_root)/include
 
-TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
-TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
-TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
+TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
+TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
+TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
 
-TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/sobegin.o
-TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/soend.o
+TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/sobegin.o
+TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/soend.o
 
 TARGET_STRIP_MODULE:=true
 
@@ -153,6 +153,9 @@
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
 	$(PRIVATE_ALL_OBJECTS) \
+	-Wl,--whole-archive \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	-Wl,--no-whole-archive \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
@@ -170,6 +173,9 @@
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
 	$(PRIVATE_LDFLAGS) \
 	$(PRIVATE_ALL_OBJECTS) \
+	-Wl,--whole-archive \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	-Wl,--no-whole-archive \
 	-Wl,--start-group \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	-Wl,--end-group \
diff --git a/core/combo/TARGET_linux-x86.mk b/core/combo/TARGET_linux-x86.mk
index dc4afb8..beceec8 100644
--- a/core/combo/TARGET_linux-x86.mk
+++ b/core/combo/TARGET_linux-x86.mk
@@ -36,8 +36,8 @@
 
 # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
 ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
-TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-android-linux-4.4.3
-TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/i686-android-linux-
+TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-4.6
+TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/i686-linux-android-
 endif
 
 TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
@@ -151,12 +151,12 @@
 	$(libm_root)/include/i387 \
 	$(libthread_db_root)/include
 
-TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
-TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
-TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
+TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
+TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
+TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
 
-TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
-TARGET_CRTEND_SO_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
+TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
+TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
 
 TARGET_STRIP_MODULE:=true
 
@@ -199,6 +199,9 @@
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_DYNAMIC_O)) \
 	$(PRIVATE_ALL_OBJECTS) \
+	-Wl,--whole-archive \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	-Wl,--no-whole-archive \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
@@ -216,6 +219,9 @@
 	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(TARGET_CRTBEGIN_STATIC_O)) \
 	$(PRIVATE_LDFLAGS) \
 	$(PRIVATE_ALL_OBJECTS) \
+	-Wl,--whole-archive \
+	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+	-Wl,--no-whole-archive \
 	-Wl,--start-group \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(TARGET_LIBGCC) \
diff --git a/core/config.mk b/core/config.mk
index 3ba0771..b0b5082 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -432,7 +432,7 @@
     ( sgrax $(1) | sort -g ) )
 endef
 
-TARGET_AVAILABLE_SDK_VERSIONS := current $(call numerically_sort,\
+TARGET_AVAILABLE_SDK_VERSIONS := $(call numerically_sort,\
     $(patsubst $(HISTORICAL_SDK_VERSIONS_ROOT)/%/android.jar,%, \
     $(wildcard $(HISTORICAL_SDK_VERSIONS_ROOT)/*/android.jar)))
 
diff --git a/core/definitions.mk b/core/definitions.mk
index f82bfa5..c3c4884 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1707,6 +1707,28 @@
 	$$(copy-file-to-target)
 endef
 
+# Copies many files.
+# $(1): The files to copy.  Each entry is a ':' separated src:dst pair
+# Evaluates to the list of the dst files (ie suitable for a dependency list)
+define copy-many-files
+$(foreach f, $(1), $(strip \
+    $(eval _cmf_tuple := $(subst :, ,$(f))) \
+    $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
+    $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
+    $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
+    $(_cmf_dest)))
+endef
+
+# Copy the file only if it's a well-formed xml file. For use via $(eval).
+# $(1): source file
+# $(2): destination file, must end with .xml.
+define copy-xml-file-checked
+$(2): $(1) | $(ACP)
+	@echo "Copy xml: $$@"
+	$(hide) xmllint $$< >/dev/null  # Don't print the xml file to stdout.
+	$$(copy-file-to-target)
+endef
+
 # The -t option to acp and the -p option to cp is
 # required for OSX.  OSX has a ridiculous restriction
 # where it's an error for a .a file's modification time
diff --git a/core/droiddoc.mk b/core/droiddoc.mk
index 47f599d..e312965 100644
--- a/core/droiddoc.mk
+++ b/core/droiddoc.mk
@@ -64,7 +64,8 @@
 ifneq ($(LOCAL_IS_HOST_MODULE),true)
 
 ifneq ($(LOCAL_SDK_VERSION),)
-  ifeq ($(LOCAL_SDK_VERSION),current)
+  ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
+    # Use android_stubs_current if LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
     LOCAL_JAVA_LIBRARIES := android_stubs_current $(LOCAL_JAVA_LIBRARIES)
   else
     LOCAL_JAVA_LIBRARIES := sdk_v$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES)
diff --git a/core/dumpvar.mk b/core/dumpvar.mk
index 0f7dd8f..4a44f77 100644
--- a/core/dumpvar.mk
+++ b/core/dumpvar.mk
@@ -16,9 +16,9 @@
 endif
 
 # Add the x86 toolchain bin dir if it actually exists
-ifneq ($(wildcard $(PWD)/prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-android-linux-4.4.3/bin),)
+ifneq ($(wildcard $(PWD)/prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-4.6/bin),)
 	# this should be copied to HOST_OUT_EXECUTABLES instead
-	ABP:=$(ABP):$(PWD)/prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-android-linux-4.4.3/bin
+	ABP:=$(ABP):$(PWD)/prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/i686-linux-android-4.6/bin
 endif
 ANDROID_BUILD_PATHS := $(ABP)
 ANDROID_PREBUILTS := prebuilt/$(HOST_PREBUILT_TAG)
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 74e9100..33c521e 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -185,7 +185,6 @@
 HOST_OUT_INTERMEDIATES := $(HOST_OUT)/obj
 HOST_OUT_HEADERS:= $(HOST_OUT_INTERMEDIATES)/include
 HOST_OUT_INTERMEDIATE_LIBRARIES := $(HOST_OUT_INTERMEDIATES)/lib
-HOST_OUT_STATIC_LIBRARIES := $(HOST_OUT_INTERMEDIATE_LIBRARIES)
 HOST_OUT_NOTICE_FILES:=$(HOST_OUT_INTERMEDIATES)/NOTICE_FILES
 HOST_OUT_COMMON_INTERMEDIATES := $(HOST_COMMON_OUT_ROOT)/obj
 
@@ -203,7 +202,6 @@
 TARGET_OUT_KEYLAYOUT := $(TARGET_OUT)/usr/keylayout
 TARGET_OUT_KEYCHARS := $(TARGET_OUT)/usr/keychars
 TARGET_OUT_ETC := $(TARGET_OUT)/etc
-TARGET_OUT_STATIC_LIBRARIES:= $(TARGET_OUT_INTERMEDIATES)/lib
 TARGET_OUT_NOTICE_FILES:=$(TARGET_OUT_INTERMEDIATES)/NOTICE_FILES
 TARGET_OUT_FAKE := $(PRODUCT_OUT)/fake_packages
 
@@ -215,7 +213,6 @@
 TARGET_OUT_DATA_KEYLAYOUT := $(TARGET_OUT_KEYLAYOUT)
 TARGET_OUT_DATA_KEYCHARS := $(TARGET_OUT_KEYCHARS)
 TARGET_OUT_DATA_ETC := $(TARGET_OUT_ETC)
-TARGET_OUT_DATA_STATIC_LIBRARIES:= $(TARGET_OUT_STATIC_LIBRARIES)
 TARGET_OUT_DATA_NATIVE_TESTS := $(TARGET_OUT_DATA)/nativetest
 
 TARGET_OUT_CACHE := $(PRODUCT_OUT)/cache
diff --git a/core/java.mk b/core/java.mk
index 4005ce3..2b6851b 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -4,10 +4,12 @@
 # all_res_assets
 
 ifeq ($(TARGET_BUILD_PDK),true)
+ifeq ($(TARGET_BUILD_PDK_JAVA),)
 # LOCAL_SDK not defined or set to current
 ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
 LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
 endif
+endif # !PDK_JAVA
 endif #PDK
 
 
@@ -28,7 +30,8 @@
       $(error $(LOCAL_PATH): Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
              Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
     else
-      ifeq ($(LOCAL_SDK_VERSION),current)
+      ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
+        # Use android_stubs_current if LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
         LOCAL_JAVA_LIBRARIES := android_stubs_current $(LOCAL_JAVA_LIBRARIES)
       else
         LOCAL_JAVA_LIBRARIES := sdk_v$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES)
@@ -166,7 +169,8 @@
 renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
 
 # prepend the RenderScript system include path
-ifneq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
+ifneq ($(filter-out current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current,$(LOCAL_SDK_VERSION))),)
+# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
 LOCAL_RENDERSCRIPT_INCLUDES := \
     $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
     $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
diff --git a/core/llvm_config.mk b/core/llvm_config.mk
index bc90b95..4145028 100644
--- a/core/llvm_config.mk
+++ b/core/llvm_config.mk
@@ -41,12 +41,12 @@
 endif
 ifeq ($(TARGET_ARCH),x86)
   CLANG_CONFIG_EXTRA_CFLAGS += \
-    -target i686-android-linux \
+    -target i686-linux-android \
     -nostdlibinc \
-    -B$(TARGET_TOOLCHAIN_ROOT)/i686-android-linux/bin
+    -B$(TARGET_TOOLCHAIN_ROOT)/i686-linux-android/bin
   CLANG_CONFIG_EXTRA_LDFLAGS += \
-    -target i686-android-linux \
-    -B$(TARGET_TOOLCHAIN_ROOT)/i686-android-linux/bin
+    -target i686-linux-android \
+    -B$(TARGET_TOOLCHAIN_ROOT)/i686-linux-android/bin
   CLANG_CONFIG_UNKNOWN_CFLAGS += \
     -finline-limit=300 \
     -fno-inline-functions-called-once \
diff --git a/core/main.mk b/core/main.mk
index fa56b83..7adde61 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -52,6 +52,11 @@
 endif
 endif
 
+# Absolute path of the present working direcotry.
+# This overrides the shell variable $PWD, which does not necessarily points to
+# the top of the source tree, for example when "make -C" is used in m/mm/mmm.
+PWD := $(shell pwd)
+
 TOP := .
 TOPDIR :=
 
@@ -662,6 +667,9 @@
 .PHONY: factory_ramdisk
 factory_ramdisk: $(INSTALLED_FACTORY_RAMDISK_TARGET)
 
+.PHONY: factory_bundle
+factory_bundle: $(INSTALLED_FACTORY_BUNDLE_TARGET)
+
 .PHONY: systemtarball
 systemtarball: $(INSTALLED_SYSTEMTARBALL_TARGET)
 
@@ -740,6 +748,7 @@
     $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
     $(INSTALLED_RAMDISK_TARGET) \
     $(INSTALLED_FACTORY_RAMDISK_TARGET) \
+    $(INSTALLED_FACTORY_BUNDLE_TARGET) \
    )
 
   ifneq ($(TARGET_BUILD_PDK),true)
diff --git a/core/package.mk b/core/package.mk
index def715f..195b346 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -267,7 +267,7 @@
 # Most packages should link against the resources defined by framework-res.
 # Even if they don't have their own resources, they may use framework
 # resources.
-ifneq ($(filter-out current,$(LOCAL_SDK_RES_VERSION)),)
+ifneq ($(filter-out current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current,$(LOCAL_SDK_RES_VERSION))),)
 # for released sdk versions, the platform resources were built into android.jar.
 framework_res_package_export := \
     $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
diff --git a/core/pdk_config.mk b/core/pdk_config.mk
index 0949c38..a1f3f72 100644
--- a/core/pdk_config.mk
+++ b/core/pdk_config.mk
@@ -33,6 +33,25 @@
 endif  # fusion
 endif  # pdk or fusion
 
+
+# additional items to add to platform.zip for platform-java build
+# For these dirs, add classes.jar and javalib.jar from the dir to platform.zip
+# all paths under out dir
+PDK_PLATFORM_JAVA_ZIP_JAVA_LIB_DIR := \
+	target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates \
+	target/common/obj/JAVA_LIBRARIES/core_intermediates \
+	target/common/obj/JAVA_LIBRARIES/core-junit_intermediates \
+	target/common/obj/JAVA_LIBRARIES/ext_intermediates \
+	target/common/obj/JAVA_LIBRARIES/framework_intermediates \
+	target/common/obj/JAVA_LIBRARIES/android.test.runner_intermediates
+# not java libraries
+PDK_PLATFORM_JAVA_ZIP_CONTENTS := \
+	target/common/obj/APPS/framework-res_intermediates/package-export.apk \
+	target/common/obj/APPS/framework-res_intermediates/src/R.stamp
+PDK_PLATFORM_JAVA_ZIP_CONTENTS += $(foreach lib_dir,$(PDK_PLATFORM_JAVA_ZIP_JAVA_LIB_DIR),\
+    $(lib_dir)/classes.jar $(lib_dir)/javalib.jar)
+
+
 ifdef PDK_FUSION_PLATFORM_ZIP
 TARGET_BUILD_PDK := true
 ifeq (,$(wildcard $(PDK_FUSION_PLATFORM_ZIP)))
@@ -42,17 +61,27 @@
 _pdk_fusion_intermediates := $(call intermediates-dir-for, PACKAGING, pdk_fusion)
 _pdk_fusion_stamp := $(_pdk_fusion_intermediates)/pdk_fusion.stamp
 
+_pdk_fusion_file_list := $(shell unzip -Z -1 $(PDK_FUSION_PLATFORM_ZIP) \
+    '*[^/]' -x 'target/common/*' 2>/dev/null)
+_pdk_fusion_java_file_list := \
+	$(shell unzip -Z -1 $(PDK_FUSION_PLATFORM_ZIP) 'target/common/*' 2>/dev/null)
+_pdk_fusion_files := $(addprefix $(_pdk_fusion_intermediates)/,\
+    $(_pdk_fusion_file_list) $(_pdk_fusion_java_file_list))
+ifneq ($(_pdk_fusion_java_file_list),)
+TARGET_BUILD_PDK_JAVA := true
+endif
+
 $(_pdk_fusion_stamp) : $(PDK_FUSION_PLATFORM_ZIP)
 	@echo "Unzip $(dir $@) <- $<"
 	$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
 	$(hide) unzip -qo $< -d $(dir $@)
-	$(hide) touch $@
 	$(call split-long-arguments,touch,$(_pdk_fusion_files))
+	$(hide) touch $@
 
-_pdk_fusion_file_list := $(shell unzip -Z -1 $(PDK_FUSION_PLATFORM_ZIP) '*[^/]' 2>/dev/null)
-_pdk_fusion_files := $(addprefix $(_pdk_fusion_intermediates)/, $(_pdk_fusion_file_list))
+
 $(_pdk_fusion_files) : $(_pdk_fusion_stamp)
 
+
 # Implicit pattern rules to copy the fusion files to the system image directory.
 # Note that if there is already explicit rule in the build system to generate a file,
 # the pattern rule will be just ignored by make.
@@ -62,14 +91,47 @@
 	@mkdir -p $(dir $@)
 	$(hide) cp -fpPR $< $@
 
-ALL_PDK_FUSION_FILES := $(addprefix $(PRODUCT_OUT)/, $(_pdk_fusion_file_list))
+ifeq (true,$(TARGET_BUILD_PDK_JAVA))
 
+define JAVA_dependency_template
+$(OUT_DIR)/$(strip $(1)): $(_pdk_fusion_intermediates)/$(strip $(1)) $(OUT_DIR)/$(strip $(2)) \
+  $(_pdk_fusion_stamp)
+	@mkdir -p $$(dir $$@)
+	$(hide) cp -fpPR $$< $$@
+endef
+
+# needs explicit dependency as package-export.apk is not explicitly pulled
+$(eval $(call JAVA_dependency_template,\
+target/common/obj/APPS/framework-res_intermediates/src/R.stamp,\
+target/common/obj/APPS/framework-res_intermediates/package-export.apk))
+
+# javalib.jar should pull classes.jar as classes.jar is not explicitly pulled.
+$(foreach lib_dir,$(PDK_PLATFORM_JAVA_ZIP_JAVA_LIB_DIR),\
+$(eval $(call JAVA_dependency_template,$(lib_dir)/javalib.jar,\
+$(lib_dir)/classes.jar)))
+
+# implicit rules for all others
+$(TARGET_COMMON_OUT_ROOT)/% : $(_pdk_fusion_intermediates)/target/common/% $(_pdk_fusion_stamp)
+	@mkdir -p $(dir $@)
+	$(hide) cp -fpPR $< $@
 endif
 
+ALL_PDK_FUSION_FILES := $(addprefix $(PRODUCT_OUT)/, $(_pdk_fusion_file_list))
+
+endif # PDK_FUSION_PLATFORM_ZIP
+
 ifeq ($(TARGET_BUILD_PDK),true)
 
+ifeq ($(TARGET_BUILD_PDK_JAVA),)
+
 # SDK used for Java build under PDK
 PDK_BUILD_SDK_VERSION := $(lastword $(TARGET_AVAILABLE_SDK_VERSIONS))
 $(info PDK Build uses SDK $(PDK_BUILD_SDK_VERSION))
 
+else # PDK_JAVA
+
+$(info PDK Build uses the current platform API)
+
+endif # PDK_JAVA
+
 endif # BUILD_PDK
diff --git a/core/prebuilt.mk b/core/prebuilt.mk
index b06bb6e..f59a17b 100644
--- a/core/prebuilt.mk
+++ b/core/prebuilt.mk
@@ -35,6 +35,13 @@
   prebuilt_module_is_a_library :=
 endif
 
+# Don't install static libraries by default.
+ifndef LOCAL_UNINSTALLABLE_MODULE
+ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
+  LOCAL_UNINSTALLABLE_MODULE := true
+endif
+endif
+
 ifeq ($(LOCAL_STRIP_MODULE),true)
   ifdef LOCAL_IS_HOST_MODULE
     $(error Cannot strip host module LOCAL_PATH=$(LOCAL_PATH))
diff --git a/core/product.mk b/core/product.mk
index b001ca2..4849d7a 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -85,8 +85,9 @@
     PRODUCT_DEFAULT_WIFI_CHANNELS \
     PRODUCT_DEFAULT_DEV_CERTIFICATE \
     PRODUCT_RESTRICT_VENDOR_FILES \
-    PRODUCT_FACTORY_RAMDISK_MODULES \
     PRODUCT_VENDOR_KERNEL_HEADERS \
+    PRODUCT_FACTORY_RAMDISK_MODULES \
+    PRODUCT_FACTORY_BUNDLE_MODULES
 
 
 define dump-product
diff --git a/core/static_java_library.mk b/core/static_java_library.mk
index 9165050..367ea5f 100644
--- a/core/static_java_library.mk
+++ b/core/static_java_library.mk
@@ -64,7 +64,7 @@
 framework_res_package_export_deps :=
 # Please refer to package.mk
 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
-ifneq ($(filter-out current,$(LOCAL_SDK_RES_VERSION)),)
+ifneq ($(filter-out current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current,$(LOCAL_SDK_RES_VERSION))),)
 framework_res_package_export := \
     $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
 framework_res_package_export_deps := $(framework_res_package_export)
diff --git a/core/tasks/factory_bundle.mk b/core/tasks/factory_bundle.mk
new file mode 100644
index 0000000..06d7a78
--- /dev/null
+++ b/core/tasks/factory_bundle.mk
@@ -0,0 +1,80 @@
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ifeq (,$(ONE_SHOT_MAKEFILE))
+
+# PRODUCT_FACTORY_RAMDISK_MODULES consists of "<module_name>:<install_path>[:<install_path>...]" tuples.
+# <install_path> is relative to the staging directory for the bundle.
+# 
+# Only host modules can be installed here. 
+# (It's possible to relax this, but it's not needed and kind of tricky.  We'll need to add
+# a better way of specifying the class. Really the answer is to stop having modules with
+# duplicate names)
+#
+# You can also add files with PRODUCT_COPY_FILES if necessary.
+#
+# For example:
+# PRODUCT_FACTORY_BUNDLE_MODULES := \
+#     adb:adb fastboot:fastboot
+requested_modules := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_FACTORY_BUNDLE_MODULES))
+
+root_dir := $(PRODUCT_OUT)/factory_bundle
+leaf := $(strip $(TARGET_PRODUCT))-factory_bundle-$(FILE_NAME_TAG)
+named_dir := $(PRODUCT_OUT)/$(leaf)
+tarball := $(PRODUCT_OUT)/$(leaf).tgz
+
+copied_files := \
+  $(foreach _fb_m, $(requested_modules), $(strip \
+    $(eval _fb_m_tuple := $(subst :, ,$(_fb_m))) \
+    $(eval _fb_m_name := $(word 1,$(_fb_m_tuple))) \
+    $(eval _fb_dests := $(wordlist 2,999,$(_fb_m_tuple))) \
+    $(eval _fb_m_built := $(filter $(HOST_OUT)/%, $(ALL_MODULES.$(_fb_m_name).BUILT))) \
+    $(if $(_fb_m_built),,$(error no built file in requested_modules for '$(_fb_m_built)'))\
+    $(foreach _fb_f,$(_fb_dests),$(eval $(call copy-one-file,$(_fb_m_built),$(root_dir)/$(_fb_f))))\
+    $(addprefix $(root_dir)/,$(_fb_dests)) \
+    )) \
+  $(filter $(root_dir)/%, $(ALL_DEFAULT_INSTALLED_MODULES))
+
+ifneq (,$(strip $(copied_files)))
+
+#
+# These files are made by magic so we need to explicitly include them
+#
+$(eval $(call copy-one-file,$(TARGET_OUT)/build.prop,$(root_dir)/build.prop))
+copied_files += $(root_dir)/build.prop
+
+$(eval $(call copy-one-file,$(PRODUCT_OUT)/factory_ramdisk.img,$(root_dir)/factory_ramdisk.img))
+copied_files += $(root_dir)/factory_ramdisk.img
+#
+# End magic
+#
+
+$(tarball): PRIVATE_ROOT_DIR := $(root_dir)
+$(tarball): PRIVATE_NAMED_DIR := $(named_dir)
+
+$(tarball): $(copied_files)
+	@echo "Tarball: $@"
+	$(hide) rm -rf $(PRIVATE_NAMED_DIR)
+	$(hide) ( cp -r $(PRIVATE_ROOT_DIR) $(PRIVATE_NAMED_DIR) \
+			&& tar cfz $@ -C $(dir $(PRIVATE_NAMED_DIR)) $(notdir $(PRIVATE_NAMED_DIR)) \
+			) && rm -rf $(PRIVATE_NAMED_DIR)
+
+INSTALLED_FACTORY_BUNDLE_TARGET := $(tarball)
+
+endif
+
+endif # ONE_SHOT_MAKEFILE
+
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index c97306c..021617d 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -41,7 +41,7 @@
   # which is the version that we reveal to the end user.
   # Update this value when the platform version changes (rather
   # than overriding it somewhere else).  Can be an arbitrary string.
-  PLATFORM_VERSION := JellyBean
+  PLATFORM_VERSION := 4.1
 endif
 
 ifeq "" "$(PLATFORM_SDK_VERSION)"
@@ -53,13 +53,13 @@
   # intermediate builds).  During development, this number remains at the
   # SDK version the branch is based on and PLATFORM_VERSION_CODENAME holds
   # the code-name of the new development work.
-  PLATFORM_SDK_VERSION := 15
+  PLATFORM_SDK_VERSION := 16
 endif
 
 ifeq "" "$(PLATFORM_VERSION_CODENAME)"
   # This is the current development code-name, if the build is not a final
   # release build.  If this is a final release build, it is simply "REL".
-  PLATFORM_VERSION_CODENAME := JellyBean
+  PLATFORM_VERSION_CODENAME := REL
 endif
 
 ifeq "" "$(DEFAULT_APP_TARGET_SDK)"
diff --git a/envsetup.sh b/envsetup.sh
index 8b7eea9..84ec3e5 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -118,7 +118,7 @@
     export ANDROID_EABI_TOOLCHAIN=
     local ARCH=$(get_build_var TARGET_ARCH)
     case $ARCH in
-        x86) toolchaindir=x86/i686-android-linux-4.4.3/bin
+        x86) toolchaindir=x86/i686-linux-android-4.6/bin
             ;;
         arm) toolchaindir=arm/arm-linux-androideabi-4.6/bin
             ;;
@@ -737,7 +737,7 @@
    local ARCH=$(get_build_var TARGET_ARCH)
    local GDB
    case "$ARCH" in
-       x86) GDB=i686-android-linux-gdb;;
+       x86) GDB=i686-linux-android-gdb;;
        arm) GDB=arm-linux-androideabi-gdb;;
        *) echo "Unknown arch $ARCH"; return 1;;
    esac
diff --git a/target/board/generic/BoardConfig.mk b/target/board/generic/BoardConfig.mk
index bc999fa..cee09ce 100644
--- a/target/board/generic/BoardConfig.mk
+++ b/target/board/generic/BoardConfig.mk
@@ -35,7 +35,9 @@
 # Enable dex-preoptimization to speed up the first boot sequence
 # of an SDK AVD. Note that this operation only works on Linux for now
 ifeq ($(HOST_OS),linux)
-WITH_DEXPREOPT := true
+  ifeq ($(WITH_DEXPREOPT),)
+    WITH_DEXPREOPT := true
+  endif
 endif
 
 # Build OpenGLES emulation guest and host libraries
diff --git a/target/board/generic_mips/Android.mk b/target/board/generic_mips/Android.mk
new file mode 100644
index 0000000..abf8d57
--- /dev/null
+++ b/target/board/generic_mips/Android.mk
@@ -0,0 +1,17 @@
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
diff --git a/target/board/generic_mips/BoardConfig.mk b/target/board/generic_mips/BoardConfig.mk
new file mode 100644
index 0000000..722e112
--- /dev/null
+++ b/target/board/generic_mips/BoardConfig.mk
@@ -0,0 +1,53 @@
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# BoardConfig.mk
+#
+# Product-specific compile-time definitions.
+#
+
+# The generic product target doesn't have any hardware-specific pieces.
+TARGET_NO_BOOTLOADER := true
+TARGET_NO_KERNEL := true
+
+TARGET_ARCH := mips
+ifeq (,$(TARGET_ARCH_VARIANT))
+TARGET_ARCH_VARIANT := mips32r2-fp
+endif
+GET_CPU_ABI  := mips
+
+HAVE_HTC_AUDIO_DRIVER := true
+BOARD_USES_GENERIC_AUDIO := true
+
+# no hardware camera
+USE_CAMERA_STUB := true
+
+# Set /system/bin/sh to ash, not mksh, to make sure we can switch back.
+TARGET_SHELL := ash
+
+# Enable dex-preoptimization to speed up the first boot sequence
+# of an SDK AVD. Note that this operation only works on Linux for now
+ifeq ($(HOST_OS),linux)
+  ifeq ($(WITH_DEXPREOPT),)
+    WITH_DEXPREOPT := true
+  endif
+endif
+
+# Build OpenGLES emulation guest and host libraries
+BUILD_EMULATOR_OPENGL := true
+
+# Build and enable the OpenGL ES View renderer. When running on the emulator,
+# the GLES renderer disables itself if host GL acceleration isn't available.
+USE_OPENGL_RENDERER := true
diff --git a/target/board/generic_mips/README.txt b/target/board/generic_mips/README.txt
new file mode 100644
index 0000000..b31a857
--- /dev/null
+++ b/target/board/generic_mips/README.txt
@@ -0,0 +1,9 @@
+The "generic_mips" product defines a MIPS based non-hardware-specific
+target without a kernel or bootloader.
+
+It can be used to build the entire user-level system, and
+will work with the emulator, though sound will not work
+(see the "emulator" product for that).
+
+It is not a product "base class"; no other products inherit
+from it or use it in any way.
diff --git a/target/board/generic_mips/device.mk b/target/board/generic_mips/device.mk
new file mode 100644
index 0000000..bd08fde
--- /dev/null
+++ b/target/board/generic_mips/device.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This is a build configuration for the product aspects that
+# are specific to the emulator.
+
+PRODUCT_PROPERTY_OVERRIDES := \
+    ro.ril.hsxpa=1 \
+    ro.ril.gprsclass=10
+
+PRODUCT_COPY_FILES := \
+    development/data/etc/apns-conf.xml:system/etc/apns-conf.xml \
+    development/data/etc/vold.conf:system/etc/vold.conf \
+    development/tools/emulator/system/camera/media_profiles.xml:system/etc/media_profiles.xml
+
+PRODUCT_PACKAGES := \
+    audio.primary.goldfish
diff --git a/target/board/generic_mips/system.prop b/target/board/generic_mips/system.prop
new file mode 100644
index 0000000..137a0f9
--- /dev/null
+++ b/target/board/generic_mips/system.prop
@@ -0,0 +1,6 @@
+#
+# system.prop for generic sdk
+#
+
+rild.libpath=/system/lib/libreference-ril.so
+rild.libargs=-d /dev/ttyS0
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
index c62b0a4..c0d7a25 100644
--- a/target/board/generic_x86/BoardConfig.mk
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -8,7 +8,7 @@
 TARGET_NO_KERNEL := true
 TARGET_CPU_ABI := x86
 TARGET_ARCH := x86
-TARGET_ARCH_VARIANT := x86-atom
+TARGET_ARCH_VARIANT := x86
 TARGET_PRELINK_MODULE := false
 
 # The IA emulator (qemu) uses the Goldfish devices
@@ -18,6 +18,9 @@
 # no hardware camera
 USE_CAMERA_STUB := true
 
+# customize the malloced address to be 16-byte aligned
+BOARD_MALLOC_ALIGNMENT := 16
+
 # Set /system/bin/sh to ash, not mksh, to make sure we can switch back.
 TARGET_SHELL := ash
 
diff --git a/target/product/AndroidProducts.mk b/target/product/AndroidProducts.mk
index 44b9000..9279633 100644
--- a/target/product/AndroidProducts.mk
+++ b/target/product/AndroidProducts.mk
@@ -36,10 +36,13 @@
     $(LOCAL_DIR)/core.mk \
     $(LOCAL_DIR)/generic.mk \
     $(LOCAL_DIR)/generic_x86.mk \
+    $(LOCAL_DIR)/generic_mips.mk \
     $(LOCAL_DIR)/full.mk \
     $(LOCAL_DIR)/full_x86.mk \
+    $(LOCAL_DIR)/full_mips.mk \
     $(LOCAL_DIR)/vbox_x86.mk \
     $(LOCAL_DIR)/sdk.mk \
     $(LOCAL_DIR)/sdk_x86.mk \
+    $(LOCAL_DIR)/sdk_mips.mk \
     $(LOCAL_DIR)/large_emu_hw.mk
 endif
diff --git a/target/product/full_mips.mk b/target/product/full_mips.mk
new file mode 100644
index 0000000..886cf31
--- /dev/null
+++ b/target/product/full_mips.mk
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This is a build configuration for a full-featured build of the
+# Open-Source part of the tree. It's geared toward a US-centric
+# mips build quite specifically for the emulator, and might not be
+# entirely appropriate to inherit from for on-device configurations.
+
+PRODUCT_PACKAGES := \
+    Camera
+
+$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base_telephony.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_mips/device.mk)
+
+# Overrides
+PRODUCT_NAME := full_mips
+PRODUCT_DEVICE := generic_mips
+PRODUCT_BRAND := Android
+PRODUCT_MODEL := Full MIPS Android on Emulator
diff --git a/target/product/generic_mips.mk b/target/product/generic_mips.mk
new file mode 100644
index 0000000..7b53d04
--- /dev/null
+++ b/target/product/generic_mips.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This is a generic phone product that isn't specialized for a specific device.
+# It includes the base Android platform.
+
+$(call inherit-product, $(SRC_TARGET_DIR)/product/generic_no_telephony.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/telephony.mk)
+
+# Overrides
+PRODUCT_BRAND := generic_mips
+PRODUCT_DEVICE := generic_mips
+PRODUCT_NAME := generic_mips
diff --git a/target/product/generic_no_telephony.mk b/target/product/generic_no_telephony.mk
index 5863435..71a86ea 100644
--- a/target/product/generic_no_telephony.mk
+++ b/target/product/generic_no_telephony.mk
@@ -53,8 +53,10 @@
 PRODUCT_PACKAGES += \
     librs_jni \
     libvideoeditor_jni \
+    libvideoeditor_core \
+    libvideoeditor_osal \
+    libvideoeditor_videofilters \
     libvideoeditorplayer \
-    libvideoeditor_core
 
 PRODUCT_PACKAGES += \
     audio.primary.default \
@@ -77,6 +79,7 @@
     ro.carrier=unknown
 
 $(call inherit-product-if-exists, frameworks/base/data/fonts/fonts.mk)
+$(call inherit-product-if-exists, external/cibu-fonts/fonts.mk)
 $(call inherit-product-if-exists, external/lohit-fonts/fonts.mk)
 $(call inherit-product-if-exists, frameworks/base/data/keyboards/keyboards.mk)
 $(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
diff --git a/target/product/sdk_mips.mk b/target/product/sdk_mips.mk
new file mode 100644
index 0000000..2072400
--- /dev/null
+++ b/target/product/sdk_mips.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This is a build configuration for a full-featured build of the
+# Open-Source part of the tree. It's geared toward a US-centric
+# build quite specifically for the emulator, and might not be
+# entirely appropriate to inherit from for on-device configurations.
+
+$(call inherit-product, $(SRC_TARGET_DIR)/product/sdk.mk)
+
+# Overrides
+PRODUCT_BRAND := generic_mips
+PRODUCT_NAME := sdk_mips
+PRODUCT_DEVICE := generic_mips
+PRODUCT_MODEL := Android SDK for Mips
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index c4d73c8..d8d9bf1 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -76,6 +76,8 @@
     private static final String CERT_SF_NAME = "META-INF/CERT.SF";
     private static final String CERT_RSA_NAME = "META-INF/CERT.RSA";
 
+    private static final String OTACERT_NAME = "META-INF/com/android/otacert";
+
     // Files matching this pattern are not copied to the output.
     private static Pattern stripPattern =
             Pattern.compile("^META-INF/(.*)[.](SF|RSA|DSA)$");
@@ -199,6 +201,7 @@
             String name = entry.getName();
             if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) &&
                 !name.equals(CERT_SF_NAME) && !name.equals(CERT_RSA_NAME) &&
+                !name.equals(OTACERT_NAME) &&
                 (stripPattern == null ||
                  !stripPattern.matcher(name).matches())) {
                 InputStream data = jar.getInputStream(entry);
@@ -217,6 +220,39 @@
         return output;
     }
 
+    /**
+     * Add a copy of the public key to the archive; this should
+     * exactly match one of the files in
+     * /system/etc/security/otacerts.zip on the device.  (The same
+     * cert can be extracted from the CERT.RSA file but this is much
+     * easier to get at.)
+     */
+    private static void addOtacert(JarOutputStream outputJar,
+                                   File publicKeyFile,
+                                   long timestamp,
+                                   Manifest manifest)
+        throws IOException, GeneralSecurityException {
+        BASE64Encoder base64 = new BASE64Encoder();
+        MessageDigest md = MessageDigest.getInstance("SHA1");
+
+        JarEntry je = new JarEntry(OTACERT_NAME);
+        je.setTime(timestamp);
+        outputJar.putNextEntry(je);
+        FileInputStream input = new FileInputStream(publicKeyFile);
+        byte[] b = new byte[4096];
+        int read;
+        while ((read = input.read(b)) != -1) {
+            outputJar.write(b, 0, read);
+            md.update(b, 0, read);
+        }
+        input.close();
+
+        Attributes attr = new Attributes();
+        attr.putValue("SHA1-Digest", base64.encode(md.digest()));
+        manifest.getEntries().put(OTACERT_NAME, attr);
+    }
+
+
     /** Write to another stream and also feed it to the Signature object. */
     private static class SignatureOutputStream extends FilterOutputStream {
         private Signature mSignature;
@@ -445,7 +481,8 @@
         FileOutputStream outputFile = null;
 
         try {
-            X509Certificate publicKey = readPublicKey(new File(args[argstart+0]));
+            File publicKeyFile = new File(args[argstart+0]);
+            X509Certificate publicKey = readPublicKey(publicKeyFile);
 
             // Assume the certificate is valid for at least an hour.
             long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000;
@@ -464,8 +501,17 @@
 
             JarEntry je;
 
-            // MANIFEST.MF
             Manifest manifest = addDigestsToManifest(inputJar);
+
+            // Everything else
+            copyFiles(manifest, inputJar, outputJar, timestamp);
+
+            // otacert
+            if (signWholeFile) {
+                addOtacert(outputJar, publicKeyFile, timestamp, manifest);
+            }
+
+            // MANIFEST.MF
             je = new JarEntry(JarFile.MANIFEST_NAME);
             je.setTime(timestamp);
             outputJar.putNextEntry(je);
@@ -486,9 +532,6 @@
             outputJar.putNextEntry(je);
             writeSignatureBlock(signature, publicKey, outputJar);
 
-            // Everything else
-            copyFiles(manifest, inputJar, outputJar, timestamp);
-
             outputJar.close();
             outputJar = null;
             outputStream.flush();