am 2bf10a72: am cdcb6926: am 6cb69bd4: Merge "Add HOST_PREFER_32_BIT to support 32-bit-by-default multilib build"

* commit '2bf10a72f87a8e97923286aa331f7db81e2361ca':
  Add HOST_PREFER_32_BIT to support 32-bit-by-default multilib build
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 9571001..548ed13 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -175,11 +175,11 @@
 else
   built_module_path := $(intermediates)
 endif
-LOCAL_BUILT_MODULE := $(built_module_path)/$(LOCAL_BUILT_MODULE_STEM)
+LOCAL_BUILT_MODULE := $(built_module_path)/$(my_built_module_stem)
 built_module_path :=
 
 ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
-  LOCAL_INSTALLED_MODULE := $(my_module_path)/$(LOCAL_INSTALLED_MODULE_STEM)
+  LOCAL_INSTALLED_MODULE := $(my_module_path)/$(my_installed_module_stem)
 endif
 
 # Assemble the list of targets to create PRIVATE_ variables for.
@@ -571,10 +571,12 @@
 ifdef LOCAL_DONT_CHECK_MODULE
   LOCAL_CHECKED_MODULE :=
 endif
-# Don't check build the module defined for the 2nd arch
+# Don't check build target module defined for the 2nd arch
+ifndef LOCAL_IS_HOST_MODULE
 ifdef LOCAL_2ND_ARCH_VAR_PREFIX
   LOCAL_CHECKED_MODULE :=
 endif
+endif
 
 ###########################################################
 ## Register with ALL_MODULES
diff --git a/core/configure_module_stem.mk b/core/configure_module_stem.mk
index 1560055..48b7787 100644
--- a/core/configure_module_stem.mk
+++ b/core/configure_module_stem.mk
@@ -1,16 +1,20 @@
 my_multilib_stem := $(LOCAL_MODULE_STEM_$(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32))
 ifdef my_multilib_stem
-LOCAL_MODULE_STEM := $(my_multilib_stem)
+  my_module_stem := $(my_multilib_stem)
+else ifdef LOCAL_MODULE_STEM
+  my_module_stem := $(LOCAL_MODULE_STEM)
+else
+  my_module_stem := $(LOCAL_MODULE)
 endif
 
-ifndef LOCAL_MODULE_STEM
-  LOCAL_MODULE_STEM := $(LOCAL_MODULE)
+ifdef LOCAL_BUILT_MODULE_STEM
+  my_built_module_stem := $(LOCAL_BUILT_MODULE_STEM)
+else
+  my_built_module_stem := $(my_module_stem)$(LOCAL_MODULE_SUFFIX)
 endif
 
-ifndef LOCAL_BUILT_MODULE_STEM
-  LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE_STEM)$(LOCAL_MODULE_SUFFIX)
-endif
-
-ifndef LOCAL_INSTALLED_MODULE_STEM
-  LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE_STEM)$(LOCAL_MODULE_SUFFIX)
+ifdef LOCAL_INSTALLED_MODULE_STEM
+  my_installed_module_stem := $(LOCAL_INSTALLED_MODULE_STEM)
+else
+  my_installed_module_stem := $(my_module_stem)$(LOCAL_MODULE_SUFFIX)
 endif
diff --git a/core/definitions.mk b/core/definitions.mk
index 11012ec..fbbc61c 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -84,8 +84,9 @@
 # Target and host installed module's dependencies on shared libraries.
 # They are list of "<module_name>:<installed_file>:lib1,lib2...".
 TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
-2ND_TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
+$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
 HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
+$(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
 
 # Generated class file names for Android resource.
 # They are escaped and quoted so can be passed safely to a bash command.
diff --git a/core/dex_preopt_libart.mk b/core/dex_preopt_libart.mk
index 7d8cee0..411af75 100644
--- a/core/dex_preopt_libart.mk
+++ b/core/dex_preopt_libart.mk
@@ -6,20 +6,15 @@
 DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oat$(HOST_EXECUTABLE_SUFFIX)
 DEX2OATD := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX)
 
