Multilib ART host.

Build ART for the host as a multilib project with dalvikvm32 and dalvikvm64
running as 32 or 64-bit repsectfully. Note, currently multilib host builds
are not the default, you make the so by setting BUILD_HOST_64bit=1.
Extend tests to execute in both 32 and 64-bit modes. By default both 32 and
64-bit tests are run, add 32 or 64 to the end of a test name to run it in
purely that flavor.
Given the extra spam, modify oat tests to only generate console output when
the test fails.
Change the test harness so that common commands are run when a test should be
skipped, when it passes or when it fails. Use these commands to generate a
summary of passing, skipped and failing tests. Tests will be skipped if they
are known to be broken or if a test has already failed. Setting the variable
TEST_ART_KEEP_GOING=true will force working tests not to be skipped.
In this change all tests running on the optimizing compiler are marked broken
due to breakages running them in a multilib environment.
Break apart Android.common.mk into its constituent parts, along with other
pieces of reorganization.

Stylistic nit, we refer to make rule targets as targets thereby overloading
the term target. While consistent with make's terminology, its confusing with
the Android notion of target. I've switched to just calling targets rules to
avoid confusion in host tests.

Change-Id: I5190fc3de46800a949fbb06b3f4c258ca89ccde9
diff --git a/build/Android.common.mk b/build/Android.common.mk
index f916e1e..4023336 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -17,156 +17,22 @@
 ifndef ANDROID_COMMON_MK
 ANDROID_COMMON_MK = true
 
-ART_SUPPORTED_ARCH := arm arm64 mips x86 x86_64
+ART_TARGET_SUPPORTED_ARCH := arm arm64 mips x86 x86_64
+ART_HOST_SUPPORTED_ARCH := x86 x86_64
 
-ifeq (,$(filter $(TARGET_ARCH),$(ART_SUPPORTED_ARCH)))
+ifeq (,$(filter $(TARGET_ARCH),$(ART_TARGET_SUPPORTED_ARCH)))
 $(warning unsupported TARGET_ARCH=$(TARGET_ARCH))
 endif
-
-# These can be overridden via the environment or by editing to
-# enable/disable certain build configuration.
-#
-# For example, to disable everything but the host debug build you use:
-#
-# (export ART_BUILD_TARGET_NDEBUG=false && export ART_BUILD_TARGET_DEBUG=false && export ART_BUILD_HOST_NDEBUG=false && ...)
-#
-# Beware that tests may use the non-debug build for performance, notable 055-enum-performance
-#
-ART_BUILD_TARGET_NDEBUG ?= true
-ART_BUILD_TARGET_DEBUG ?= true
-ART_BUILD_HOST_NDEBUG ?= true
-ART_BUILD_HOST_DEBUG ?= true
-
-ifeq ($(HOST_PREFER_32_BIT),true)
-ART_HOST_ARCH := $(HOST_2ND_ARCH)
-else
-ART_HOST_ARCH := $(HOST_ARCH)
+ifeq (,$(filter $(HOST_ARCH),$(ART_HOST_SUPPORTED_ARCH)))
+$(warning unsupported HOST_ARCH=$(HOST_ARCH))
 endif
 
-ifeq ($(ART_BUILD_TARGET_NDEBUG),false)
-$(info Disabling ART_BUILD_TARGET_NDEBUG)
-endif
-ifeq ($(ART_BUILD_TARGET_DEBUG),false)
-$(info Disabling ART_BUILD_TARGET_DEBUG)
-endif
-ifeq ($(ART_BUILD_HOST_NDEBUG),false)
-$(info Disabling ART_BUILD_HOST_NDEBUG)
-endif
-ifeq ($(ART_BUILD_HOST_DEBUG),false)
-$(info Disabling ART_BUILD_HOST_DEBUG)
-endif
-
-#
-# Used to enable smart mode
-#
-ART_SMALL_MODE := false
-ifneq ($(wildcard art/SMALL_ART),)
-$(info Enabling ART_SMALL_MODE because of existence of art/SMALL_ART)
-ART_SMALL_MODE := true
-endif
-ifeq ($(WITH_ART_SMALL_MODE), true)
-ART_SMALL_MODE := true
-endif
-
-#
-# Used to enable SEA mode
-#
-ART_SEA_IR_MODE := false
-ifneq ($(wildcard art/SEA_IR_ART),)
-$(info Enabling ART_SEA_IR_MODE because of existence of art/SEA_IR_ART)
-ART_SEA_IR_MODE := true
-endif
-ifeq ($(WITH_ART_SEA_IR_MODE), true)
-ART_SEA_IR_MODE := true
-endif
-
-#
-# Used to enable portable mode
-#
-ART_USE_PORTABLE_COMPILER := false
-ifneq ($(wildcard art/USE_PORTABLE_COMPILER),)
-$(info Enabling ART_USE_PORTABLE_COMPILER because of existence of art/USE_PORTABLE_COMPILER)
-ART_USE_PORTABLE_COMPILER := true
-endif
-ifeq ($(WITH_ART_USE_PORTABLE_COMPILER),true)
-$(info Enabling ART_USE_PORTABLE_COMPILER because WITH_ART_USE_PORTABLE_COMPILER=true)
-ART_USE_PORTABLE_COMPILER := true
-endif
-
-#
-# Used to enable optimizing compiler
-#
-ART_USE_OPTIMIZING_COMPILER := false
-ifneq ($(wildcard art/USE_OPTIMIZING_COMPILER),)
-$(info Enabling ART_USE_OPTIMIZING_COMPILER because of existence of art/USE_OPTIMIZING_COMPILER)
-ART_USE_OPTIMIZING_COMPILER := true
-endif
-ifeq ($(WITH_ART_USE_OPTIMIZING_COMPILER), true)
-ART_USE_OPTIMIZING_COMPILER := true
-endif
-
-ifeq ($(ART_USE_OPTIMIZING_COMPILER),true)
-DEX2OAT_FLAGS := --compiler-backend=Optimizing
-DALVIKVM_FLAGS += -Xcompiler-option --compiler-backend=Optimizing
-endif
-
-#
-# Used to change the default GC. Valid values are CMS, SS, GSS. The default is CMS.
-#
-ART_DEFAULT_GC_TYPE ?= CMS
-ART_DEFAULT_GC_TYPE_CFLAGS := -DART_DEFAULT_GC_TYPE_IS_$(ART_DEFAULT_GC_TYPE)
-
-ifeq ($(ART_USE_PORTABLE_COMPILER),true)
-  LLVM_ROOT_PATH := external/llvm
-  # Don't fail a dalvik minimal host build.
-  -include $(LLVM_ROOT_PATH)/llvm.mk
-endif
-
-# Clang build support.
-
-# Host.
-ART_HOST_CLANG := false
-ifneq ($(WITHOUT_HOST_CLANG),true)
-  # By default, host builds use clang for better warnings.
-  ART_HOST_CLANG := true
-endif
-
-# Clang on the target: only enabled for ARM64. Target builds use GCC by default.
-ART_TARGET_CLANG :=
-ART_TARGET_CLANG_arm :=
-ART_TARGET_CLANG_arm64 :=
-ART_TARGET_CLANG_mips :=
-ART_TARGET_CLANG_x86 :=
-ART_TARGET_CLANG_x86_64 :=
-
-define set-target-local-clang-vars
-    LOCAL_CLANG := $(ART_TARGET_CLANG)
-    $(foreach arch,$(ART_SUPPORTED_ARCH),
-    	ifneq ($$(ART_TARGET_CLANG_$(arch)),)
-        LOCAL_CLANG_$(arch) := $$(ART_TARGET_CLANG_$(arch))
-      endif)
-endef
-
-# directory used for dalvik-cache on device
-ART_DALVIK_CACHE_DIR := /data/dalvik-cache
-
-# directory used for gtests on device
-ART_NATIVETEST_DIR := /data/nativetest/art
-ART_NATIVETEST_OUT := $(TARGET_OUT_DATA_NATIVE_TESTS)/art
-
-# directory used for oat tests on device
-ART_TEST_DIR := /data/art-test
-ART_TEST_OUT := $(TARGET_OUT_DATA)/art-test
-
 # Primary vs. secondary
 2ND_TARGET_ARCH := $(TARGET_2ND_ARCH)
-ART_PHONY_TEST_TARGET_SUFFIX :=
-2ND_ART_PHONY_TEST_TARGET_SUFFIX :=
+TARGET_INSTRUCTION_SET_FEATURES := $(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
+2ND_TARGET_INSTRUCTION_SET_FEATURES := $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
 ifdef TARGET_2ND_ARCH
-  art_test_primary_suffix :=
-  art_test_secondary_suffix :=
   ifneq ($(filter %64,$(TARGET_ARCH)),)
-    art_test_primary_suffix := 64
     ART_PHONY_TEST_TARGET_SUFFIX := 64
     2ND_ART_PHONY_TEST_TARGET_SUFFIX := 32
     ART_TARGET_ARCH_32 := $(TARGET_2ND_ARCH)
@@ -176,268 +42,32 @@
     $(error Do not know what to do with this multi-target configuration!)
   endif
 else
+  ART_PHONY_TEST_TARGET_SUFFIX := 32
+  2ND_ART_PHONY_TEST_TARGET_SUFFIX :=
   ART_TARGET_ARCH_32 := $(TARGET_ARCH)
   ART_TARGET_ARCH_64 :=
 endif
 
-ART_CPP_EXTENSION := .cc
-
-ART_HOST_SHLIB_EXTENSION := $(HOST_SHLIB_SUFFIX)
-ART_HOST_SHLIB_EXTENSION ?= .so
-
-ART_C_INCLUDES := \
-	external/gtest/include \
-	external/valgrind/main/include \
-	external/valgrind/main \
-	external/vixl/src \
-	external/zlib \
-	frameworks/compile/mclinker/include
-
-art_cflags := \
-	-fno-rtti \
-	-std=gnu++11 \
-	-ggdb3 \
-	-Wall \
-	-Werror \
-	-Wextra \
-	-Wno-sign-promo \
-	-Wno-unused-parameter \
-	-Wstrict-aliasing \
-	-fstrict-aliasing
-
-ART_TARGET_CLANG_CFLAGS :=
-ART_TARGET_CLANG_CFLAGS_arm :=
-ART_TARGET_CLANG_CFLAGS_arm64 :=
-ART_TARGET_CLANG_CFLAGS_mips :=
-ART_TARGET_CLANG_CFLAGS_x86 :=
-ART_TARGET_CLANG_CFLAGS_x86_64 :=
-
-# these are necessary for Clang ARM64 ART builds
-ART_TARGET_CLANG_CFLAGS_arm64  += \
-	-Wno-implicit-exception-spec-mismatch \
-	-DNVALGRIND \
-	-Wno-unused-value
-
-ifeq ($(ART_SMALL_MODE),true)
-  art_cflags += -DART_SMALL_MODE=1
-endif
-
-ifeq ($(ART_SEA_IR_MODE),true)
-  art_cflags += -DART_SEA_IR_MODE=1
-endif
-
-art_non_debug_cflags := \
-	-O3
-
-ifeq ($(HOST_OS),linux)
-  art_non_debug_cflags += \
-	-Wframe-larger-than=1728
-endif
-
-# FIXME: upstream LLVM has a vectorizer bug that needs to be fixed
-ART_TARGET_CLANG_CFLAGS_arm64 += \
-	-fno-vectorize
-
-art_debug_cflags := \
-	-O1 \
-	-DDYNAMIC_ANNOTATIONS_ENABLED=1 \
-	-UNDEBUG
-
-ART_HOST_CFLAGS := $(art_cflags) -DANDROID_SMP=1 -DART_BASE_ADDRESS=$(LIBART_IMG_HOST_BASE_ADDRESS)
-ART_HOST_CFLAGS += -DART_DEFAULT_INSTRUCTION_SET_FEATURES=default
-ART_HOST_CFLAGS += $(ART_DEFAULT_GC_TYPE_CFLAGS)
-
-ART_TARGET_CFLAGS := $(art_cflags) -DART_TARGET -DART_BASE_ADDRESS=$(LIBART_IMG_TARGET_BASE_ADDRESS)
-ifeq ($(TARGET_CPU_SMP),true)
-  ART_TARGET_CFLAGS += -DANDROID_SMP=1
+ifeq ($(HOST_PREFER_32_BIT),true)
+  ART_PHONY_TEST_HOST_SUFFIX := 32
+  2ND_ART_PHONY_TEST_HOST_SUFFIX :=
+  ART_HOST_ARCH_32 := x86
+  ART_HOST_ARCH_64 :=
+  ART_HOST_ARCH := x86
+  2ND_ART_HOST_ARCH :=
+  2ND_HOST_ARCH :=
+  ART_HOST_OUT_SHARED_LIBRARIES := $(2ND_HOST_OUT_SHARED_LIBRARIES)
+  2ND_ART_HOST_OUT_SHARED_LIBRARIES :=
 else
-  ifeq ($(TARGET_CPU_SMP),false)
-    ART_TARGET_CFLAGS += -DANDROID_SMP=0
-  else
-    $(warning TARGET_CPU_SMP should be (true|false), found $(TARGET_CPU_SMP))
-    # Make sure we emit barriers for the worst case.
-    ART_TARGET_CFLAGS += -DANDROID_SMP=1
-  endif
+  ART_PHONY_TEST_HOST_SUFFIX := 64
+  2ND_ART_PHONY_TEST_HOST_SUFFIX := 32
+  ART_HOST_ARCH_32 := x86
+  ART_HOST_ARCH_64 := x86_64
+  ART_HOST_ARCH := x86_64
+  2ND_ART_HOST_ARCH := x86
+  2ND_HOST_ARCH := x86
+  ART_HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT_SHARED_LIBRARIES)
+  2ND_ART_HOST_OUT_SHARED_LIBRARIES := $(2ND_HOST_OUT_SHARED_LIBRARIES)
 endif
