resolved conflicts for merge of 2b8d2383 to gingerbread

Change-Id: I9174f843f0fde139a7d582f45b027f3face5c981
diff --git a/core/envsetup.mk b/core/envsetup.mk
index f8a2027..86aa2f3 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -342,6 +342,7 @@
 $(info   TARGET_BUILD_VARIANT=$(TARGET_BUILD_VARIANT))
 $(info   TARGET_SIMULATOR=$(TARGET_SIMULATOR))
 $(info   TARGET_BUILD_TYPE=$(TARGET_BUILD_TYPE))
+$(info   TARGET_BUILD_APPS=$(TARGET_BUILD_APPS))
 $(info   TARGET_ARCH=$(TARGET_ARCH))
 $(info   HOST_ARCH=$(HOST_ARCH))
 $(info   HOST_OS=$(HOST_OS))
diff --git a/core/main.mk b/core/main.mk
index ea8b66b..9d1ad85 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -46,6 +46,7 @@
 BUILD_SYSTEM := $(TOPDIR)build/core
 
 # This is the default target.  It must be the first declared target.
+.PHONY: droid
 DEFAULT_GOAL := droid
 $(DEFAULT_GOAL):
 
@@ -688,63 +689,60 @@
 	$(INSTALLED_USERDATAIMAGE_TARGET) \
 	$(INSTALLED_FILES_FILE)
 
-# The actual files built by the droidcore target changes depending
-# on the build variant.
-.PHONY: droid tests
-ifeq ($(strip $(is_unbundled_app_build)),true)
-unbundled_build_modules :=
-ifdef UNBUNDLED_APPS
-unbundled_build_modules := $(UNBUNDLED_APPS)
-else # UNBUNDLED_APPS
-# Otherwise we build all modules in the source tree.
-unbundled_build_modules := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS)))
-endif # UNBUNDLED_APPS
-droid: $(unbundled_build_modules)
-else # is_unbundled_app_build
-droid: droidcore
-endif # is_unbundled_app_build
-tests: droidcore
+ifneq ($(TARGET_BUILD_APPS),)
+  # If this build is just for apps, only build apps and not the full system by default.
 
-ifneq ($(strip $(is_unbundled_app_build)),true)
-$(call dist-for-goals, droid, \
-	$(INTERNAL_UPDATE_PACKAGE_TARGET) \
-	$(INTERNAL_OTA_PACKAGE_TARGET) \
-	$(SYMBOLS_ZIP) \
-	$(APPS_ZIP) \
-	$(INTERNAL_EMULATOR_PACKAGE_TARGET) \
-	$(PACKAGE_STATS_FILE) \
-	$(INSTALLED_FILES_FILE) \
-	$(INSTALLED_BUILD_PROP_TARGET) \
-	$(BUILT_TARGET_FILES_PACKAGE) \
-	$(INSTALLED_ANDROID_INFO_TXT_TARGET) \
-	$(INSTALLED_RAMDISK_TARGET) \
- )
+  unbundled_build_modules :=
+  ifneq ($(filter all,$(TARGET_BUILD_APPS)),)
+    # If they used the magic goal "all" then build everything
+    unbundled_build_modules := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS)))
+  else
+    unbundled_build_modules := $(TARGET_BUILD_APPS)
+  endif
 
-ifeq ($(EMMA_INSTRUMENT),true)
-$(call dist-for-goals, droid, \
-	$(EMMA_META_ZIP) \
- )
-endif
-
-# Tests are installed in userdata.img.  If we're building the tests
-# variant, copy it for "make tests dist".  Also copy a zip of the
-# contents of userdata.img, so that people can easily extract a
-# single .apk.
-ifeq ($(TARGET_BUILD_VARIANT),tests)
-$(call dist-for-goals, droid, \
-	$(INSTALLED_USERDATAIMAGE_TARGET) \
-	$(BUILT_TESTS_ZIP_PACKAGE) \
- )
-endif
-
-else # is_unbundled_app_build
-# dist the unbundled app.
-ifdef UNBUNDLED_APPS
-  $(call dist-for-goals,droid, \
-    $(foreach m,$(UNBUNDLED_APPS),$(ALL_MODULES.$(m).INSTALLED)) \
+  # dist the unbundled app.
+  $(call dist-for-goals,apps_only, \
+    $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED)) \
   )