-LIBART_COMPILER := $(HOST_OUT_SHARED_LIBRARIES)/libart-compiler$(HOST_SHLIB_SUFFIX)
-LIBARTD_COMPILER := $(HOST_OUT_SHARED_LIBRARIES)/libartd-compiler$(HOST_SHLIB_SUFFIX)
-
 # By default, do not run rerun dex2oat if the tool changes.
 # Comment out the | to force dex2oat to rerun on after all changes.
 DEX2OAT_DEPENDENCY := art/runtime/oat.cc # dependency on oat version number
 DEX2OAT_DEPENDENCY += art/runtime/image.cc # dependency on image version number
 DEX2OAT_DEPENDENCY += |
 DEX2OAT_DEPENDENCY += $(DEX2OAT)
-DEX2OAT_DEPENDENCY += $(LIBART_COMPILER)
 
 DEX2OATD_DEPENDENCY := $(DEX2OAT_DEPENDENCY)
 DEX2OATD_DEPENDENCY += $(DEX2OATD)
-DEX2OATD_DEPENDENCY += $(LIBARTD_COMPILER)
 
 PRELOADED_CLASSES := frameworks/base/preloaded-classes
 
diff --git a/core/dynamic_binary.mk b/core/dynamic_binary.mk
index e538d1e..396199c 100644
--- a/core/dynamic_binary.mk
+++ b/core/dynamic_binary.mk
@@ -26,7 +26,7 @@
 # The basename of this target must be the same as the final output
 # binary name, because it's used to set the "soname" in the binary.
 # The includer of this file will define a rule to build this target.
-linked_module := $(guessed_intermediates)/LINKED/$(LOCAL_BUILT_MODULE_STEM)
+linked_module := $(guessed_intermediates)/LINKED/$(my_built_module_stem)
 
 ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module)
 
@@ -57,7 +57,7 @@
 
 ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
 $(error Symbol compression not yet supported.)
-compress_output := $(intermediates)/COMPRESSED-$(LOCAL_BUILT_MODULE_STEM)
+compress_output := $(intermediates)/COMPRESSED-$(my_built_module_stem)
 
 #TODO: write the real $(STRIPPER) rule.
 #TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and
@@ -79,7 +79,7 @@
 my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
 endif
 symbolic_input := $(compress_output)
-symbolic_output := $(my_unstripped_path)/$(LOCAL_INSTALLED_MODULE_STEM)
+symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
 $(symbolic_output) : $(symbolic_input) | $(ACP)
 	@echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
 	$(copy-file-to-target)
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 2da9d8d..3498e34 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -67,6 +67,10 @@
 $(error Unable to determine HOST_OS from uname -sm: $(UNAME)!)
 endif
 
+ifeq ($(HOST_PREFER_32_BIT),true)
+# User asks for multilib build, but use 32-bit as preferred arch.
+BUILD_HOST_64bit := true
+endif
 
 # HOST_ARCH
 ifneq (,$(findstring x86_64,$(UNAME)))