-ART_TARGET_CFLAGS += $(ART_DEFAULT_GC_TYPE_CFLAGS)
-
-# DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES is set in ../build/core/dex_preopt.mk based on
-# the TARGET_CPU_VARIANT
-ifeq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
-$(error Required DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES is not set)
-endif
-ART_TARGET_CFLAGS += -DART_DEFAULT_INSTRUCTION_SET_FEATURES=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
-
-# Enable thread-safety for GCC 4.6, and clang, but not for GCC 4.7 or later where this feature was
-# removed. Warn when -Wthread-safety is not used.
-ifneq ($(filter 4.6 4.6.%, $(TARGET_GCC_VERSION)),)
-  ART_TARGET_CFLAGS += -Wthread-safety
-else
-  # FIXME: add -Wthread-safety when the problem is fixed
-  ifeq ($(ART_TARGET_CLANG),true)
-    ART_TARGET_CFLAGS +=
-  else
-    # Warn if -Wthread-safety is not suport and not doing a top-level or 'mma' build.
-    ifneq ($(ONE_SHOT_MAKEFILE),)
-      # Enable target GCC 4.6 with: export TARGET_GCC_VERSION_EXP=4.6
-      $(info Using target GCC $(TARGET_GCC_VERSION) disables thread-safety checks.)
-    endif
-  endif
-endif
-# We compile with GCC 4.6 or clang on the host, both of which support -Wthread-safety.
-ART_HOST_CFLAGS += -Wthread-safety
-
-# To use oprofile_android --callgraph, uncomment this and recompile with "mmm art -B -j16"
-# ART_TARGET_CFLAGS += -fno-omit-frame-pointer -marm -mapcs
-
-# Addition CPU specific CFLAGS.
-ifeq ($(TARGET_ARCH),arm)
-  ifneq ($(filter cortex-a15, $(TARGET_CPU_VARIANT)),)
-    # Fake a ARM feature for LPAE support.
-    ART_TARGET_CFLAGS += -D__ARM_FEATURE_LPAE=1
-  endif
-endif
-
-ART_HOST_NON_DEBUG_CFLAGS := $(art_non_debug_cflags)
-ART_TARGET_NON_DEBUG_CFLAGS := $(art_non_debug_cflags)
-
-# TODO: move -fkeep-inline-functions to art_debug_cflags when target gcc > 4.4 (and -lsupc++)
-ART_HOST_DEBUG_CFLAGS := $(art_debug_cflags) -fkeep-inline-functions
-ART_HOST_DEBUG_LDLIBS := -lsupc++
-
-ifneq ($(HOST_OS),linux)
-  # Some Mac OS pthread header files are broken with -fkeep-inline-functions.
-  ART_HOST_DEBUG_CFLAGS := $(filter-out -fkeep-inline-functions,$(ART_HOST_DEBUG_CFLAGS))
-  # Mac OS doesn't have libsupc++.
-  ART_HOST_DEBUG_LDLIBS := $(filter-out -lsupc++,$(ART_HOST_DEBUG_LDLIBS))
-endif
-
-ART_TARGET_DEBUG_CFLAGS := $(art_debug_cflags)
-
-# $(1): ndebug_or_debug
-define set-target-local-cflags-vars
-    LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
-    LOCAL_CFLAGS_x86 += $(ART_TARGET_CFLAGS_x86)
-    art_target_cflags_ndebug_or_debug := $(1)
-    ifeq ($$(art_target_cflags_ndebug_or_debug),debug)
-      LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS)
-    else
-      LOCAL_CFLAGS += $(ART_TARGET_NON_DEBUG_CFLAGS)
-    endif
-
-    # TODO: Also set when ART_TARGET_CLANG_$(arch)!=false and ART_TARGET_CLANG==true
-    $(foreach arch,$(ART_SUPPORTED_ARCH),
-    	ifeq ($$(ART_TARGET_CLANG_$(arch)),true)
-        LOCAL_CFLAGS_$(arch) += $$(ART_TARGET_CLANG_CFLAGS_$(arch))
-      endif)
-endef
-
-ART_BUILD_TARGET := false
-ART_BUILD_HOST := false
-ART_BUILD_NDEBUG := false
-ART_BUILD_DEBUG := false
-ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
-  ART_BUILD_TARGET := true
-  ART_BUILD_NDEBUG := true
-endif
-ifeq ($(ART_BUILD_TARGET_DEBUG),true)
-  ART_BUILD_TARGET := true
-  ART_BUILD_DEBUG := true
-endif
-ifeq ($(ART_BUILD_HOST_NDEBUG),true)
-  ART_BUILD_HOST := true
-  ART_BUILD_NDEBUG := true
-endif
-ifeq ($(ART_BUILD_HOST_DEBUG),true)
-  ART_BUILD_HOST := true
-  ART_BUILD_DEBUG := true
-endif
-
-# Helper function to call a function twice with a target suffix
-# $(1): The generator function for the rules
-#         Has one argument, the suffix
-define call-art-multi-target
-  $(call $(1),$(ART_PHONY_TEST_TARGET_SUFFIX))
-
-  ifdef TARGET_2ND_ARCH
-    $(call $(1),$(2ND_ART_PHONY_TEST_TARGET_SUFFIX))
-  endif
-endef
-
-# Helper function to combine two variables with suffixes together.
-# $(1): The base name.
-define combine-art-multi-target-var
-  ifdef TARGET_2ND_ARCH
-    ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),)
-      ifneq ($(2ND_ART_PHONY_TEST_TARGET_SUFFIX),)
-$(1) := $($(1)$(ART_PHONY_TEST_TARGET_SUFFIX)) $($(1)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX))
-      endif
-    endif
-  endif
-endef
-
-
-# Helper function to define a variable twice with a target suffix. Assume the name generated is
-# derived from $(2) so we can create a combined var.
-# $(1): The generator function for the rules
-#         Has one argument, the suffix
-define call-art-multi-target-var
-  $(call $(1),$(ART_PHONY_TEST_TARGET_SUFFIX))
-
-  ifdef TARGET_2ND_ARCH
-    $(call $(1),$(2ND_ART_PHONY_TEST_TARGET_SUFFIX))
-
-    # Link both together, if it makes sense
-    ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),)
-      ifneq ($(2ND_ART_PHONY_TEST_TARGET_SUFFIX),)
-$(2) := $(2)$(ART_PHONY_TEST_TARGET_SUFFIX) $(2)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)
-      endif
-    endif
-
-  endif
-endef
-
-# Helper function to call a function twice with a target suffix. Assume it generates make rules
-# with the given name, and link them.
-# $(1): The generator function for the rules
-#         Has one argument, the suffix
-# $(2): The base rule name, necessary for the link
-#       We assume we can link the names together easily...
-define call-art-multi-target-rule
-  $(call $(1),$(ART_PHONY_TEST_TARGET_SUFFIX))
-
-  ifdef TARGET_2ND_ARCH
-    $(call $(1),$(2ND_ART_PHONY_TEST_TARGET_SUFFIX))
-
-    # Link both together, if it makes sense
-    ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),)
-      ifneq ($(2ND_ART_PHONY_TEST_TARGET_SUFFIX),)
-.PHONY: $(2)
-$(2): $(2)$(ART_PHONY_TEST_TARGET_SUFFIX) $(2)$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)
-      endif
-    endif
-  endif
-endef
-
-HOST_CORE_OAT := $(HOST_OUT_JAVA_LIBRARIES)/$(ART_HOST_ARCH)/core.oat
-TARGET_CORE_OAT := $(ART_TEST_DIR)/$(DEX2OAT_TARGET_ARCH)/core.oat
-ifdef TARGET_2ND_ARCH
-2ND_TARGET_CORE_OAT := $(2ND_ART_TEST_DIR)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/core.oat
-endif
-
-HOST_CORE_OAT_OUT := $(HOST_OUT_JAVA_LIBRARIES)/$(ART_HOST_ARCH)/core.oat
-TARGET_CORE_OAT_OUT := $(ART_TEST_OUT)/$(DEX2OAT_TARGET_ARCH)/core.oat
-ifdef TARGET_2ND_ARCH
-2ND_TARGET_CORE_OAT_OUT := $(ART_TEST_OUT)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/core.oat
-endif
-
-HOST_CORE_IMG_OUT := $(HOST_OUT_JAVA_LIBRARIES)/$(ART_HOST_ARCH)/core.art
-TARGET_CORE_IMG_OUT := $(ART_TEST_OUT)/$(DEX2OAT_TARGET_ARCH)/core.art
-ifdef TARGET_2ND_ARCH
-2ND_TARGET_CORE_IMG_OUT := $(ART_TEST_OUT)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/core.art
-endif
-
-HOST_CORE_IMG_LOCATION := $(HOST_OUT_JAVA_LIBRARIES)/core.art
-TARGET_CORE_IMG_LOCATION := $(ART_TEST_OUT)/core.art
 
 endif # ANDROID_COMMON_MK
