Refactor calculation LOCAL_CHECKED_MODULE

To remove dup code;
Also added two more umbrella targets: host, target.

Change-Id: Ia6deed2940a26a31ad823fe54816840861f3fb72
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 92cf58c..1cdc836 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -531,6 +531,14 @@
   endif
 endif
 
+need_compile_java :=
+ifdef java_alternative_checked_module
+ifneq (,$(strip $(all_java_sources)$(full_static_java_libs))$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED)))
+  need_compile_java := true
+  LOCAL_CHECKED_MODULE := $(java_alternative_checked_module)
+endif
+endif
+
 # If they request that this module not be checked, then don't.
 # PLEASE DON'T SET THIS.  ANY PLACES THAT SET THIS WITHOUT
 # GOOD REASON WILL HAVE IT REMOVED.
@@ -585,8 +593,8 @@
 # it will default to recursive expansion.
 $(foreach tag,$(LOCAL_MODULE_TAGS),\
     $(eval ALL_MODULE_TAGS.$(tag) := \
-	    $(ALL_MODULE_TAGS.$(tag)) \
-	    $(LOCAL_INSTALLED_MODULE)))
+        $(ALL_MODULE_TAGS.$(tag)) \
+        $(LOCAL_INSTALLED_MODULE)))
 
 # Add this module name to the tag list of each specified tag.
 $(foreach tag,$(LOCAL_MODULE_TAGS),\
@@ -595,18 +603,12 @@
 ###########################################################
 ## umbrella targets used to verify builds
 ###########################################################
-check_build_target := $(LOCAL_CHECKED_MODULE)
 j_or_n :=
 ifneq (,$(filter EXECUTABLES SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)))
 j_or_n := native
 else
 ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS)))
 j_or_n := java
-# We don't want to verify the jni code when you just want to check the Java code.
-# See LOCAL_CHECKED_MODULE in build/core/java.mk
-ifneq (,$(strip $(all_java_sources)$(full_static_java_libs))$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED)))
-check_build_target := $(full_classes_compiled_jar)
-endif
 endif
 endif
 ifdef LOCAL_IS_HOST_MODULE
@@ -616,9 +618,9 @@
 endif
 
 ifdef j_or_n
-$(j_or_n) $(j_or_n)-$(h_or_t) : $(check_build_target)
+$(j_or_n) $(h_or_t) $(j_or_n)-$(h_or_t) : $(LOCAL_CHECKED_MODULE)
 ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests))
-$(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(check_build_target)
+$(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(LOCAL_CHECKED_MODULE)
 endif
 endif