@@ -230,7 +234,13 @@
 HOST_2ND_ARCH_MODULE_SUFFIX := _32
 $(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATES := $(HOST_OUT)/obj32
 $(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES := $($(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATES)/lib
+ifeq ($(HOST_PREFER_32_BIT),true)
+# To keep path compatibility, put 32-bit libs in lib/ and 64-bit libs in lib64/.
+HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib64
+$(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib
+else
 $(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES := $(HOST_OUT)/lib32
+endif
 $(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_EXECUTABLES := $(HOST_OUT_EXECUTABLES)
 
 
diff --git a/core/host_executable.mk b/core/host_executable.mk
index 874bf87..53b5fd1 100644
--- a/core/host_executable.mk
+++ b/core/host_executable.mk
@@ -3,9 +3,13 @@
 include $(BUILD_SYSTEM)/multilib.mk
 
 ifndef my_module_multilib
+ifeq ($(HOST_PREFER_32_BIT),true)
+my_module_multilib := 32
+else
 # By default we only build host module for the first arch.
 my_module_multilib := first
 endif
+endif
 
 ifeq ($(my_module_multilib),both)
 ifeq ($(LOCAL_MODULE_PATH_32)$(LOCAL_MODULE_STEM_32),)
@@ -33,9 +37,6 @@
 OVERRIDE_BUILT_MODULE_PATH :=
 LOCAL_BUILT_MODULE :=
 LOCAL_INSTALLED_MODULE :=
-LOCAL_MODULE_STEM :=
-LOCAL_BUILT_MODULE_STEM :=
-LOCAL_INSTALLED_MODULE_STEM :=
 LOCAL_INTERMEDIATE_TARGETS :=
 
 include $(BUILD_SYSTEM)/host_executable_internal.mk
diff --git a/core/host_shared_library.mk b/core/host_shared_library.mk
index de5e6ad..2fdf61f 100644
--- a/core/host_shared_library.mk
+++ b/core/host_shared_library.mk
@@ -2,9 +2,13 @@
 include $(BUILD_SYSTEM)/multilib.mk
 
 ifndef my_module_multilib
+ifeq ($(HOST_PREFER_32_BIT),true)
+my_module_multilib := 32
+else
 # By default we only build host module for the first arch.
 my_module_multilib := first
 endif
+endif
 
 LOCAL_2ND_ARCH_VAR_PREFIX :=
 include $(BUILD_SYSTEM)/module_arch_supported.mk
@@ -21,9 +25,6 @@
 OVERRIDE_BUILT_MODULE_PATH :=
 LOCAL_BUILT_MODULE :=
 LOCAL_INSTALLED_MODULE :=
-LOCAL_MODULE_STEM :=
-LOCAL_BUILT_MODULE_STEM :=
-LOCAL_INSTALLED_MODULE_STEM :=
 LOCAL_INTERMEDIATE_TARGETS :=
 
 include $(BUILD_SYSTEM)/host_shared_library_internal.mk
diff --git a/core/host_static_library.mk b/core/host_static_library.mk
index ab3f16e..c40cf7d 100644
--- a/core/host_static_library.mk
+++ b/core/host_static_library.mk
@@ -2,9 +2,13 @@
 include $(BUILD_SYSTEM)/multilib.mk
 
 ifndef my_module_multilib
+ifeq ($(HOST_PREFER_32_BIT),true)
+my_module_multilib := 32
+else
 # By default we only build host module for the first arch.
 my_module_multilib := first
 endif
+endif
 
 LOCAL_2ND_ARCH_VAR_PREFIX :=
 include $(BUILD_SYSTEM)/module_arch_supported.mk
@@ -21,9 +25,6 @@
 OVERRIDE_BUILT_MODULE_PATH :=
 LOCAL_BUILT_MODULE :=
 LOCAL_INSTALLED_MODULE :=
-LOCAL_MODULE_STEM :=
-LOCAL_BUILT_MODULE_STEM :=
-LOCAL_INSTALLED_MODULE_STEM :=
 LOCAL_INTERMEDIATE_TARGETS :=
 
 include $(BUILD_SYSTEM)/host_static_library_internal.mk
diff --git a/core/install_jni_libs.mk b/core/install_jni_libs.mk
index b9e70b1..700d106 100644
--- a/core/install_jni_libs.mk
+++ b/core/install_jni_libs.mk
@@ -36,7 +36,7 @@
 endif
 
 # App-specific lib path.
-my_app_lib_path :=  $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(LOCAL_INSTALLED_MODULE_STEM))
+my_app_lib_path :=  $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(my_installed_module_stem))
 my_extracted_jni_libs :=
 
 ifdef my_embed_jni
diff --git a/core/main.mk b/core/main.mk
index dd5cfa3..e8169fc 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -643,6 +643,14 @@
       $(subst $(comma),$(space),$(lastword $(p))))))) \
   $(eval $(call add-required-deps,$(word 2,$(p)),$(r))))
 endif
+ifdef HOST_2ND_ARCH
+$(foreach m,$($(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES), \
+  $(eval p := $(subst :,$(space),$(m))) \
+  $(eval r := $(filter $(HOST_OUT_ROOT)/%,$(call module-installed-files,\
+    $(addsuffix $(HOST_2ND_ARCH_MODULE_SUFFIX), \
+      $(subst $(comma),$(space),$(lastword $(p))))))) \
+  $(eval $(call add-required-deps,$(word 2,$(p)),$(r))))
+endif
 
 m :=
 r :=