diff --git a/build/Android.common_build.mk b/build/Android.common_build.mk
new file mode 100644
index 0000000..90609ec
--- /dev/null
+++ b/build/Android.common_build.mk
@@ -0,0 +1,326 @@
+#
+# 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.
+#
+
+ifndef ANDROID_COMMON_BUILD_MK
+ANDROID_COMMON_BUILD_MK = true
+
+include art/build/Android.common.mk
+
+# These can be overridden via the environment or by editing to
+# enable/disable certain build configuration.
+#
+# For example, to disable everything but the host debug build you use:
+#
+# (export ART_BUILD_TARGET_NDEBUG=false && export ART_BUILD_TARGET_DEBUG=false && export ART_BUILD_HOST_NDEBUG=false && ...)
+#
+# Beware that tests may use the non-debug build for performance, notable 055-enum-performance
+#
+ART_BUILD_TARGET_NDEBUG ?= true
+ART_BUILD_TARGET_DEBUG ?= true
+ART_BUILD_HOST_NDEBUG ?= true
+ART_BUILD_HOST_DEBUG ?= true
+
+ifeq ($(ART_BUILD_TARGET_NDEBUG),false)
+$(info Disabling ART_BUILD_TARGET_NDEBUG)
+endif
+ifeq ($(ART_BUILD_TARGET_DEBUG),false)
+$(info Disabling ART_BUILD_TARGET_DEBUG)
+endif
+ifeq ($(ART_BUILD_HOST_NDEBUG),false)
+$(info Disabling ART_BUILD_HOST_NDEBUG)
+endif
+ifeq ($(ART_BUILD_HOST_DEBUG),false)
+$(info Disabling ART_BUILD_HOST_DEBUG)
+endif
+
+#
+# Used to enable smart mode
+#
+ART_SMALL_MODE := false
+ifneq ($(wildcard art/SMALL_ART),)
+$(info Enabling ART_SMALL_MODE because of existence of art/SMALL_ART)
+ART_SMALL_MODE := true
+endif
+ifeq ($(WITH_ART_SMALL_MODE), true)
+ART_SMALL_MODE := true
+endif
+
+#
+# Used to enable SEA mode
+#
+ART_SEA_IR_MODE := false
+ifneq ($(wildcard art/SEA_IR_ART),)
+$(info Enabling ART_SEA_IR_MODE because of existence of art/SEA_IR_ART)
+ART_SEA_IR_MODE := true
+endif
+ifeq ($(WITH_ART_SEA_IR_MODE), true)
+ART_SEA_IR_MODE := true
+endif
+
+#
+# Used to enable portable mode
+#
+ART_USE_PORTABLE_COMPILER := false
+ifneq ($(wildcard art/USE_PORTABLE_COMPILER),)
+$(info Enabling ART_USE_PORTABLE_COMPILER because of existence of art/USE_PORTABLE_COMPILER)
+ART_USE_PORTABLE_COMPILER := true
+endif
+ifeq ($(WITH_ART_USE_PORTABLE_COMPILER),true)
+$(info Enabling ART_USE_PORTABLE_COMPILER because WITH_ART_USE_PORTABLE_COMPILER=true)
+ART_USE_PORTABLE_COMPILER := true
+endif
+
+#
+# Used to enable optimizing compiler
+#
+ART_USE_OPTIMIZING_COMPILER := false
+ifneq ($(wildcard art/USE_OPTIMIZING_COMPILER),)
+$(info Enabling ART_USE_OPTIMIZING_COMPILER because of existence of art/USE_OPTIMIZING_COMPILER)
+ART_USE_OPTIMIZING_COMPILER := true
+endif
+ifeq ($(WITH_ART_USE_OPTIMIZING_COMPILER), true)
+ART_USE_OPTIMIZING_COMPILER := true
+endif
+
+ifeq ($(ART_USE_OPTIMIZING_COMPILER),true)
+DEX2OAT_FLAGS := --compiler-backend=Optimizing
+DALVIKVM_FLAGS += -Xcompiler-option --compiler-backend=Optimizing
+endif
+
+#
+# Used to change the default GC. Valid values are CMS, SS, GSS. The default is CMS.
+#
+ART_DEFAULT_GC_TYPE ?= CMS
+ART_DEFAULT_GC_TYPE_CFLAGS := -DART_DEFAULT_GC_TYPE_IS_$(ART_DEFAULT_GC_TYPE)
+
+ifeq ($(ART_USE_PORTABLE_COMPILER),true)
+  LLVM_ROOT_PATH := external/llvm
+  # Don't fail a dalvik minimal host build.
+  -include $(LLVM_ROOT_PATH)/llvm.mk
+endif
+
+# Clang build support.
+
+# Host.
+ART_HOST_CLANG := false
+ifneq ($(WITHOUT_HOST_CLANG),true)
+  # By default, host builds use clang for better warnings.
+  ART_HOST_CLANG := true
+endif
+
+# Clang on the target: only enabled for ARM64. Target builds use GCC by default.
+ART_TARGET_CLANG :=
+ART_TARGET_CLANG_arm :=
+ART_TARGET_CLANG_arm64 := true
+ART_TARGET_CLANG_mips :=
+ART_TARGET_CLANG_x86 :=
+ART_TARGET_CLANG_x86_64 :=
+
+define set-target-local-clang-vars
+    LOCAL_CLANG := $(ART_TARGET_CLANG)
+    $(foreach arch,$(ART_TARGET_SUPPORTED_ARCH),
+      ifneq ($$(ART_TARGET_CLANG_$(arch)),)
+        LOCAL_CLANG_$(arch) := $$(ART_TARGET_CLANG_$(arch))
+      endif)
+endef
+
+ART_CPP_EXTENSION := .cc
+
+ART_HOST_SHLIB_EXTENSION := $(HOST_SHLIB_SUFFIX)
+ART_HOST_SHLIB_EXTENSION ?= .so
+
+ART_C_INCLUDES := \
+  external/gtest/include \
+  external/valgrind/main/include \
+  external/valgrind/main \
+  external/vixl/src \
+  external/zlib \
+  frameworks/compile/mclinker/include
+
+art_cflags := \
+  -fno-rtti \
+  -std=gnu++11 \
+  -ggdb3 \
+  -Wall \
+  -Werror \
+  -Wextra \
+  -Wno-sign-promo \
+  -Wno-unused-parameter \
+  -Wstrict-aliasing \
+  -fstrict-aliasing
+
+ART_TARGET_CLANG_CFLAGS :=
+ART_TARGET_CLANG_CFLAGS_arm :=
+ART_TARGET_CLANG_CFLAGS_arm64 :=
+ART_TARGET_CLANG_CFLAGS_mips :=
+ART_TARGET_CLANG_CFLAGS_x86 :=
+ART_TARGET_CLANG_CFLAGS_x86_64 :=
+
+# these are necessary for Clang ARM64 ART builds
+ART_TARGET_CLANG_CFLAGS_arm64  += \
+  -Wno-implicit-exception-spec-mismatch \
+  -DNVALGRIND \
+  -Wno-unused-value
+
+ifeq ($(ART_SMALL_MODE),true)
+  art_cflags += -DART_SMALL_MODE=1
+endif
+
+ifeq ($(ART_SEA_IR_MODE),true)
+  art_cflags += -DART_SEA_IR_MODE=1
+endif
+
+art_non_debug_cflags := \
+  -O3
+
+ifeq ($(HOST_OS),linux)
+  art_non_debug_cflags += -Wframe-larger-than=1728
+endif
+
+# FIXME: upstream LLVM has a vectorizer bug that needs to be fixed
+ART_TARGET_CLANG_CFLAGS_arm64 += \
+  -fno-vectorize
+
+art_debug_cflags := \
+  -O1 \
+  -DDYNAMIC_ANNOTATIONS_ENABLED=1 \
+  -UNDEBUG
+
+ifndef LIBART_IMG_HOST_BASE_ADDRESS
+  $(error LIBART_IMG_HOST_BASE_ADDRESS unset)
+endif
+ART_HOST_CFLAGS := $(art_cflags) -DANDROID_SMP=1 -DART_BASE_ADDRESS=$(LIBART_IMG_HOST_BASE_ADDRESS)
+ART_HOST_CFLAGS += -DART_DEFAULT_INSTRUCTION_SET_FEATURES=default
+ART_HOST_CFLAGS += $(ART_DEFAULT_GC_TYPE_CFLAGS)
+
+ifndef LIBART_IMG_TARGET_BASE_ADDRESS
+  $(error LIBART_IMG_TARGET_BASE_ADDRESS unset)
+endif
+ART_TARGET_CFLAGS := $(art_cflags) -DART_TARGET -DART_BASE_ADDRESS=$(LIBART_IMG_TARGET_BASE_ADDRESS)
+ifeq ($(TARGET_CPU_SMP),true)
+  ART_TARGET_CFLAGS += -DANDROID_SMP=1
+else
+  ifeq ($(TARGET_CPU_SMP),false)
+    ART_TARGET_CFLAGS += -DANDROID_SMP=0
+  else
+    $(warning TARGET_CPU_SMP should be (true|false), found $(TARGET_CPU_SMP))
+    # Make sure we emit barriers for the worst case.
+    ART_TARGET_CFLAGS += -DANDROID_SMP=1
+  endif
+endif
+ART_TARGET_CFLAGS += $(ART_DEFAULT_GC_TYPE_CFLAGS)
+
+# DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES is set in ../build/core/dex_preopt.mk based on
+# the TARGET_CPU_VARIANT
+ifeq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
+$(error Required DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES is not set)
+endif
+ART_TARGET_CFLAGS += -DART_DEFAULT_INSTRUCTION_SET_FEATURES=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
+
+# Enable thread-safety for GCC 4.6, and clang, but not for GCC 4.7 or later where this feature was
+# removed. Warn when -Wthread-safety is not used.
+ifneq ($(filter 4.6 4.6.%, $(TARGET_GCC_VERSION)),)
+  ART_TARGET_CFLAGS += -Wthread-safety
+else
+  # FIXME: add -Wthread-safety when the problem is fixed
+  ifeq ($(ART_TARGET_CLANG),true)
+    ART_TARGET_CFLAGS +=
+  else
+    # Warn if -Wthread-safety is not supported and not doing a top-level or 'mma' build.
+    ifneq ($(ONE_SHOT_MAKEFILE),)
+      # Enable target GCC 4.6 with: export TARGET_GCC_VERSION_EXP=4.6
+      $(info Using target GCC $(TARGET_GCC_VERSION) disables thread-safety checks.)
+    endif
+  endif
+endif
+# We compile with GCC 4.6 or clang on the host, both of which support -Wthread-safety.
+ART_HOST_CFLAGS += -Wthread-safety
+
+# To use oprofile_android --callgraph, uncomment this and recompile with "mmm art -B -j16"
+# ART_TARGET_CFLAGS += -fno-omit-frame-pointer -marm -mapcs
+
+# Addition CPU specific CFLAGS.
+ifeq ($(TARGET_ARCH),arm)
+  ifneq ($(filter cortex-a15, $(TARGET_CPU_VARIANT)),)
+    # Fake a ARM feature for LPAE support.
+    ART_TARGET_CFLAGS += -D__ARM_FEATURE_LPAE=1
+  endif
+endif
+
+ART_HOST_NON_DEBUG_CFLAGS := $(art_non_debug_cflags)
+ART_TARGET_NON_DEBUG_CFLAGS := $(art_non_debug_cflags)
+
+# TODO: move -fkeep-inline-functions to art_debug_cflags when target gcc > 4.4 (and -lsupc++)
+ART_HOST_DEBUG_CFLAGS := $(art_debug_cflags) -fkeep-inline-functions
+ART_HOST_DEBUG_LDLIBS := -lsupc++
+
+ifneq ($(HOST_OS),linux)
+  # Some Mac OS pthread header files are broken with -fkeep-inline-functions.
+  ART_HOST_DEBUG_CFLAGS := $(filter-out -fkeep-inline-functions,$(ART_HOST_DEBUG_CFLAGS))
+  # Mac OS doesn't have libsupc++.
+  ART_HOST_DEBUG_LDLIBS := $(filter-out -lsupc++,$(ART_HOST_DEBUG_LDLIBS))
+endif
+
+ART_TARGET_DEBUG_CFLAGS := $(art_debug_cflags)
+
+# $(1): ndebug_or_debug
+define set-target-local-cflags-vars
+  LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
+  LOCAL_CFLAGS_x86 += $(ART_TARGET_CFLAGS_x86)
+  art_target_cflags_ndebug_or_debug := $(1)
+  ifeq ($$(art_target_cflags_ndebug_or_debug),debug)
+    LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS)
+  else
+    LOCAL_CFLAGS += $(ART_TARGET_NON_DEBUG_CFLAGS)
+  endif
+
+  # TODO: Also set when ART_TARGET_CLANG_$(arch)!=false and ART_TARGET_CLANG==true
+  $(foreach arch,$(ART_SUPPORTED_ARCH),
+    ifeq ($$(ART_TARGET_CLANG_$(arch)),true)
+      LOCAL_CFLAGS_$(arch) += $$(ART_TARGET_CLANG_CFLAGS_$(arch))
+  endif)
+
+  # Clear locally used variables.
+  art_target_cflags_ndebug_or_debug :=
+endef
+
+ART_BUILD_TARGET := false
+ART_BUILD_HOST := false
+ART_BUILD_NDEBUG := false
+ART_BUILD_DEBUG := false
+ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
+  ART_BUILD_TARGET := true
+  ART_BUILD_NDEBUG := true
+endif
+ifeq ($(ART_BUILD_TARGET_DEBUG),true)
+  ART_BUILD_TARGET := true
+  ART_BUILD_DEBUG := true
+endif
+ifeq ($(ART_BUILD_HOST_NDEBUG),true)
+  ART_BUILD_HOST := true
+  ART_BUILD_NDEBUG := true
+endif
+ifeq ($(ART_BUILD_HOST_DEBUG),true)
+  ART_BUILD_HOST := true
+  ART_BUILD_DEBUG := true
+endif
+
+# Clear locally defined variables that aren't necessary in the rest of the build system.
+ART_DEFAULT_GC_TYPE :=
+ART_DEFAULT_GC_TYPE_CFLAGS :=
+art_cflags :=
+
+endif # ANDROID_COMMON_BUILD_MK
diff --git a/build/Android.common_path.mk b/build/Android.common_path.mk
new file mode 100644
index 0000000..d672393
--- /dev/null
+++ b/build/Android.common_path.mk
@@ -0,0 +1,76 @@
+#
+# 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.
+#
+
+ifndef ANDROID_COMMON_PATH_MK
+ANDROID_COMMON_PATH_MK := true
+
+include art/build/Android.common.mk
+
+# Directory used for dalvik-cache on device.
+ART_TARGET_DALVIK_CACHE_DIR := /data/dalvik-cache
+
+# Directory used for gtests on device.
+ART_TARGET_NATIVETEST_DIR := /data/nativetest/art
+ART_TARGET_NATIVETEST_OUT := $(TARGET_OUT_DATA_NATIVE_TESTS)/art
+
+# Directory used for oat tests on device.
+ART_TARGET_TEST_DIR := /data/art-test
+ART_TARGET_TEST_OUT := $(TARGET_OUT_DATA)/art-test
+
+# Directory used for temporary test files on the host.
+ART_HOST_TEST_DIR := /tmp/test-art-$(shell echo $$PPID)
+
+# Core.oat location on the device.
+TARGET_CORE_OAT := $(ART_TARGET_TEST_DIR)/$(DEX2OAT_TARGET_ARCH)/core.oat
+ifdef TARGET_2ND_ARCH
+2ND_TARGET_CORE_OAT := $(ART_TARGET_TEST_DIR)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/core.oat
+endif
+
+# Core.oat locations under the out directory.
+HOST_CORE_OAT_OUT := $(HOST_OUT_JAVA_LIBRARIES)/$(ART_HOST_ARCH)/core.oat
+ifneq ($(HOST_PREFER_32_BIT),true)
+2ND_HOST_CORE_OAT_OUT := $(HOST_OUT_JAVA_LIBRARIES)/$(2ND_ART_HOST_ARCH)/core.oat
+endif
+TARGET_CORE_OAT_OUT := $(ART_TARGET_TEST_OUT)/$(DEX2OAT_TARGET_ARCH)/core.oat
+ifdef TARGET_2ND_ARCH
+2ND_TARGET_CORE_OAT_OUT := $(ART_TARGET_TEST_OUT)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/core.oat
+endif
+
+# Core.art locations under the out directory.
+HOST_CORE_IMG_OUT := $(HOST_OUT_JAVA_LIBRARIES)/$(ART_HOST_ARCH)/core.art
+ifneq ($(HOST_PREFER_32_BIT),true)
+2ND_HOST_CORE_IMG_OUT := $(HOST_OUT_JAVA_LIBRARIES)/$(2ND_ART_HOST_ARCH)/core.art
+endif
+TARGET_CORE_IMG_OUT := $(ART_TARGET_TEST_OUT)/$(DEX2OAT_TARGET_ARCH)/core.art
+ifdef TARGET_2ND_ARCH
+2ND_TARGET_CORE_IMG_OUT := $(ART_TARGET_TEST_OUT)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/core.art
+endif
+
+# Oat location of core.art.
+HOST_CORE_IMG_LOCATION := $(HOST_OUT_JAVA_LIBRARIES)/core.art
+TARGET_CORE_IMG_LOCATION := $(ART_TARGET_TEST_OUT)/core.art
+
+# Jar files for core.art.
+TARGET_CORE_JARS := core-libart conscrypt okhttp core-junit bouncycastle
+HOST_CORE_JARS := $(addsuffix -hostdex,$(TARGET_CORE_JARS))
+
+HOST_CORE_DEX_LOCATIONS   := $(foreach jar,$(HOST_CORE_JARS),  $(HOST_OUT_JAVA_LIBRARIES)/$(jar).jar)
+TARGET_CORE_DEX_LOCATIONS := $(foreach jar,$(TARGET_CORE_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar)
+
+HOST_CORE_DEX_FILES   := $(foreach jar,$(HOST_CORE_JARS),  $(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),t,COMMON)/javalib.jar)
+TARGET_CORE_DEX_FILES := $(foreach jar,$(TARGET_CORE_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar), ,COMMON)/javalib.jar)
+
+endif # ANDROID_COMMON_PATH_MK
diff --git a/build/Android.common_test.mk b/build/Android.common_test.mk
new file mode 100644
index 0000000..1815f50
--- /dev/null
+++ b/build/Android.common_test.mk
@@ -0,0 +1,117 @@
+#
+# 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.
+#
+
+ifndef ANDROID_COMMON_TEST_MK
+ANDROID_COMMON_TEST_MK = true
+
+include art/build/Android.common_path.mk
+
+# List of known broken tests that we won't attempt to execute. The test name must be the full
+# rule name such as test-art-host-oat-optimizing-HelloWorld64.
+ART_TEST_KNOWN_BROKEN :=
+
+# List of known failing tests that when executed won't cause test execution to finish. The test name
+# must be the full rule name such as test-art-host-oat-optimizing-HelloWorld64.
+ART_TEST_KNOWN_FAILING := $(ART_TEST_KNOWN_BROKEN)
+
+# Keep going after encountering a test failure?
+ART_TEST_KEEP_GOING ?= false
+
+# Define the command run on test failure. $(1) is the name of the test. Executed by the shell.
+define ART_TEST_FAILED
+  ( [ -f $(ART_HOST_TEST_DIR)/skipped/$(1) ] || \
+    (mkdir -p $(ART_HOST_TEST_DIR)/failed/ && touch $(ART_HOST_TEST_DIR)/failed/$(1) && \
+      echo $(ART_TEST_KNOWN_FAILING) | grep -q $(1) \
+        && (echo -e "$(1) \e[91mKNOWN FAILURE\e[0m") \
+        || (echo -e "$(1) \e[91mFAILED\e[0m")))
+endef
+
+# Define the command run on test success. $(1) is the name of the test. Executed by the shell.
+# The command checks prints "PASSED" then checks to see if this was a top-level make target (e.g.
+# "mm test-art-host-oat-HelloWorld32"), if it was then it does nothing, otherwise it creates a file
+# to be printed in the passing test summary.
+define ART_TEST_PASSED
+  ( echo -e "$(1) \e[92mPASSED\e[0m" && \
+    (echo $(MAKECMDGOALS) | grep -q $(1) || \
+      (mkdir -p $(ART_HOST_TEST_DIR)/passed/ && touch $(ART_HOST_TEST_DIR)/passed/$(1))))
+endef
+
+# Define the command run on test success of multiple prerequisites. $(1) is the name of the test.
+# When the test is a top-level make target then a summary of the ran tests is produced. Executed by
+# the shell.
+define ART_TEST_PREREQ_FINISHED
+  (echo -e "$(1) \e[32mCOMPLETE\e[0m" && \
+    (echo $(MAKECMDGOALS) | grep -q -v $(1) || \
+      (([ -d $(ART_HOST_TEST_DIR)/passed/ ] \
+        && (echo -e "\e[92mPASSING TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/passed/) \
+        || (echo -e "\e[91mNO TESTS PASSED\e[0m")) && \
+      ([ -d $(ART_HOST_TEST_DIR)/skipped/ ] \
+        && (echo -e "\e[93mSKIPPED TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/skipped/) \
+        || (echo -e "\e[92mNO TESTS SKIPPED\e[0m")) && \
+      ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \
+        && (echo -e "\e[91mFAILING TESTS\e[0m" && ls -1 $(ART_HOST_TEST_DIR)/failed/) \
+        || (echo -e "\e[92mNO TESTS FAILED\e[0m")) \
+      && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] && rm -r $(ART_HOST_TEST_DIR) \
+          || (rm -r $(ART_HOST_TEST_DIR) && false)))))
+endef
+
+# Define the command executed by the shell ahead of running an art test. $(1) is the name of the
+# test.
+define ART_TEST_SKIP
+  ((echo $(ART_TEST_KNOWN_BROKEN) | grep -q -v $(1) \
+     && ([ ! -d $(ART_HOST_TEST_DIR)/failed/ ] || [ $(ART_TEST_KEEP_GOING) = true ])\
+     && echo -e "$(1) \e[95mRUNNING\e[0m") \
+   || ((mkdir -p $(ART_HOST_TEST_DIR)/skipped/ && touch $(ART_HOST_TEST_DIR)/skipped/$(1) \
+     && ([ -d $(ART_HOST_TEST_DIR)/failed/ ] \
+       && echo -e "$(1) \e[93mSKIPPING DUE TO EARLIER FAILURE\e[0m") \
+     || echo -e "$(1) \e[93mSKIPPING BROKEN TEST\e[0m") && false))
+endef
+
+# Create a build rule to create the dex file for a test.
+# $(1): module prefix, e.g. art-test-dex
+# $(2): input test directory in art/test, e.g. HelloWorld
+# $(3): target output module path (default module path is used on host)
+# $(4): additional dependencies
+# $(5): a make variable used to collate dependencies
+define build-art-test-dex
+  ifeq ($(ART_BUILD_TARGET),true)
+    include $(CLEAR_VARS)
+    LOCAL_MODULE := $(1)-$(2)
+    LOCAL_SRC_FILES := $(call all-java-files-under, $(2))
+    LOCAL_NO_STANDARD_LIBRARIES := true
+    LOCAL_DEX_PREOPT := false
+    LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_test.mk $(4)
+    LOCAL_MODULE_TAGS := tests
+    LOCAL_JAVA_LIBRARIES := $(TARGET_CORE_JARS)
+    LOCAL_MODULE_PATH := $(3)
+    LOCAL_DEX_PREOPT_IMAGE_LOCATION := $(TARGET_CORE_IMG_OUT)
+    include $(BUILD_JAVA_LIBRARY)
+  endif
+  ifeq ($(ART_BUILD_HOST),true)
+    include $(CLEAR_VARS)
+    LOCAL_MODULE := $(1)-$(2)
+    LOCAL_SRC_FILES := $(call all-java-files-under, $(2))
+    LOCAL_NO_STANDARD_LIBRARIES := true
+    LOCAL_DEX_PREOPT := false
+    LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_test.mk $(4)
+    LOCAL_JAVA_LIBRARIES := $(HOST_CORE_JARS)
+    LOCAL_DEX_PREOPT_IMAGE := $(HOST_CORE_IMG_LOCATION)
+    include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
+  endif
+  $(5) := $$(LOCAL_INSTALLED_MODULE)
+endef
+
+endif # ANDROID_COMMON_TEST_MK
diff --git a/build/Android.cpplint.mk b/build/Android.cpplint.mk
index 1ecad21..7abf863 100644
--- a/build/Android.cpplint.mk
+++ b/build/Android.cpplint.mk
@@ -14,6 +14,8 @@
 # limitations under the License.
 #
 
