Dist only if the goal is to be built

Change-Id: I1b794f36a6dc39ce68cc990b967d2d55118c92ca
http://b/issue?id=2635603
diff --git a/core/Makefile b/core/Makefile
index 78d1c32..c2cd3ff 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -986,8 +986,12 @@
 
 .PHONY: installed-file-list
 installed-file-list: $(INSTALLED_FILES_FILE)
+ifneq ($(filter sdk,$(MAKECMDGOALS)),)
 $(call dist-for-goals, sdk, $(INSTALLED_FILES_FILE))
+endif
+ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
 $(call dist-for-goals, sdk_addon, $(INSTALLED_FILES_FILE))
+endif
 
 # -----------------------------------------------------------------
 # A zip of the tests that are built when running "make tests".
diff --git a/core/main.mk b/core/main.mk
index 1fd546e..fb5fe62 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -691,6 +691,8 @@
 .PHONY: droid tests
 droid tests: droidcore
 
+# 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))|),)
 $(call dist-for-goals, droid, \
 	$(INTERNAL_UPDATE_PACKAGE_TARGET) \
 	$(INTERNAL_OTA_PACKAGE_TARGET) \
@@ -709,7 +711,7 @@
 $(call dist-for-goals, droid, \
 	$(EMMA_META_ZIP) \
  )
-endif
+endif  # EMMA_INSTRUMENT
 
 # 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
@@ -720,7 +722,8 @@
 	$(INSTALLED_USERDATAIMAGE_TARGET) \
 	$(BUILT_TESTS_ZIP_PACKAGE) \
  )
-endif
+endif  # tests
+endif  # droid in $(MAKECMDGOALS)
 
 .PHONY: docs
 docs: $(ALL_DOCS)
@@ -728,10 +731,12 @@
 .PHONY: sdk
 ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
 sdk: $(ALL_SDK_TARGETS)
+ifneq ($(filter sdk,$(MAKECMDGOALS)),)
 $(call dist-for-goals,sdk, \
 	$(ALL_SDK_TARGETS) \
 	$(SYMBOLS_ZIP) \
  )
+endif
 
 .PHONY: samplecode
 sample_MODULES := $(sort $(call get-tagged-modules,samples))