Support to build emmap_mata.zip in unbundled builds.

Bug: 6987838
Change-Id: Id6c81b08c4859442b7d52054ed5f278575719d1a
diff --git a/core/Makefile b/core/Makefile
index 2a214c6..4dde9f4 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -1287,12 +1287,16 @@
 # A zip of emma code coverage meta files. Generated for fully emma
 # instrumented build.
 #
+ifeq (true,$(EMMA_INSTRUMENT))
 EMMA_META_ZIP := $(PRODUCT_OUT)/emma_meta.zip
-$(EMMA_META_ZIP): $(INSTALLED_SYSTEMIMAGE)
+# the dependency will be set up later in build/core/main.mk.
+$(EMMA_META_ZIP) :
 	@echo "Collecting Emma coverage meta files."
 	$(hide) find $(TARGET_COMMON_OUT_ROOT) -name "coverage.em" | \
 		zip -@ -q $@
 
+endif # EMMA_INSTRUMENT=true
+
 # -----------------------------------------------------------------
 # dalvik something
 .PHONY: dalvikfiles
diff --git a/core/main.mk b/core/main.mk
index 64be9ff..49367ec 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -780,10 +780,6 @@
 # dist_files only for putting your library into the dist directory with a full build.
 .PHONY: dist_files
 
-ifeq ($(EMMA_INSTRUMENT),true)
-  $(call dist-for-goals, dist_files, $(EMMA_META_ZIP))
-endif
-
 # Dist for droid if droid is among the cmd goals, or no cmd goal is given.
 ifneq ($(filter droid,$(MAKECMDGOALS))$(filter ||,|$(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))|),)
 
@@ -798,10 +794,15 @@
     unbundled_build_modules := $(TARGET_BUILD_APPS)
   endif
 
+  apps_only_installed_files := $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED))
   # dist the unbundled app.
-  $(call dist-for-goals,apps_only, \
-    $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED)) \
-  )
+  $(call dist-for-goals,apps_only, $(apps_only_installed_files))
+
+  ifeq ($(EMMA_INSTRUMENT),true)
+    $(EMMA_META_ZIP) : $(apps_only_installed_files)
+
+    $(call dist-for-goals,apps_only, $(EMMA_META_ZIP))
+  endif
 
 .PHONY: apps_only
 apps_only: $(unbundled_build_modules)
@@ -830,6 +831,12 @@
     )
   endif
 
+  ifeq ($(EMMA_INSTRUMENT),true)
+    $(EMMA_META_ZIP) : $(INSTALLED_SYSTEMIMAGE)
+
+    $(call dist-for-goals, dist_files, $(EMMA_META_ZIP))
+  endif
+
 # Building a full system-- the default is to build droidcore
 droid: droidcore dist_files