+include art/build/Android.common_build.mk
+
 ART_CPPLINT := art/tools/cpplint.py
 ART_CPPLINT_FILTER := --filter=-whitespace/line_length,-build/include,-readability/function,-readability/streams,-readability/todo,-runtime/references,-runtime/sizeof,-runtime/threadsafe_fn,-runtime/printf
 ART_CPPLINT_SRC := $(shell find art -name "*.h" -o -name "*$(ART_CPP_EXTENSION)" | grep -v art/compiler/llvm/generated/)
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 49e7384..d887acd 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -14,7 +14,7 @@
 # limitations under the License.
 #
 
-include art/build/Android.common.mk
+include art/build/Android.common_build.mk
 
 ART_HOST_EXECUTABLES ?=
 ART_TARGET_EXECUTABLES ?=
@@ -85,13 +85,13 @@
     LOCAL_SHARED_LIBRARIES += libartd
   endif
 
-  LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk
+  LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common_build.mk
   LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.executable.mk
 
   ifeq ($$(art_target_or_host),target)
     LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
-    LOCAL_MULTILIB := $$(art_multilib)
   endif
+  LOCAL_MULTILIB := $$(art_multilib)
 
   include external/libcxx/libcxx.mk
   ifeq ($$(art_target_or_host),target)
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 4c2cda4..9723b89a 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -14,147 +14,251 @@
 # limitations under the License.
 #
 