-endif # UNBUNDLED_APPS
-endif # is_unbundled_app_build
+
+.PHONY: apps_only
+apps_only: $(unbundled_build_modules)
+
+droid: apps_only
+
+else # TARGET_BUILD_APPS
+  $(call dist-for-goals, droidcore, \
+    $(INTERNAL_UPDATE_PACKAGE_TARGET) \
+    $(INTERNAL_OTA_PACKAGE_TARGET) \
+    $(SYMBOLS_ZIP) \
+    $(APPS_ZIP) \
+    $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
+    $(PACKAGE_STATS_FILE) \
+    $(INSTALLED_FILES_FILE) \
+    $(INSTALLED_BUILD_PROP_TARGET) \
+    $(BUILT_TARGET_FILES_PACKAGE) \
+    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
+   )
+
+  # Tests are installed in userdata.img.  If we're building the tests
+  # variant, copy it for "make tests dist".  Also copy a zip of the
+  # contents of userdata.img, so that people can easily extract a
+  # single .apk.
+  ifeq ($(TARGET_BUILD_VARIANT),tests)
+  $(call dist-for-goals, droid, \
+    $(INSTALLED_USERDATAIMAGE_TARGET) \
+    $(BUILT_TESTS_ZIP_PACKAGE) \
+   )
+  endif
+
+# Building a full system-- the default is to build droidcore
+droid: droidcore
+
+endif
+
+
+.PHONY: droid tests
+tests: droidcore
 
 .PHONY: docs
 docs: $(ALL_DOCS)
diff --git a/core/package.mk b/core/package.mk
index e7be05f..cdeefb4 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -311,7 +311,7 @@
 # Define the rule to build the actual package.
 $(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
 $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
-ifeq ($(strip $(is_unbundled_app_build)),true)
+ifneq ($(TARGET_BUILD_APPS),)
     # Include all resources for unbundled apps.
     $(LOCAL_BUILT_MODULE): PRODUCT_AAPT_CONFIG :=
 endif
diff --git a/core/product_config.mk b/core/product_config.mk
index a7eba92..50bc7bc 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -157,13 +157,12 @@
   ifneq ($(words $(unbundled_goals)),1)
     $(error Only one APP-* goal may be specified; saw "$(unbundled_goals)"))
   endif
-  UNBUNDLED_APPS := $(strip $(subst -, ,$(patsubst APP-%,%,$(unbundled_goals))))
+  TARGET_BUILD_APPS := $(strip $(subst -, ,$(patsubst APP-%,%,$(unbundled_goals))))
   ifneq ($(filter $(DEFAULT_GOAL),$(MAKECMDGOALS)),)
     MAKECMDGOALS := $(patsubst $(unbundled_goals),,$(MAKECMDGOALS))
   else
     MAKECMDGOALS := $(patsubst $(unbundled_goals),$(DEFAULT_GOAL),$(MAKECMDGOALS))
   endif
-  is_unbundled_app_build := true
 
 .PHONY: $(unbundled_goals)
 $(unbundled_goals): $(MAKECMDGOALS)
@@ -178,7 +177,7 @@
 include $(BUILD_SYSTEM)/product.mk
 include $(BUILD_SYSTEM)/device.mk
 
-ifeq ($(strip $(is_unbundled_app_build)),true)
+ifneq ($(strip $(TARGET_BUILD_APPS)),)
   # An unbundled app build needs only the core product makefiles.
   $(call import-products,$(call get-product-makefiles,\
       $(SRC_TARGET_DIR)/product/AndroidProducts.mk))
@@ -189,7 +188,7 @@
   #TODO: when we start allowing direct pointers to product files,
   #    guarantee that they're in this list.
   $(call import-products, $(get-all-product-makefiles))
-endif # is_unbundled_app_build
+endif # TARGET_BUILD_APPS
 $(check-all-products)
 #$(dump-products)
 #$(error done)