art: convert makefiles to support multilib build

Convert makefiles to allow for building two architectures at the
same time.  More changes may be necessary to get the tests to
build.

Change-Id: I02ba11706b7e5b5592d76e43c167bcbf0e665b93
diff --git a/Android.mk b/Android.mk
index 6ad5606..b8d14e3 100644
--- a/Android.mk
+++ b/Android.mk
@@ -62,6 +62,10 @@
 	rm -f $(TARGET_OUT_APPS)/*.odex
 	rm -f $(TARGET_OUT_INTERMEDIATES)/JAVA_LIBRARIES/*_intermediates/javalib.odex
 	rm -f $(TARGET_OUT_INTERMEDIATES)/APPS/*_intermediates/*.odex
+ifdef TARGET_2ND_ARCH
+	rm -f $(2ND_TARGET_OUT_INTERMEDIATES)/JAVA_LIBRARIES/*_intermediates/javalib.odex
+	rm -f $(2ND_TARGET_OUT_INTERMEDIATES)/APPS/*_intermediates/*.odex
+endif
 	rm -rf /tmp/test-*/dalvik-cache/*@classes.dex
 	rm -rf /tmp/android-data/dalvik-cache/*@classes.dex
 
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 415d810..1299beb 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -17,6 +17,12 @@
 ifndef ANDROID_COMMON_MK
 ANDROID_COMMON_MK = true
 
+ART_SUPPORTED_ARCH := arm mips x86 x86_64
+
+ifeq (,$(filter $(TARGET_ARCH),$(ART_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.
 #
@@ -162,10 +168,6 @@
 endif
 ART_TARGET_CFLAGS += -DART_DEFAULT_INSTRUCTION_SET_FEATURES=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
 
-ifeq ($(TARGET_ARCH),x86)
-ART_TARGET_CFLAGS += -msse2
-endif
-
 # Enable thread-safety for GCC 4.6 on the target but not for GCC 4.7 where this feature was removed.
 ifneq ($(filter 4.6 4.6.%, $(TARGET_GCC_VERSION)),)
   ART_TARGET_CFLAGS += -Wthread-safety
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 5cf15be..e8d48e4 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -70,6 +70,7 @@
   ifeq ($$(art_target_or_host),target)
     LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
+    LOCAL_CFLAGS_x86 += $(ART_TARGET_CFLAGS_x86)
     ifeq ($$(art_ndebug_or_debug),debug)
       LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS)
     else
@@ -95,6 +96,10 @@
   LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.executable.mk
 
   ifeq ($$(art_target_or_host),target)
+    LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
+  endif
+
+  ifeq ($$(art_target_or_host),target)
     include $(BUILD_EXECUTABLE)
     ART_TARGET_EXECUTABLES := $(ART_TARGET_EXECUTABLES) $(TARGET_OUT_EXECUTABLES)/$$(LOCAL_MODULE)
   else # host
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index acaa0f8..332e505 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -133,6 +133,7 @@
   ifeq ($$(art_target_or_host),target)
     LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS) $(ART_TARGET_DEBUG_CFLAGS)
+    LOCAL_CFLAGS_x86 := $(ART_TARGET_CFLAGS_x86)
     LOCAL_SHARED_LIBRARIES += libdl libicuuc libicui18n libnativehelper libz libcutils
     LOCAL_STATIC_LIBRARIES += libgtest
     LOCAL_MODULE_PATH := $(ART_NATIVETEST_OUT)
diff --git a/build/Android.libarttest.mk b/build/Android.libarttest.mk
index 65b78c9..d807a9c 100644
--- a/build/Android.libarttest.mk
+++ b/build/Android.libarttest.mk
@@ -48,9 +48,11 @@
   ifeq ($$(art_target_or_host),target)
     LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS := $(ART_TARGET_CFLAGS) $(ART_TARGET_DEBUG_CFLAGS)
+    LOCAL_CFLAGS_x86 := $(ART_TARGET_CFLAGS_x86)
     LOCAL_SHARED_LIBRARIES += libdl libcutils
     LOCAL_STATIC_LIBRARIES := libgtest
     LOCAL_MODULE_PATH := $(ART_TEST_OUT)
+    LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
     include $(BUILD_SHARED_LIBRARY)
   else # host
     LOCAL_CLANG := $(ART_HOST_CLANG)
diff --git a/compiler/Android.mk b/compiler/Android.mk
index c6662c2..c51087c 100644
--- a/compiler/Android.mk
+++ b/compiler/Android.mk
@@ -155,7 +155,7 @@
 
   LOCAL_SRC_FILES := $$(LIBART_COMPILER_SRC_FILES)
 
-  GENERATED_SRC_DIR := $$(call intermediates-dir-for,$$(LOCAL_MODULE_CLASS),$$(LOCAL_MODULE),$$(LOCAL_IS_HOST_MODULE),)
+  GENERATED_SRC_DIR := $$(call local-generated-sources-dir)
   ENUM_OPERATOR_OUT_CC_FILES := $$(patsubst %.h,%_operator_out.cc,$$(LIBART_COMPILER_ENUM_OPERATOR_OUT_HEADER_FILES))
   ENUM_OPERATOR_OUT_GEN := $$(addprefix $$(GENERATED_SRC_DIR)/,$$(ENUM_OPERATOR_OUT_CC_FILES))
 
@@ -198,27 +198,13 @@
   ifeq ($(ART_USE_PORTABLE_COMPILER),true)
     LOCAL_CFLAGS += -DART_USE_PORTABLE_COMPILER=1
     ifeq ($$(art_target_or_host),target)
-      ifeq ($(TARGET_ARCH),arm)
-        LOCAL_STATIC_LIBRARIES += libmcldARMInfo libmcldARMTarget
-      else # TARGET_ARCH != arm
-      ifeq ($(TARGET_ARCH),x86)
-        LOCAL_STATIC_LIBRARIES += libmcldX86Info libmcldX86Target
-      else # TARGET_ARCH != x86
-      ifeq ($(TARGET_ARCH),x86_64)
-        LOCAL_STATIC_LIBRARIES += libmcldX86Info libmcldX86Target
-      else # TARGET_ARCH != x86_64
-      ifeq ($(TARGET_ARCH),mips)
-        LOCAL_STATIC_LIBRARIES += libmcldMipsInfo libmcldMipsTarget
-      else # TARGET_ARCH != mips
-      ifeq ($(TARGET_ARCH),aarch64)
-         $$(info TODOAArch64: $$(LOCAL_PATH)/Android.mk Add AArch64 specific MCLinker libraries)
-      else # TARGET_ARCH != aarch64
-        $$(error unsupported TARGET_ARCH=$(TARGET_ARCH))
-      endif # TARGET_ARCH != aarch64
-      endif # TARGET_ARCH != mips
-      endif # TARGET_ARCH != x86_64
-      endif # TARGET_ARCH != x86
-      endif # TARGET_ARCH != arm
+      LOCAL_STATIC_LIBRARIES_arm += libmcldARMInfo libmcldARMTarget
+      LOCAL_STATIC_LIBRARIES_x86 += libmcldX86Info libmcldX86Target
+      LOCAL_STATIC_LIBRARIES_x86_64 += libmcldX86Info libmcldX86Target
+      LOCAL_STATIC_LIBRARIES_mips += libmcldMipsInfo libmcldMipsTarget
+      ifeq ($(TARGET_ARCH),arm64)
+         $$(info TODOAArch64: $$(LOCAL_PATH)/Android.mk Add Arm64 specific MCLinker libraries)
+      endif # TARGET_ARCH != arm64
     else # host
       LOCAL_STATIC_LIBRARIES += libmcldARMInfo libmcldARMTarget
       LOCAL_STATIC_LIBRARIES += libmcldX86Info libmcldX86Target
@@ -284,6 +270,9 @@
 ifeq ($(ART_BUILD_TARGET),true)
 # TODO: Move to external/compiler_rt
 $(eval $(call copy-one-file, $(call intermediates-dir-for,STATIC_LIBRARIES,libcompiler_rt,,)/libcompiler_rt.a, $(TARGET_OUT_SHARED_LIBRARIES)/libcompiler_rt.a))
+ifdef TARGET_2ND_ARCH
+$(eval $(call copy-one-file, $(call intermediates-dir-for,STATIC_LIBRARIES,libcompiler_rt,,,t)/libcompiler_rt.a, $(2ND_TARGET_OUT_SHARED_LIBRARIES)/libcompiler_rt.a))
+endif
 
 $(DEX2OAT): $(TARGET_OUT_SHARED_LIBRARIES)/libcompiler_rt.a
 
diff --git a/disassembler/Android.mk b/disassembler/Android.mk
index f8001a4..1ce7b13 100644
--- a/disassembler/Android.mk
+++ b/disassembler/Android.mk
@@ -59,8 +59,6 @@
 
   LOCAL_SRC_FILES := $$(LIBART_DISASSEMBLER_SRC_FILES)
 
-  GENERATED_SRC_DIR := $$(call intermediates-dir-for,$$(LOCAL_MODULE_CLASS),$$(LOCAL_MODULE),$$(LOCAL_IS_HOST_MODULE),)
-
   ifeq ($$(art_target_or_host),target)
     LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
diff --git a/runtime/Android.mk b/runtime/Android.mk
index 223ae7c..73c75fb 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -184,6 +184,8 @@
 	entrypoints/quick/quick_throw_entrypoints.cc \
 	entrypoints/quick/quick_trampoline_entrypoints.cc
 
+LIBART_LDFLAGS := -Wl,--no-fatal-warnings
+
 LIBART_TARGET_SRC_FILES := \
 	$(LIBART_COMMON_SRC_FILES) \
 	base/logging_android.cc \
@@ -192,9 +194,7 @@
 	runtime_android.cc \
 	thread_android.cc
 
-LIBART_LDFLAGS :=
-ifeq ($(TARGET_ARCH),arm)
-LIBART_TARGET_SRC_FILES += \
+LIBART_TARGET_SRC_FILES_arm := \
 	arch/arm/context_arm.cc.arm \
 	arch/arm/entrypoints_init_arm.cc \
 	arch/arm/jni_entrypoints_arm.S \
@@ -202,19 +202,16 @@
 	arch/arm/quick_entrypoints_arm.S \
 	arch/arm/arm_sdiv.S \
 	arch/arm/thread_arm.cc
-else # TARGET_ARCH != arm
-ifeq ($(TARGET_ARCH),x86)
-LIBART_TARGET_SRC_FILES += \
+
+LIBART_TARGET_SRC_FILES_x86 := \
 	arch/x86/context_x86.cc \
 	arch/x86/entrypoints_init_x86.cc \
 	arch/x86/jni_entrypoints_x86.S \
 	arch/x86/portable_entrypoints_x86.S \
 	arch/x86/quick_entrypoints_x86.S \
 	arch/x86/thread_x86.cc
-LIBART_LDFLAGS += -Wl,--no-fatal-warnings
-else # TARGET_ARCH != x86
-ifeq ($(TARGET_ARCH),x86_64)
-LIBART_TARGET_SRC_FILES += \
+
+LIBART_TARGET_SRC_FILES_x86_64 := \
 	arch/x86_64/context_x86_64.cc \
 	arch/x86_64/entrypoints_init_x86_64.cc \
 	arch/x86_64/jni_entrypoints_x86_64.S \
@@ -222,31 +219,27 @@
 	arch/x86_64/quick_entrypoints_x86_64.S \
 	arch/x86_64/thread_x86_64.cc \
 	monitor_pool.cc
-LIBART_LDFLAGS += -Wl,--no-fatal-warnings
-else # TARGET_ARCH != x86_64
-ifeq ($(TARGET_ARCH),mips)
-LIBART_TARGET_SRC_FILES += \
+
+
+LIBART_TARGET_SRC_FILES_mips := \
 	arch/mips/context_mips.cc \
 	arch/mips/entrypoints_init_mips.cc \
 	arch/mips/jni_entrypoints_mips.S \
 	arch/mips/portable_entrypoints_mips.S \
 	arch/mips/quick_entrypoints_mips.S \
 	arch/mips/thread_mips.cc
-else # TARGET_ARCH != mips
+
 ifeq ($(TARGET_ARCH),arm64)
 $(info TODOArm64: $(LOCAL_PATH)/Android.mk Add Arm64 specific runtime files)
 else
 ifeq ($(TARGET_ARCH),mips64)
 $(info TODOMips64: $(LOCAL_PATH)/Android.mk Add mips64 specific runtime files)
-else
-$(error unsupported TARGET_ARCH=$(TARGET_ARCH))
 endif # TARGET_ARCH != mips64
 endif # TARGET_ARCH != arm64
-endif # TARGET_ARCH != mips
-endif # TARGET_ARCH != x86_64
-endif # TARGET_ARCH != x86
-endif # TARGET_ARCH != arm
 
+ifeq (,$(filter $(TARGET_ARCH),$(ART_SUPPORTED_ARCH)))
+$(warning unsupported TARGET_ARCH=$(TARGET_ARCH))
+endif
 
 LIBART_HOST_SRC_FILES := \
 	$(LIBART_COMMON_SRC_FILES) \
@@ -337,12 +330,14 @@
 
   ifeq ($$(art_target_or_host),target)
     LOCAL_SRC_FILES := $(LIBART_TARGET_SRC_FILES)
+    $(foreach arch,$(ART_SUPPORTED_ARCH),
+      LOCAL_SRC_FILES_$(arch) := $$(LIBART_TARGET_SRC_FILES_$(arch))))
   else # host
     LOCAL_SRC_FILES := $(LIBART_HOST_SRC_FILES)
     LOCAL_IS_HOST_MODULE := true
   endif
 
-  GENERATED_SRC_DIR := $$(call intermediates-dir-for,$$(LOCAL_MODULE_CLASS),$$(LOCAL_MODULE),$$(LOCAL_IS_HOST_MODULE),)
+  GENERATED_SRC_DIR := $$(call local-generated-sources-dir)
   ENUM_OPERATOR_OUT_CC_FILES := $$(patsubst %.h,%_operator_out.cc,$$(LIBART_ENUM_OPERATOR_OUT_HEADER_FILES))
   ENUM_OPERATOR_OUT_GEN := $$(addprefix $$(GENERATED_SRC_DIR)/,$$(ENUM_OPERATOR_OUT_CC_FILES))
 
@@ -355,6 +350,9 @@
 
   LOCAL_CFLAGS := $(LIBART_CFLAGS)
   LOCAL_LDFLAGS := $(LIBART_LDFLAGS)
+  $(foreach arch,$(ART_SUPPORTED_ARCH),
+    LOCAL_LDFLAGS_$(arch) := $$(LIBART_TARGET_LDFLAGS_$(arch))))
+
   ifeq ($$(art_target_or_host),target)
     LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
@@ -393,6 +391,11 @@
   include $(LLVM_GEN_INTRINSICS_MK)
   LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk
   LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
+
+  ifeq ($$(art_target_or_host),target)
+    LOCAL_MODULE_TARGET_ARCH := $(ART_SUPPORTED_ARCH)
+  endif
+
   ifeq ($$(art_target_or_host),target)
     include $(LLVM_DEVICE_BUILD_MK)
     include $(BUILD_SHARED_LIBRARY)