+# The path for which all the dex files are relative, not actually the current directory.
+LOCAL_PATH := art/test
+
+include art/build/Android.common_test.mk
+include art/build/Android.common_path.mk
+
+# Subdirectories in art/test which contain dex files used as inputs for gtests.
+GTEST_DEX_DIRECTORIES := \
+  AbstractMethod \
+  AllFields \
+  ExceptionHandle \
+  GetMethodSignature \
+  Interfaces \
+  Main \
+  MyClass \
+  MyClassNatives \
+  Nested \
+  NonStaticLeafMethods \
+  ProtoCompare \
+  ProtoCompare2 \
+  StaticLeafMethods \
+  Statics \
+  StaticsFromCode \
+  Transaction \
+  XandY
+
+# Create build rules for each dex file recording the dependency.
+$(foreach dir,$(GTEST_DEX_DIRECTORIES), $(eval $(call build-art-test-dex,art-gtest,$(dir), \
+  $(ART_TARGET_NATIVETEST_OUT),art/build/Android.gtest.mk,ART_GTEST_$(dir)_DEX)))
+
+# Dex file dependencies for each gtest.
+ART_GTEST_class_linker_test_DEPS := $(ART_GTEST_Interfaces_DEX) $(ART_GTEST_MyClass_DEX) \
+  $(ART_GTEST_Nested_DEX) $(ART_GTEST_Statics_DEX) $(ART_GTEST_StaticsFromCode_DEX)
+ART_GTEST_compiler_test_DEPS := $(ART_GTEST_AbstractMethod_DEX)
+ART_GTEST_dex_file_test_DEPS := $(ART_GTEST_GetMethodSignature_DEX)
+ART_GTEST_exception_test_DEPS := $(ART_GTEST_ExceptionHandle_DEX)
+ART_GTEST_jni_compiler_test_DEPS := $(ART_GTEST_MyClassNatives_DEX)
+ART_GTEST_jni_internal_test_DEPS := $(ART_GTEST_AllFields_DEX)
+ART_GTEST_object_test_DEPS := $(ART_GTEST_ProtoCompare_DEX) $(ART_GTEST_ProtoCompare2_DEX) \
+   $(ART_GTEST_StaticsFromCode_DEX) $(ART_GTEST_XandY_DEX)
+ART_GTEST_proxy_test_DEPS := $(ART_GTEST_Interfaces_DEX)
+ART_GTEST_reflection_test_DEPS := $(ART_GTEST_Main_DEX) $(ART_GTEST_NonStaticLeafMethods_DEX) \
+  $(ART_GTEST_StaticLeafMethods_DEX)
+ART_GTEST_stub_test_DEPS := $(ART_GTEST_AllFields_DEX)
+ART_GTEST_transaction_test_DEPS := $(ART_GTEST_Transaction_DEX)
+
+# The elf writer test has dependencies on core.oat.
+ART_GTEST_elf_writer_test_DEPS := $(HOST_CORE_OAT_OUT) $(2ND_HOST_CORE_OAT_OUT) \
+  $(TARGET_CORE_OAT_OUT) $(2ND_TARGET_CORE_OAT_OUT)
+
+# The path for which all the source files are relative, not actually the current directory.
 LOCAL_PATH := art
 
 RUNTIME_GTEST_COMMON_SRC_FILES := \
-	runtime/arch/arch_test.cc \
-	runtime/arch/stub_test.cc \
-	runtime/barrier_test.cc \
-	runtime/base/bit_field_test.cc \
-	runtime/base/bit_vector_test.cc \
-	runtime/base/hex_dump_test.cc \
-	runtime/base/histogram_test.cc \
-	runtime/base/mutex_test.cc \
-	runtime/base/scoped_flock_test.cc \
-	runtime/base/timing_logger_test.cc \
-	runtime/base/unix_file/fd_file_test.cc \
-	runtime/base/unix_file/mapped_file_test.cc \
-	runtime/base/unix_file/null_file_test.cc \
-	runtime/base/unix_file/random_access_file_utils_test.cc \
-	runtime/base/unix_file/string_file_test.cc \
-	runtime/class_linker_test.cc \
-	runtime/dex_file_test.cc \
-	runtime/dex_file_verifier_test.cc \
-	runtime/dex_instruction_visitor_test.cc \
-	runtime/dex_method_iterator_test.cc \
-	runtime/entrypoints/math_entrypoints_test.cc \
-	runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc \
-	runtime/entrypoints_order_test.cc \
-	runtime/exception_test.cc \
-	runtime/gc/accounting/space_bitmap_test.cc \
-	runtime/gc/heap_test.cc \
-	runtime/gc/space/dlmalloc_space_base_test.cc \
-	runtime/gc/space/dlmalloc_space_static_test.cc \
-	runtime/gc/space/dlmalloc_space_random_test.cc \
-	runtime/gc/space/rosalloc_space_base_test.cc \
-	runtime/gc/space/rosalloc_space_static_test.cc \
-	runtime/gc/space/rosalloc_space_random_test.cc \
-	runtime/gc/space/large_object_space_test.cc \
-	runtime/gtest_test.cc \
-	runtime/handle_scope_test.cc \
-	runtime/indenter_test.cc \
-	runtime/indirect_reference_table_test.cc \
-	runtime/instruction_set_test.cc \
-	runtime/intern_table_test.cc \
-	runtime/leb128_test.cc \
-	runtime/mem_map_test.cc \
-	runtime/mirror/dex_cache_test.cc \
-	runtime/mirror/object_test.cc \
-	runtime/parsed_options_test.cc \
-	runtime/reference_table_test.cc \
-	runtime/thread_pool_test.cc \
-	runtime/transaction_test.cc \
-	runtime/utils_test.cc \
-	runtime/verifier/method_verifier_test.cc \
-	runtime/verifier/reg_type_test.cc \
-	runtime/zip_archive_test.cc
+  runtime/arch/arch_test.cc \
+  runtime/arch/stub_test.cc \
+  runtime/barrier_test.cc \
+  runtime/base/bit_field_test.cc \
+  runtime/base/bit_vector_test.cc \
+  runtime/base/hex_dump_test.cc \
+  runtime/base/histogram_test.cc \
+  runtime/base/mutex_test.cc \
+  runtime/base/scoped_flock_test.cc \
+  runtime/base/timing_logger_test.cc \
+  runtime/base/unix_file/fd_file_test.cc \
+  runtime/base/unix_file/mapped_file_test.cc \
+  runtime/base/unix_file/null_file_test.cc \
+  runtime/base/unix_file/random_access_file_utils_test.cc \
+  runtime/base/unix_file/string_file_test.cc \
+  runtime/class_linker_test.cc \
+  runtime/dex_file_test.cc \
+  runtime/dex_file_verifier_test.cc \
+  runtime/dex_instruction_visitor_test.cc \
+  runtime/dex_method_iterator_test.cc \
+  runtime/entrypoints/math_entrypoints_test.cc \
+  runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc \
+  runtime/entrypoints_order_test.cc \
+  runtime/exception_test.cc \
+  runtime/gc/accounting/space_bitmap_test.cc \
+  runtime/gc/heap_test.cc \
+  runtime/gc/space/dlmalloc_space_base_test.cc \
+  runtime/gc/space/dlmalloc_space_static_test.cc \
+  runtime/gc/space/dlmalloc_space_random_test.cc \
+  runtime/gc/space/rosalloc_space_base_test.cc \
+  runtime/gc/space/rosalloc_space_static_test.cc \
+  runtime/gc/space/rosalloc_space_random_test.cc \
+  runtime/gc/space/large_object_space_test.cc \
+  runtime/gtest_test.cc \
+  runtime/handle_scope_test.cc \
+  runtime/indenter_test.cc \
+  runtime/indirect_reference_table_test.cc \
+  runtime/instruction_set_test.cc \
+  runtime/intern_table_test.cc \
+  runtime/leb128_test.cc \
+  runtime/mem_map_test.cc \
+  runtime/mirror/dex_cache_test.cc \
+  runtime/mirror/object_test.cc \
+  runtime/parsed_options_test.cc \
+  runtime/reference_table_test.cc \
+  runtime/thread_pool_test.cc \
+  runtime/transaction_test.cc \
+  runtime/utils_test.cc \
+  runtime/verifier/method_verifier_test.cc \
+  runtime/verifier/reg_type_test.cc \
+  runtime/zip_archive_test.cc
 
 COMPILER_GTEST_COMMON_SRC_FILES := \
-	runtime/jni_internal_test.cc \
-	runtime/proxy_test.cc \
-	runtime/reflection_test.cc \
-	compiler/dex/local_value_numbering_test.cc \
-	compiler/dex/mir_optimization_test.cc \
-	compiler/driver/compiler_driver_test.cc \
-	compiler/elf_writer_test.cc \
-	compiler/image_test.cc \
-	compiler/jni/jni_compiler_test.cc \
-	compiler/oat_test.cc \
-	compiler/optimizing/codegen_test.cc \
-	compiler/optimizing/dominator_test.cc \
-	compiler/optimizing/find_loops_test.cc \
-	compiler/optimizing/graph_test.cc \
-	compiler/optimizing/linearize_test.cc \
-	compiler/optimizing/liveness_test.cc \
-	compiler/optimizing/live_interval_test.cc \
-	compiler/optimizing/live_ranges_test.cc \
-	compiler/optimizing/parallel_move_test.cc \
-	compiler/optimizing/pretty_printer_test.cc \
-	compiler/optimizing/register_allocator_test.cc \
-	compiler/optimizing/ssa_test.cc \
-	compiler/output_stream_test.cc \
-	compiler/utils/arena_allocator_test.cc \
-	compiler/utils/dedupe_set_test.cc \
-	compiler/utils/arm/managed_register_arm_test.cc \
-	compiler/utils/arm64/managed_register_arm64_test.cc \
-	compiler/utils/x86/managed_register_x86_test.cc \
+  runtime/jni_internal_test.cc \
+  runtime/proxy_test.cc \
+  runtime/reflection_test.cc \
+  compiler/dex/local_value_numbering_test.cc \
+  compiler/dex/mir_optimization_test.cc \
+  compiler/driver/compiler_driver_test.cc \
+  compiler/elf_writer_test.cc \
+  compiler/image_test.cc \
+  compiler/jni/jni_compiler_test.cc \
+  compiler/oat_test.cc \
+  compiler/optimizing/codegen_test.cc \
+  compiler/optimizing/dominator_test.cc \
+  compiler/optimizing/find_loops_test.cc \
+  compiler/optimizing/graph_test.cc \
+  compiler/optimizing/linearize_test.cc \
+  compiler/optimizing/liveness_test.cc \
+  compiler/optimizing/live_interval_test.cc \
+  compiler/optimizing/live_ranges_test.cc \
+  compiler/optimizing/parallel_move_test.cc \
+  compiler/optimizing/pretty_printer_test.cc \
+  compiler/optimizing/register_allocator_test.cc \
+  compiler/optimizing/ssa_test.cc \
+  compiler/output_stream_test.cc \
+  compiler/utils/arena_allocator_test.cc \
+  compiler/utils/dedupe_set_test.cc \
+  compiler/utils/arm/managed_register_arm_test.cc \
+  compiler/utils/arm64/managed_register_arm64_test.cc \
+  compiler/utils/x86/managed_register_x86_test.cc \
 
 ifeq ($(ART_SEA_IR_MODE),true)
 COMPILER_GTEST_COMMON_SRC_FILES += \
-	compiler/utils/scoped_hashtable_test.cc \
-	compiler/sea_ir/types/type_data_test.cc \
-	compiler/sea_ir/types/type_inference_visitor_test.cc \
-	compiler/sea_ir/ir/regions_test.cc
+  compiler/utils/scoped_hashtable_test.cc \
+  compiler/sea_ir/types/type_data_test.cc \
+  compiler/sea_ir/types/type_inference_visitor_test.cc \
+  compiler/sea_ir/ir/regions_test.cc
 endif
 
 RUNTIME_GTEST_TARGET_SRC_FILES := \
-	$(RUNTIME_GTEST_COMMON_SRC_FILES)
+  $(RUNTIME_GTEST_COMMON_SRC_FILES)
 
 RUNTIME_GTEST_HOST_SRC_FILES := \
-	$(RUNTIME_GTEST_COMMON_SRC_FILES)
+  $(RUNTIME_GTEST_COMMON_SRC_FILES)
 
 COMPILER_GTEST_TARGET_SRC_FILES := \
-	$(COMPILER_GTEST_COMMON_SRC_FILES)
+  $(COMPILER_GTEST_COMMON_SRC_FILES)
 
 COMPILER_GTEST_HOST_SRC_FILES := \
-	$(COMPILER_GTEST_COMMON_SRC_FILES) \
-	compiler/utils/x86/assembler_x86_test.cc \
-	compiler/utils/x86_64/assembler_x86_64_test.cc
-
-ART_HOST_GTEST_EXECUTABLES :=
-ART_TARGET_GTEST_EXECUTABLES$(ART_PHONY_TEST_TARGET_SUFFIX) :=
-ART_TARGET_GTEST_EXECUTABLES$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) :=
-ART_HOST_GTEST_TARGETS :=
-ART_HOST_VALGRIND_GTEST_TARGETS :=
-ART_TARGET_GTEST_TARGETS$(ART_PHONY_TEST_TARGET_SUFFIX) :=
-ART_TARGET_GTEST_TARGETS$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) :=
+  $(COMPILER_GTEST_COMMON_SRC_FILES) \
+  compiler/utils/x86/assembler_x86_test.cc \
+  compiler/utils/x86_64/assembler_x86_64_test.cc
 
 ART_TEST_CFLAGS :=
 ifeq ($(ART_USE_PORTABLE_COMPILER),true)
   ART_TEST_CFLAGS += -DART_USE_PORTABLE_COMPILER=1
 endif
 
-# Build a make target for a target test.
-# (1) Prefix for variables
-define build-art-test-make-target
-.PHONY: $$(art_gtest_target)$($(1)ART_PHONY_TEST_TARGET_SUFFIX)
-$$(art_gtest_target)$($(1)ART_PHONY_TEST_TARGET_SUFFIX): $(ART_NATIVETEST_OUT)/$(TARGET_$(1)ARCH)/$$(LOCAL_MODULE) test-art-target-sync
-	adb shell touch $(ART_TEST_DIR)/$(TARGET_$(1)ARCH)/$$@
-	adb shell rm $(ART_TEST_DIR)/$(TARGET_$(1)ARCH)/$$@
-	adb shell chmod 755 $(ART_NATIVETEST_DIR)/$(TARGET_$(1)ARCH)/$$(notdir $$<)
-	adb shell sh -c "$(ART_NATIVETEST_DIR)/$(TARGET_$(1)ARCH)/$$(notdir $$<) && touch $(ART_TEST_DIR)/$(TARGET_$(1)ARCH)/$$@"
-	$(hide) (adb pull $(ART_TEST_DIR)/$(TARGET_$(1)ARCH)/$$@ /tmp/ && echo $$@ PASSED) || (echo $$@ FAILED && exit 1)
-	$(hide) rm /tmp/$$@
+# Variables holding collections of gtest pre-requisits used to run a number of gtests.
+ART_TEST_HOST_GTEST$(ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_GTEST$(2ND_ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_GTEST_RULES :=
+ART_TEST_HOST_VALGRIND_GTEST$(ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_VALGRIND_GTEST$(2ND_ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_VALGRIND_GTEST_RULES :=
+ART_TEST_TARGET_GTEST$(ART_PHONY_TEST_TARGET_SUFFIX)_RULES :=
+ART_TEST_TARGET_GTEST$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)_RULES :=
+ART_TEST_TARGET_GTEST_RULES :=
 
-  ART_TARGET_GTEST_TARGETS$($(1)ART_PHONY_TEST_TARGET_SUFFIX) += $$(art_gtest_target)$($(1)ART_PHONY_TEST_TARGET_SUFFIX)
-endef
+# Define a make rule for a target device gtest.
+# $(1): gtest name - the name of the test we're building such as leb128_test.
+# $(2): 2ND_ or undefined - used to differentiate between the primary and secondary architecture.
+define define-art-gtest-rule-target
+  gtest_rule := test-art-target-gtest-$(1)$$($(2)ART_PHONY_TEST_TARGET_SUFFIX)
 
+  # Add the test dependencies to test-art-target-sync, which will be a prerequisit for the test
+  # to ensure files are pushed to the device.
+  TEST_ART_TARGET_SYNC_DEPS += \
+    $$(ART_GTEST_$(1)_DEPS) \
+    $$(ART_TARGET_NATIVETEST_OUT)/$$(TARGET_$(2)ARCH)/$(1) \
+    $$(TARGET_CORE_DEX_LOCATIONS)
 
+.PHONY: $$(gtest_rule)
+$$(gtest_rule): test-art-target-sync
+	$(hide) adb shell touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
+	$(hide) adb shell rm $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
+	$(hide) adb shell chmod 755 $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1)
+	$(hide) $$(call ART_TEST_SKIP,$$@) && \
+	  (adb shell sh -c "$(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1) && touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID" \
+	  && (adb pull $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID /tmp/ \
+	      && $$(call ART_TEST_PASSED,$$@)) \
+	  || $$(call ART_TEST_FAILED,$$@))
+	$(hide) rm /tmp/$$@-$$$$PPID
+
+  ART_TEST_TARGET_GTEST$($(2)ART_PHONY_TEST_TARGET_SUFFIX)_RULES += $$(gtest_rule)
+  ART_TEST_TARGET_GTEST_RULES += $$(gtest_rule)
+  ART_TEST_TARGET_GTEST_$(1)_RULES += $$(gtest_rule)
+
+  # Clear locally defined variables.
+  gtest_rule :=
+endef  # define-art-gtest-rule-target
+
+# Define make rules for a host gtests.
+# $(1): gtest name - the name of the test we're building such as leb128_test.
+# $(2): 2ND_ or undefined - used to differentiate between the primary and secondary architecture.
+define define-art-gtest-rule-host
+  gtest_rule := test-art-host-gtest-$(1)$$($(2)ART_PHONY_TEST_HOST_SUFFIX)
+  gtest_exe := $$(HOST_OUT_EXECUTABLES)/$(1)$$($(2)ART_PHONY_TEST_HOST_SUFFIX)
+
+.PHONY: $$(gtest_rule)
+$$(gtest_rule): $$(gtest_exe) $$(ART_GTEST_$(1)_DEPS) $$(HOST_CORE_DEX_LOCATIONS)
+	$(hide) ($$(call ART_TEST_SKIP,$$@) && $$< && $$(call ART_TEST_PASSED,$$@)) \
+	  || $$(call ART_TEST_FAILED,$$@)
+
+  ART_TEST_HOST_GTEST$$($(2)ART_PHONY_TEST_HOST_SUFFIX)_RULES += $$(gtest_rule)
+  ART_TEST_HOST_GTEST_RULES += $$(gtest_rule)
+  ART_TEST_HOST_GTEST_$(1)_RULES += $$(gtest_rule)
+
+.PHONY: valgrind-$$(gtest_rule)
+valgrind-$$(gtest_rule): $$(gtest_exe) test-art-host-dependencies $$(ART_GTEST_$(1)_DEPS)
+	$(hide) $$(call ART_TEST_SKIP,$$@) && \
+	  valgrind --leak-check=full --error-exitcode=1 $$< && $$(call ART_TEST_PASSED,$$@) \
+	    || $$(call ART_TEST_FAILED,$$@)
+
+  ART_TEST_HOST_VALGRIND_GTEST$$($(2)ART_PHONY_TEST_HOST_SUFFIX)_RULES += valgrind-$$(gtest_rule)
+  ART_TEST_HOST_VALGRIND_GTEST_RULES += valgrind-$$(gtest_rule)
+  ART_TEST_HOST_VALGRIND_GTEST_$(1)_RULES += valgrind-$$(gtest_rule)
+
+  # Clear locally defined variables.
+  valgrind_gtest_rule :=
+  gtest_rule :=
+  gtest_exe :=
+endef  # define-art-gtest-rule-host
+
+# Define the rules to build and run host and target gtests.
 # $(1): target or host
 # $(2): file name
 # $(3): extra C includes
 # $(4): extra shared libraries
-define build-art-test
+define define-art-gtest
   ifneq ($(1),target)
     ifneq ($(1),host)
       $$(error expected target or host for argument 1, received $(1))
@@ -166,94 +270,103 @@
   art_gtest_extra_c_includes := $(3)
   art_gtest_extra_shared_libraries := $(4)
 
+  include $$(CLEAR_VARS)
   art_gtest_name := $$(notdir $$(basename $$(art_gtest_filename)))
-
-  include $(CLEAR_VARS)
-  LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
   LOCAL_MODULE := $$(art_gtest_name)
   ifeq ($$(art_target_or_host),target)
     LOCAL_MODULE_TAGS := tests
   endif
+  LOCAL_CPP_EXTENSION := $$(ART_CPP_EXTENSION)
   LOCAL_SRC_FILES := $$(art_gtest_filename) runtime/common_runtime_test.cc
-  LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime $(3)
-  LOCAL_SHARED_LIBRARIES += libartd $(4)
-  # dex2oatd is needed to go with libartd
-  LOCAL_REQUIRED_MODULES := dex2oatd
+  LOCAL_C_INCLUDES += $$(ART_C_INCLUDES) art/runtime $$(art_gtest_extra_c_includes)
+  LOCAL_SHARED_LIBRARIES += libartd $$(art_gtest_extra_shared_libraries)
 
-  LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk
-  LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.gtest.mk
+  # LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk
+  # LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.gtest.mk
 
   # Mac OS linker doesn't understand --export-dynamic.
-  ifneq ($(HOST_OS)-$$(art_target_or_host),darwin-host)
+  ifneq ($$(HOST_OS)-$$(art_target_or_host),darwin-host)
     # Allow jni_compiler_test to find Java_MyClassNatives_bar within itself using dlopen(NULL, ...).
     LOCAL_LDFLAGS := -Wl,--export-dynamic -Wl,-u,Java_MyClassNatives_bar -Wl,-u,Java_MyClassNatives_sbar
   endif
 
-  LOCAL_CFLAGS := $(ART_TEST_CFLAGS)
+  LOCAL_CFLAGS := $$(ART_TEST_CFLAGS)
   include external/libcxx/libcxx.mk
   ifeq ($$(art_target_or_host),target)
-  	$(call set-target-local-clang-vars)
-  	$(call set-target-local-cflags-vars,debug)
+    $$(eval $$(call set-target-local-clang-vars))
+    $$(eval $$(call set-target-local-cflags-vars,debug))
     LOCAL_SHARED_LIBRARIES += libdl libicuuc libicui18n libnativehelper libz libcutils libvixl
     LOCAL_STATIC_LIBRARIES += libgtest_libc++
-    LOCAL_MODULE_PATH_32 := $(ART_NATIVETEST_OUT)/$(ART_TARGET_ARCH_32)
-    LOCAL_MODULE_PATH_64 := $(ART_NATIVETEST_OUT)/$(ART_TARGET_ARCH_64)
+    LOCAL_MODULE_PATH_32 := $$(ART_TARGET_NATIVETEST_OUT)/$$(ART_TARGET_ARCH_32)
+    LOCAL_MODULE_PATH_64 := $$(ART_TARGET_NATIVETEST_OUT)/$$(ART_TARGET_ARCH_64)
     LOCAL_MULTILIB := both
-    include $(BUILD_EXECUTABLE)
+    include $$(BUILD_EXECUTABLE)
 
-    ART_TARGET_GTEST_EXECUTABLES$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_NATIVETEST_OUT)/$(TARGET_ARCH)/$$(LOCAL_MODULE)
-    art_gtest_target := test-art-$$(art_target_or_host)-gtest-$$(art_gtest_name)
-
+    ART_TEST_TARGET_GTEST_$$(art_gtest_name)_RULES :=
     ifdef TARGET_2ND_ARCH
-      $(call build-art-test-make-target,2ND_)
-
-      ART_TARGET_GTEST_EXECUTABLES$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_NATIVETEST_OUT)/$(TARGET_2ND_ARCH)/$$(LOCAL_MODULE)
-
-      # Bind the primary to the non-suffix rule
-      ifneq ($(ART_PHONY_TEST_TARGET_SUFFIX),)
-$$(art_gtest_target): $$(art_gtest_target)$(ART_PHONY_TEST_TARGET_SUFFIX)
-      endif
+      $$(eval $$(call define-art-gtest-rule-target,$$(art_gtest_name),2ND_))
     endif
-    $(call build-art-test-make-target,)
+    $$(eval $$(call define-art-gtest-rule-target,$$(art_gtest_name),))
 
+    # A rule to run the different architecture versions of the gtest.
+.PHONY: test-art-target-gtest-$$(art_gtest_name)
+test-art-target-gtest-$$(art_gtest_name): $$(ART_TEST_TARGET_GTEST_$$(art_gtest_name)_RULES)
+	$$(hide) $$(call ART_TEST_PREREQ_FINISHED,$$@)
+
+    # Clear locally defined variables.
+    ART_TEST_TARGET_GTEST_$$(art_gtest_name)_RULES :=
   else # host
-    LOCAL_CLANG := $(ART_HOST_CLANG)
-    LOCAL_CFLAGS += $(ART_HOST_CFLAGS) $(ART_HOST_DEBUG_CFLAGS)
+    LOCAL_CLANG := $$(ART_HOST_CLANG)
+    LOCAL_CFLAGS += $$(ART_HOST_CFLAGS) $$(ART_HOST_DEBUG_CFLAGS)
     LOCAL_SHARED_LIBRARIES += libicuuc-host libicui18n-host libnativehelper libz-host
     LOCAL_STATIC_LIBRARIES += libcutils libvixl
-    ifneq ($(WITHOUT_HOST_CLANG),true)
-        # GCC host compiled tests fail with this linked, presumably due to destructors that run.
-        LOCAL_STATIC_LIBRARIES += libgtest_libc++_host
+    ifneq ($$(WITHOUT_HOST_CLANG),true)
+      # GCC host compiled tests fail with this linked, presumably due to destructors that run.
+      LOCAL_STATIC_LIBRARIES += libgtest_libc++_host
     endif
     LOCAL_LDLIBS += -lpthread -ldl
     LOCAL_IS_HOST_MODULE := true
-    include $(BUILD_HOST_EXECUTABLE)
-    art_gtest_exe := $(HOST_OUT_EXECUTABLES)/$$(LOCAL_MODULE)
-    ART_HOST_GTEST_EXECUTABLES += $$(art_gtest_exe)
-    art_gtest_target := test-art-$$(art_target_or_host)-gtest-$$(art_gtest_name)
-.PHONY: $$(art_gtest_target)
-$$(art_gtest_target): $$(art_gtest_exe) test-art-host-dependencies
-	$$<
-	@echo $$@ PASSED
+    LOCAL_MULTILIB := both
+    LOCAL_MODULE_STEM_32 := $$(art_gtest_name)32
+    LOCAL_MODULE_STEM_64 := $$(art_gtest_name)64
+    include $$(BUILD_HOST_EXECUTABLE)
 
-    ART_HOST_GTEST_TARGETS += $$(art_gtest_target)
+    ART_TEST_HOST_GTEST_$$(art_gtest_name)_RULES :=
+    ART_TEST_HOST_VALGRIND_GTEST_$$(art_gtest_name)_RULES :=
+    ifneq ($$(HOST_PREFER_32_BIT),true)
+      $$(eval $$(call define-art-gtest-rule-host,$$(art_gtest_name),2ND_))
+    endif
+    $$(eval $$(call define-art-gtest-rule-host,$$(art_gtest_name),))
 
-.PHONY: valgrind-$$(art_gtest_target)
-valgrind-$$(art_gtest_target): $$(art_gtest_exe) test-art-host-dependencies
-	valgrind --leak-check=full --error-exitcode=1 $$<
-	@echo $$@ PASSED
+    # Rules to run the different architecture versions of the gtest.
+.PHONY: test-art-host-gtest-$$(art_gtest_name)
+test-art-host-gtest-$$(art_gtest_name): $$(ART_TEST_HOST_GTEST_$$(art_gtest_name)_RULES)
+	$$(hide) $$(call ART_TEST_PREREQ_FINISHED,$$@)
 
-    ART_HOST_VALGRIND_GTEST_TARGETS += valgrind-$$(art_gtest_target)
-  endif
-endef
+.PHONY: valgrind-test-art-host-gtest-$$(art_gtest_name)
+valgrind-test-art-host-gtest-$$(art_gtest_name): $$(ART_TEST_HOST_VALGRIND_GTEST_$$(art_gtest_name)_RULES)
+	$$(hide) $$(call ART_TEST_PREREQ_FINISHED,$$@)
+
+    # Clear locally defined variables.
+    ART_TEST_HOST_GTEST_$$(art_gtest_name)_RULES :=
+    ART_TEST_HOST_VALGRIND_GTEST_$$(art_gtest_name)_RULES :=
+  endif  # host_or_target
+
+  # Clear locally defined variables.
+  art_target_or_host :=
+  art_gtest_filename :=
+  art_gtest_extra_c_includes :=
+  art_gtest_extra_shared_libraries :=
+  art_gtest_name :=
+endef  # define-art-gtest
 
 ifeq ($(ART_BUILD_TARGET),true)
-  $(foreach file,$(RUNTIME_GTEST_TARGET_SRC_FILES), $(eval $(call build-art-test,target,$(file),,)))
-  $(foreach file,$(COMPILER_GTEST_TARGET_SRC_FILES), $(eval $(call build-art-test,target,$(file),art/compiler,libartd-compiler)))
+  $(foreach file,$(RUNTIME_GTEST_TARGET_SRC_FILES), $(eval $(call define-art-gtest,target,$(file),,)))
+  $(foreach file,$(COMPILER_GTEST_TARGET_SRC_FILES), $(eval $(call define-art-gtest,target,$(file),art/compiler,libartd-compiler)))
 endif
 ifeq ($(ART_BUILD_HOST),true)
-  $(foreach file,$(RUNTIME_GTEST_HOST_SRC_FILES), $(eval $(call build-art-test,host,$(file),,)))
-  $(foreach file,$(COMPILER_GTEST_HOST_SRC_FILES), $(eval $(call build-art-test,host,$(file),art/compiler,libartd-compiler)))
+  $(foreach file,$(RUNTIME_GTEST_HOST_SRC_FILES), $(eval $(call define-art-gtest,host,$(file),,)))
+  $(foreach file,$(COMPILER_GTEST_HOST_SRC_FILES), $(eval $(call define-art-gtest,host,$(file),art/compiler,libartd-compiler)))
 endif
 
 # Used outside the art project to get a list of the current tests
@@ -261,3 +374,85 @@
 $(foreach file, $(RUNTIME_GTEST_TARGET_SRC_FILES), $(eval RUNTIME_TARGET_GTEST_MAKE_TARGETS += $$(notdir $$(basename $$(file)))))
 COMPILER_TARGET_GTEST_MAKE_TARGETS :=
 $(foreach file, $(COMPILER_GTEST_TARGET_SRC_FILES), $(eval COMPILER_TARGET_GTEST_MAKE_TARGETS += $$(notdir $$(basename $$(file)))))
+
+# Define all the combinations of host/target, valgrind and suffix such as:
+# test-art-host-gtest or valgrind-test-art-host-gtest64
+# $(1): host or target
+# $(2): HOST or TARGET
+# $(3): valgrind- or undefined
+# $(4): undefined, 32 or 64
+define define-test-art-gtest-combination
+  ifeq ($(1),host)
+    ifneq ($(2),HOST)
+      $$(error argument mismatch $(1) and ($2))
+    endif
+  else
+    ifneq ($(1),target)
+      $$(error found $(1) expected host or target)
+    endif
+    ifneq ($(2),TARGET)
+      $$(error argument mismatch $(1) and ($2))
+    endif
+  endif
+
+  rule_name := $(3)test-art-$(1)-gtest$(4)
+  dependencies := $$(ART_TEST_$(2)_GTEST$(4)_RULES)
+
+.PHONY: $$(rule_name)
+$$(rule_name): $$(dependencies)
+	$(hide) $$(call ART_TEST_PREREQ_FINISHED,$$@)
+
+  # Clear locally defined variables.
+  rule_name :=
+  dependencies :=
+endef  # define-test-art-gtest-combination
+
+$(eval $(call define-test-art-gtest-combination,target,TARGET,,))
+$(eval $(call define-test-art-gtest-combination,target,TARGET,,$(ART_PHONY_TEST_TARGET_SUFFIX)))
+ifdef TARGET_2ND_ARCH
+$(eval $(call define-test-art-gtest-combination,target,TARGET,,$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)))
+endif
+$(eval $(call define-test-art-gtest-combination,host,HOST,,))
+$(eval $(call define-test-art-gtest-combination,host,HOST,valgrind-,))
+$(eval $(call define-test-art-gtest-combination,host,HOST,,$(ART_PHONY_TEST_HOST_SUFFIX)))
+$(eval $(call define-test-art-gtest-combination,host,HOST,valgrind-,$(ART_PHONY_TEST_HOST_SUFFIX)))
+ifneq ($(HOST_PREFER_32_BIT),true)
+$(eval $(call define-test-art-gtest-combination,host,HOST,,$(2ND_ART_PHONY_TEST_HOST_SUFFIX)))
+$(eval $(call define-test-art-gtest-combination,host,HOST,valgrind-,$(2ND_ART_PHONY_TEST_HOST_SUFFIX)))
+endif
+
+# Clear locally defined variables.
+define-art-gtest-rule-target :=
+define-art-gtest-rule-host :=
+define-art-gtest :=
+define-test-art-gtest-combination :=
+RUNTIME_GTEST_COMMON_SRC_FILES :=
+COMPILER_GTEST_COMMON_SRC_FILES :=
+RUNTIME_GTEST_TARGET_SRC_FILES :=
+RUNTIME_GTEST_HOST_SRC_FILES :=
+COMPILER_GTEST_TARGET_SRC_FILES :=
+COMPILER_GTEST_HOST_SRC_FILES :=
+ART_TEST_CFLAGS :=
+ART_TEST_HOST_GTEST$(ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_GTEST$(2ND_ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_GTEST_RULES :=
+ART_TEST_HOST_VALGRIND_GTEST$(ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_VALGRIND_GTEST$(2ND_ART_PHONY_TEST_HOST_SUFFIX)_RULES :=
+ART_TEST_HOST_VALGRIND_GTEST_RULES :=
+ART_TEST_TARGET_GTEST$(ART_PHONY_TEST_TARGET_SUFFIX)_RULES :=
+ART_TEST_TARGET_GTEST$(2ND_ART_PHONY_TEST_TARGET_SUFFIX)_RULES :=
+ART_TEST_TARGET_GTEST_RULES :=
+ART_GTEST_class_linker_test_DEPS :=
+ART_GTEST_compiler_test_DEPS :=
+ART_GTEST_dex_file_test_DEPS :=
+ART_GTEST_exception_test_DEPS :=
+ART_GTEST_jni_compiler_test_DEPS :=
+ART_GTEST_jni_internal_test_DEPS :=
+ART_GTEST_object_test_DEPS :=
+ART_GTEST_proxy_test_DEPS :=
+ART_GTEST_reflection_test_DEPS :=
+ART_GTEST_stub_test_DEPS :=
+ART_GTEST_transaction_test_DEPS :=
+$(foreach dir,$(GTEST_DEX_DIRECTORIES), $(eval ART_GTEST_TEST_$(dir)_DEX :=))
+GTEST_DEX_DIRECTORIES :=
+LOCAL_PATH :=
\ No newline at end of file
diff --git a/build/Android.libarttest.mk b/build/Android.libarttest.mk
deleted file mode 100644
index 76e5af0..0000000
--- a/build/Android.libarttest.mk
+++ /dev/null
@@ -1,79 +0,0 @@
-#
-# 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.
-#
-
-LIBARTTEST_COMMON_SRC_FILES := \
-	test/JniTest/jni_test.cc \
-	test/SignalTest/signaltest.cc \
-	test/ReferenceMap/stack_walk_refmap_jni.cc \
-	test/StackWalk/stack_walk_jni.cc \
-	test/UnsafeTest/unsafe_test.cc
-
-ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TEST_OUT)/$(TARGET_ARCH)/libarttest.so
-ifdef TARGET_2ND_ARCH
-  ART_TARGET_LIBARTTEST_$(2ND_ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TEST_OUT)/$(TARGET_2ND_ARCH)/libarttest.so
-endif
-
-# $(1): target or host
-define build-libarttest
-  ifneq ($(1),target)
-    ifneq ($(1),host)
-      $$(error expected target or host for argument 1, received $(1))
-    endif
-  endif
-
-  art_target_or_host := $(1)
-
-  include $(CLEAR_VARS)
-  LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
-  LOCAL_MODULE := libarttest
-  ifeq ($$(art_target_or_host),target)
-    LOCAL_MODULE_TAGS := tests
-  endif
-  LOCAL_SRC_FILES := $(LIBARTTEST_COMMON_SRC_FILES)
-  LOCAL_SHARED_LIBRARIES += libartd
-  LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime
-  LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/build/Android.common.mk
-  LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/build/Android.libarttest.mk
-  include external/libcxx/libcxx.mk
-  ifeq ($$(art_target_or_host),target)
-  	$(call set-target-local-clang-vars)
-  	$(call set-target-local-cflags-vars,debug)
-    LOCAL_SHARED_LIBRARIES += libdl libcutils
-    LOCAL_STATIC_LIBRARIES := libgtest
-    LOCAL_MULTILIB := both
-    LOCAL_MODULE_PATH_32 := $(ART_TEST_OUT)/$(ART_TARGET_ARCH_32)
-    LOCAL_MODULE_PATH_64 := $(ART_TEST_OUT)/$(ART_TARGET_ARCH_64)
-    LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
-    include $(BUILD_SHARED_LIBRARY)
-  else # host
-    LOCAL_CLANG := $(ART_HOST_CLANG)
-    LOCAL_CFLAGS := $(ART_HOST_CFLAGS) $(ART_HOST_DEBUG_CFLAGS)
-    LOCAL_STATIC_LIBRARIES := libcutils
-    LOCAL_LDLIBS += -ldl -lpthread
-    ifeq ($(HOST_OS),linux)
-      LOCAL_LDLIBS += -lrt
-    endif
-    LOCAL_IS_HOST_MODULE := true
-    include $(BUILD_HOST_SHARED_LIBRARY)
-  endif
-endef
-
-ifeq ($(ART_BUILD_TARGET),true)
-  $(eval $(call build-libarttest,target))
-endif
-ifeq ($(ART_BUILD_HOST),true)
-  $(eval $(call build-libarttest,host))
-endif
diff --git a/build/Android.oat.mk b/build/Android.oat.mk
index c67a815..3117f71 100644
--- a/build/Android.oat.mk
+++ b/build/Android.oat.mk
@@ -20,53 +20,62 @@
 #
 # The main rules to build the default "boot" image are in
 # build/core/dex_preopt_libart.mk
-TARGET_CORE_JARS := core-libart conscrypt okhttp core-junit bouncycastle
-HOST_CORE_JARS := $(addsuffix -hostdex,$(TARGET_CORE_JARS))
 
-HOST_CORE_DEX_LOCATIONS   := $(foreach jar,$(HOST_CORE_JARS),  $(HOST_OUT_JAVA_LIBRARIES)/$(jar).jar)
-TARGET_CORE_DEX_LOCATIONS := $(foreach jar,$(TARGET_CORE_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar)
-
-HOST_CORE_DEX_FILES   := $(foreach jar,$(HOST_CORE_JARS),  $(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),t,COMMON)/javalib.jar)
-TARGET_CORE_DEX_FILES := $(foreach jar,$(TARGET_CORE_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar), ,COMMON)/javalib.jar)
-
-TARGET_INSTRUCTION_SET_FEATURES := $(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
+include art/build/Android.common_path.mk
 
 # Use dex2oat debug version for better error reporting
-$(HOST_CORE_IMG_OUT): $(HOST_CORE_DEX_FILES) $(DEX2OATD_DEPENDENCY)
-	@echo "host dex2oat: $@ ($?)"
-	@mkdir -p $(dir $@)
-	$(hide) $(DEX2OATD) --runtime-arg -Xms16m --runtime-arg -Xmx16m --image-classes=$(PRELOADED_CLASSES) $(addprefix \
-		--dex-file=,$(HOST_CORE_DEX_FILES)) $(addprefix --dex-location=,$(HOST_CORE_DEX_LOCATIONS)) --oat-file=$(HOST_CORE_OAT_OUT) \
-		--oat-location=$(HOST_CORE_OAT) --image=$(HOST_CORE_IMG_OUT) --base=$(LIBART_IMG_HOST_BASE_ADDRESS) \
-		--instruction-set=$(ART_HOST_ARCH) --host --android-root=$(HOST_OUT)
+# $(1): 2ND_ or undefined, 2ND_ for 32-bit host builds.
+define create-core-oat-host-rules
+$$($(1)HOST_CORE_IMG_OUT): $$($(1)HOST_CORE_DEX_FILES) $$(DEX2OATD_DEPENDENCY)
+	@echo "host dex2oat: $$@ ($$?)"
+	@mkdir -p $$(dir $$@)
+	$$(hide) $$(DEX2OATD) --runtime-arg -Xms16m --runtime-arg -Xmx16m \
+	  --image-classes=$$(PRELOADED_CLASSES) $$(addprefix --dex-file=,$$(HOST_CORE_DEX_FILES)) \
+	  $$(addprefix --dex-location=,$$(HOST_CORE_DEX_LOCATIONS)) --oat-file=$$($(1)HOST_CORE_OAT_OUT) \
+	  --oat-location=$$($(1)HOST_CORE_OAT) --image=$$($(1)HOST_CORE_IMG_OUT) \
+	  --base=$$(LIBART_IMG_HOST_BASE_ADDRESS) --instruction-set=$$($(1)ART_HOST_ARCH) \
+	  --instruction-set-features=$$($(1)HOST_INSTRUCTION_SET_FEATURES) \
+	  --host --android-root=$$(HOST_OUT)
 
-$(HOST_CORE_OAT_OUT): $(HOST_CORE_IMG_OUT)
+# This "renaming" eases declaration in art/Android.mk
+HOST_CORE_IMG_OUT$($(1)ART_PHONY_TEST_HOST_SUFFIX) := $($(1)HOST_CORE_IMG_OUT)
+
+$$($(1)HOST_CORE_OAT_OUT): $$($(1)HOST_CORE_IMG_OUT)
+endef  # create-core-oat-host-rules
+
+$(eval $(call create-core-oat-host-rules,))
+ifneq ($(HOST_PREFER_32_BIT),true)
+$(eval $(call create-core-oat-host-rules,2ND_))
+endif
 
 IMPLICIT_CHECKS_arm := null,stack
 IMPLICIT_CHECKS_arm64 := none
 IMPLICIT_CHECKS_x86 := none
 IMPLICIT_CHECKS_x86_64 := none
 IMPLICIT_CHECKS_mips := none
-define create-oat-target-targets
+define create-core-oat-target-rules
 $$($(1)TARGET_CORE_IMG_OUT): $$($(1)TARGET_CORE_DEX_FILES) $$(DEX2OATD_DEPENDENCY)
 	@echo "target dex2oat: $$@ ($$?)"
 	@mkdir -p $$(dir $$@)
-	$$(hide) $$(DEX2OATD) --runtime-arg -Xms16m --runtime-arg -Xmx16m --image-classes=$$(PRELOADED_CLASSES) $$(addprefix \
-		--dex-file=,$$(TARGET_CORE_DEX_FILES)) $$(addprefix --dex-location=,$$(TARGET_CORE_DEX_LOCATIONS)) --oat-file=$$($(1)TARGET_CORE_OAT_OUT) \
-		--oat-location=$$($(1)TARGET_CORE_OAT) --image=$$($(1)TARGET_CORE_IMG_OUT) --base=$$(LIBART_IMG_TARGET_BASE_ADDRESS) \
-		--implicit-checks=$(IMPLICIT_CHECKS_$($(1)TARGET_ARCH)) \
-		--instruction-set=$$($(1)TARGET_ARCH) --instruction-set-features=$$(TARGET_INSTRUCTION_SET_FEATURES) --android-root=$$(PRODUCT_OUT)/system
+	$$(hide) $$(DEX2OATD) --runtime-arg -Xms16m --runtime-arg -Xmx16m \
+	  --image-classes=$$(PRELOADED_CLASSES) $$(addprefix --dex-file=,$$(TARGET_CORE_DEX_FILES)) \
+	  $$(addprefix --dex-location=,$$(TARGET_CORE_DEX_LOCATIONS)) --oat-file=$$($(1)TARGET_CORE_OAT_OUT) \
+	  --oat-location=$$($(1)TARGET_CORE_OAT) --image=$$($(1)TARGET_CORE_IMG_OUT) \
+	  --base=$$(LIBART_IMG_TARGET_BASE_ADDRESS) --instruction-set=$$($(1)TARGET_ARCH) \
+	  --instruction-set-features=$$($(1)TARGET_INSTRUCTION_SET_FEATURES) \
+	  --implicit-checks=$(IMPLICIT_CHECKS_$($(1)TARGET_ARCH)) \
+	  --android-root=$$(PRODUCT_OUT)/system
 
 # This "renaming" eases declaration in art/Android.mk
 TARGET_CORE_IMG_OUT$($(1)ART_PHONY_TEST_TARGET_SUFFIX) := $($(1)TARGET_CORE_IMG_OUT)
 
 $$($(1)TARGET_CORE_OAT_OUT): $$($(1)TARGET_CORE_IMG_OUT)
-endef
+endef  # create-core-oat-target-rules
 
 ifdef TARGET_2ND_ARCH
-  $(eval $(call create-oat-target-targets,2ND_))
+$(eval $(call create-core-oat-target-rules,2ND_))
 endif
-$(eval $(call create-oat-target-targets,))
+$(eval $(call create-core-oat-target-rules,))
 
 
 ifeq ($(ART_BUILD_HOST),true)