Commits

Anonymous committed 737a51d Merge

Merge "Refactor llvm_config.mk and support the 2nd arch"

  • Participants
  • Parent commits 5e9a203, 1f98283

Comments (0)

Files changed (21)

   my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
 endif
 
-ifeq ($(strip $(WITHOUT_CLANG)),true)
+ifeq ($(strip $($(LOCAL_2ND_ARCH_VAR_PREFIX)WITHOUT_CLANG)),true)
   LOCAL_CLANG :=
 endif
 
 endif # LOCAL_SDK_VERSION
 
 ifeq ($(LOCAL_CLANG),true)
-my_target_global_cflags := $(CLANG_TARGET_GLOBAL_CFLAGS)
-my_target_global_cppflags := $(CLANG_TARGET_GLOBAL_CPPFLAGS)
-my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
+my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CFLAGS)
+my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CPPFLAGS)
+my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_LDFLAGS)
 my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
 else
 my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_CFLAGS)
 arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS)
 normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
 ifeq ($(strip $(LOCAL_CLANG)),true)
-arm_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(arm_objects_cflags))
-normal_objects_cflags := $(call convert-to-$(my_host)clang-flags,$(normal_objects_cflags))
+arm_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(arm_objects_cflags))
+normal_objects_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(normal_objects_cflags))
 endif
 
 else
 ###########################################################
 
 ifeq ($(LOCAL_CLANG),true)
-my_cflags := $(call convert-to-$(my_host)clang-flags,$(my_cflags))
-my_cppflags := $(call convert-to-$(my_host)clang-flags,$(my_cppflags))
-my_asflags := $(call convert-to-$(my_host)clang-flags,$(my_asflags))
-my_ldflags := $(call convert-to-$(my_host)clang-flags,$(my_ldflags))
+my_cflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cflags))
+my_cppflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_cppflags))
+my_asflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_asflags))
+my_ldflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_ldflags))
 endif
 
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)

core/clang/HOST_x86.mk

+
+include $(BUILD_SYSTEM)/clang/x86.mk
+
+ifeq ($(HOST_OS),linux)
+CLANG_CONFIG_x86_HOST_TRIPLE := i686-linux-gnu
+endif
+ifeq ($(HOST_OS),darwin)
+CLANG_CONFIG_x86_HOST_TRIPLE := i686-apple-darwin
+endif
+ifeq ($(HOST_OS),windows)
+CLANG_CONFIG_x86_HOST_TRIPLE := i686-pc-mingw32
+endif
+
+CLANG_CONFIG_x86_HOST_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_x86_HOST_TRIPLE) \
+
+CLANG_CONFIG_x86_HOST_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_HOST_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_x86_HOST_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_x86_HOST_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_x86_HOST_TRIPLE) \
+
+
+define convert-to-host-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-x86-flags,\
+  $(filter-out $(CLANG_CONFIG_x86_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+CLANG_HOST_GLOBAL_CFLAGS := \
+  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_x86_HOST_EXTRA_CFLAGS)
+
+CLANG_HOST_GLOBAL_CPPFLAGS := \
+  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_x86_HOST_EXTRA_CPPFLAGS)
+
+CLANG_HOST_GLOBAL_LDFLAGS := \
+  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_x86_HOST_EXTRA_LDFLAGS)

core/clang/HOST_x86_64.mk

+
+include $(BUILD_SYSTEM)/clang/x86_64.mk
+
+ifeq ($(HOST_OS),linux)
+CLANG_CONFIG_x86_64_HOST_TRIPLE := x86_64-linux-gnu
+endif
+ifeq ($(HOST_OS),darwin)
+CLANG_CONFIG_x86_64_HOST_TRIPLE := x86_64-apple-darwin
+endif
+ifeq ($(HOST_OS),windows)
+CLANG_CONFIG_x86_64_HOST_TRIPLE := x86_64-pc-mingw64
+endif
+
+CLANG_CONFIG_x86_64_HOST_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_x86_64_HOST_TRIPLE) \
+
+CLANG_CONFIG_x86_64_HOST_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_64_HOST_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_x86_64_HOST_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_x86_64_HOST_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_HOST_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_x86_64_HOST_TRIPLE) \
+
+
+define convert-to-host-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-x86_64-flags,\
+  $(filter-out $(CLANG_CONFIG_x86_64_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+CLANG_HOST_GLOBAL_CFLAGS := \
+  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_x86_64_HOST_EXTRA_CFLAGS)
+
+CLANG_HOST_GLOBAL_CPPFLAGS := \
+  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_x86_64_HOST_EXTRA_CPPFLAGS)
+
+CLANG_HOST_GLOBAL_LDFLAGS := \
+  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_x86_64_HOST_EXTRA_LDFLAGS)

core/clang/TARGET_arm.mk

+
+include $(BUILD_SYSTEM)/clang/arm.mk
+
+CLANG_CONFIG_arm_TARGET_TRIPLE := arm-linux-androideabi
+CLANG_CONFIG_arm_TARGET_TOOLCHAIN_PREFIX := \
+  $(TARGET_TOOLCHAIN_ROOT)/$(CLANG_CONFIG_arm_TARGET_TRIPLE)/bin
+
+CLANG_CONFIG_arm_TARGET_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_arm_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_arm_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_arm_TARGET_TOOLCHAIN_PREFIX)
+
+CLANG_CONFIG_arm_TARGET_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_arm_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_arm_TARGET_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_arm_TARGET_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_arm_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_arm_TARGET_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_arm_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_arm_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_arm_TARGET_TOOLCHAIN_PREFIX)
+
+
+define $(clang_2nd_arch_prefix)convert-to-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-arm-flags,\
+  $(filter-out $(CLANG_CONFIG_arm_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_CFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_arm_TARGET_EXTRA_CFLAGS)
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_CPPFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_arm_TARGET_EXTRA_CPPFLAGS)
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_LDFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_arm_TARGET_EXTRA_LDFLAGS)
+
+$(clang_2nd_arch_prefix)RS_TRIPLE := armv7-none-linux-gnueabi

core/clang/TARGET_arm64.mk

+
+include $(BUILD_SYSTEM)/clang/arm64.mk
+
+CLANG_CONFIG_arm64_TARGET_TRIPLE := aarch64-linux-androideabi
+CLANG_CONFIG_arm64_TARGET_TOOLCHAIN_PREFIX := \
+  $(TARGET_TOOLCHAIN_ROOT)/$(CLANG_CONFIG_arm64_TARGET_TRIPLE)/bin
+
+CLANG_CONFIG_arm64_TARGET_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_arm64_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_arm64_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_arm64_TARGET_TOOLCHAIN_PREFIX)
+
+CLANG_CONFIG_arm64_TARGET_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_arm64_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_arm64_TARGET_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_arm64_TARGET_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_arm64_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_arm64_TARGET_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_arm64_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_arm64_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_arm64_TARGET_TOOLCHAIN_PREFIX)
+
+
+define convert-to-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-arm64-flags,\
+  $(filter-out $(CLANG_CONFIG_arm64_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+CLANG_TARGET_GLOBAL_CFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_arm64_TARGET_EXTRA_CFLAGS)
+
+CLANG_TARGET_GLOBAL_CPPFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_arm64_TARGET_EXTRA_CPPFLAGS)
+
+CLANG_TARGET_GLOBAL_LDFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_arm64_TARGET_EXTRA_LDFLAGS)
+
+$(warning Incorrect arm64 RS_TRIPLE, fix me!)
+RS_TRIPLE := armv7-none-linux-gnueabi

core/clang/TARGET_mips.mk

+
+include $(BUILD_SYSTEM)/clang/mips.mk
+
+CLANG_CONFIG_mips_TARGET_TRIPLE := mipsel-linux-android
+CLANG_CONFIG_mips_TARGET_TOOLCHAIN_PREFIX := \
+  $(TARGET_TOOLCHAIN_ROOT)/$(CLANG_CONFIG_mips_TARGET_TRIPLE)/bin
+
+CLANG_CONFIG_mips_TARGET_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_mips_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_mips_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_mips_TARGET_TOOLCHAIN_PREFIX)
+
+CLANG_CONFIG_mips_TARGET_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_mips_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_mips_TARGET_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_mips_TARGET_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_mips_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_mips_TARGET_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_mips_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_mips_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_mips_TARGET_TOOLCHAIN_PREFIX)
+
+
+define $(clang_2nd_arch_prefix)convert-to-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-mips-flags,\
+  $(filter-out $(CLANG_CONFIG_mips_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_CFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_mips_TARGET_EXTRA_CFLAGS)
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_CPPFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$(clang_2nd_arch_prefix)$(TARGET_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_mips_TARGET_EXTRA_CPPFLAGS)
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_LDFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_mips_TARGET_EXTRA_LDFLAGS)
+
+$(clang_2nd_arch_prefix)RS_TRIPLE := mipsel-unknown-linux

core/clang/TARGET_mips64.mk

+
+include $(BUILD_SYSTEM)/clang/mips64.mk
+
+CLANG_CONFIG_mips64_TARGET_TRIPLE := mips64el-linux-android
+CLANG_CONFIG_mips64_TARGET_TOOLCHAIN_PREFIX := \
+  $(TARGET_TOOLCHAIN_ROOT)/$(CLANG_CONFIG_mips64_TARGET_TRIPLE)/bin
+
+CLANG_CONFIG_mips64_TARGET_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_mips64_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_mips64_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_mips64_TARGET_TOOLCHAIN_PREFIX)
+
+CLANG_CONFIG_mips64_TARGET_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_mips64_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_mips64_TARGET_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_mips64_TARGET_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_mips64_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_mips64_TARGET_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_mips64_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_mips64_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_mips64_TARGET_TOOLCHAIN_PREFIX)
+
+
+define convert-to-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-mips64-flags,\
+  $(filter-out $(CLANG_CONFIG_mips64_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+CLANG_TARGET_GLOBAL_CFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_mips64_TARGET_EXTRA_CFLAGS)
+
+CLANG_TARGET_GLOBAL_CPPFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_mips64_TARGET_EXTRA_CPPFLAGS)
+
+CLANG_TARGET_GLOBAL_LDFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_mips64_TARGET_EXTRA_LDFLAGS)
+
+RS_TRIPLE := mips64el-unknown-linux

core/clang/TARGET_x86.mk

+
+include $(BUILD_SYSTEM)/clang/x86.mk
+
+CLANG_CONFIG_x86_TARGET_TRIPLE := i686-linux-android
+CLANG_CONFIG_x86_TARGET_TOOLCHAIN_PREFIX := \
+  $(TARGET_TOOLCHAIN_ROOT)/x86_64-linux-android/bin
+
+CLANG_CONFIG_x86_TARGET_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_x86_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_x86_TARGET_TOOLCHAIN_PREFIX)
+
+CLANG_CONFIG_x86_TARGET_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_TARGET_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_x86_TARGET_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_x86_TARGET_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_x86_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_x86_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_x86_TARGET_TOOLCHAIN_PREFIX)
+
+
+define $(clang_2nd_arch_prefix)convert-to-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-x86-flags,\
+  $(filter-out $(CLANG_CONFIG_x86_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_CFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_x86_TARGET_EXTRA_CFLAGS)
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_CPPFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_x86_TARGET_EXTRA_CPPFLAGS)
+
+$(clang_2nd_arch_prefix)CLANG_TARGET_GLOBAL_LDFLAGS := \
+  $(call $(clang_2nd_arch_prefix)convert-to-clang-flags,$($(clang_2nd_arch_prefix)TARGET_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_x86_TARGET_EXTRA_LDFLAGS)
+
+$(clang_2nd_arch_prefix)RS_TRIPLE := i686-unknown-linux

core/clang/TARGET_x86_64.mk

+
+include $(BUILD_SYSTEM)/clang/x86_64.mk
+
+CLANG_CONFIG_x86_64_TARGET_TRIPLE := x86_64-linux-android
+CLANG_CONFIG_x86_64_TARGET_TOOLCHAIN_PREFIX := \
+  $(TARGET_TOOLCHAIN_ROOT)/$(CLANG_CONFIG_x86_64_TARGET_TRIPLE)/bin
+
+CLANG_CONFIG_x86_64_TARGET_EXTRA_ASFLAGS := \
+  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_ASFLAGS) \
+  -target $(CLANG_CONFIG_x86_64_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_x86_64_TARGET_TOOLCHAIN_PREFIX)
+
+CLANG_CONFIG_x86_64_TARGET_EXTRA_CFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_CFLAGS) \
+  $(CLANG_CONFIG_x86_64_TARGET_EXTRA_ASFLAGS)
+
+CLANG_CONFIG_x86_64_TARGET_EXTRA_CPPFLAGS := \
+  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_CPPFLAGS) \
+
+CLANG_CONFIG_x86_64_TARGET_EXTRA_LDFLAGS := \
+  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
+  $(CLANG_CONFIG_x86_64_EXTRA_LDFLAGS) \
+  -target $(CLANG_CONFIG_x86_64_TARGET_TRIPLE) \
+  -B$(CLANG_CONFIG_x86_64_TARGET_TOOLCHAIN_PREFIX)
+
+
+define convert-to-clang-flags
+  $(strip \
+  $(call subst-clang-incompatible-x86_64-flags,\
+  $(filter-out $(CLANG_CONFIG_x86_64_UNKNOWN_CFLAGS),\
+  $(1))))
+endef
+
+CLANG_TARGET_GLOBAL_CFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_CFLAGS)) \
+  $(CLANG_CONFIG_x86_64_TARGET_EXTRA_CFLAGS)
+
+CLANG_TARGET_GLOBAL_CPPFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_CPPFLAGS)) \
+  $(CLANG_CONFIG_x86_64_TARGET_EXTRA_CPPFLAGS)
+
+CLANG_TARGET_GLOBAL_LDFLAGS := \
+  $(call convert-to-clang-flags,$(TARGET_GLOBAL_LDFLAGS)) \
+  $(CLANG_CONFIG_x86_64_TARGET_EXTRA_LDFLAGS)
+
+RS_TRIPLE := x86_64-unknown-linux

core/clang/arm.mk

+# Clang flags for arm arch, target or host.
+
+CLANG_CONFIG_arm_EXTRA_ASFLAGS :=
+
+CLANG_CONFIG_arm_EXTRA_CFLAGS := \
+  -mllvm -arm-enable-ehabi
+
+CLANG_CONFIG_arm_EXTRA_LDFLAGS :=
+
+# Include common unknown flags
+CLANG_CONFIG_arm_UNKNOWN_CFLAGS := \
+  $(CLANG_CONFIG_UNKNOWN_CFLAGS) \
+  -mthumb-interwork \
+  -fgcse-after-reload \
+  -frerun-cse-after-loop \
+  -frename-registers \
+  -fno-builtin-sin \
+  -fno-strict-volatile-bitfields \
+  -fno-align-jumps \
+  -Wa,--noexecstack
+
+define subst-clang-incompatible-arm-flags
+  $(subst -march=armv5te,-march=armv5t,\
+  $(subst -march=armv5e,-march=armv5,\
+  $(subst -mcpu=cortex-a15,-march=armv7-a,\
+  $(1))))
+endef

core/clang/arm64.mk

+# Clang flags for arm64 arch, target or host.
+
+$(warning Untested arm64 clang flags, fix me!)
+
+CLANG_CONFIG_arm64_EXTRA_ASFLAGS :=
+
+CLANG_CONFIG_arm64_EXTRA_CFLAGS := \
+  -mllvm -arm-enable-ehabi
+
+CLANG_CONFIG_arm64_EXTRA_LDFLAGS :=
+
+# Include common unknown flags
+CLANG_CONFIG_arm64_UNKNOWN_CFLAGS := \
+  $(CLANG_CONFIG_UNKNOWN_CFLAGS) \
+  -mthumb-interwork \
+  -fgcse-after-reload \
+  -frerun-cse-after-loop \
+  -frename-registers \
+  -fno-builtin-sin \
+  -fno-strict-volatile-bitfields \
+  -fno-align-jumps \
+  -Wa,--noexecstack
+
+define subst-clang-incompatible-arm64-flags
+  $(subst -march=armv5te,-march=armv5t,\
+  $(subst -march=armv5e,-march=armv5,\
+  $(subst -mcpu=cortex-a15,-march=armv7-a,\
+  $(1))))
+endef

core/clang/config.mk

+
+CLANG := $(HOST_OUT_EXECUTABLES)/clang$(HOST_EXECUTABLE_SUFFIX)
+CLANG_CXX := $(HOST_OUT_EXECUTABLES)/clang++$(HOST_EXECUTABLE_SUFFIX)
+LLVM_AS := $(HOST_OUT_EXECUTABLES)/llvm-as$(HOST_EXECUTABLE_SUFFIX)
+LLVM_LINK := $(HOST_OUT_EXECUTABLES)/llvm-link$(HOST_EXECUTABLE_SUFFIX)
+
+# Clang flags for all host or target rules
+CLANG_CONFIG_EXTRA_ASFLAGS :=
+CLANG_CONFIG_EXTRA_CFLAGS :=
+CLANG_CONFIG_EXTRA_CPPFLAGS :=
+CLANG_CONFIG_EXTRA_LDFLAGS :=
+
+CLANG_CONFIG_EXTRA_CFLAGS := \
+  -D__compiler_offsetof=__builtin_offsetof
+
+CLANG_CONFIG_UNKNOWN_CFLAGS := \
+  -funswitch-loops \
+  -Wno-psabi \
+  -Wno-unused-but-set-variable \
+  -Wno-unused-but-set-parameter
+
+# Clang flags for all host rules
+CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
+CLANG_CONFIG_HOST_EXTRA_CFLAGS :=
+CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=
+CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=
+
+# Clang flags for all target rules
+CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=
+CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc
+CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc
+CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=
+
+# HOST config
+include $(BUILD_SYSTEM)/clang/HOST_$(HOST_ARCH).mk
+
+# TARGET config
+clang_2nd_arch_prefix :=
+include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_ARCH).mk
+
+# TARGET_2ND_ARCH config
+ifdef TARGET_2ND_ARCH
+clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
+include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk
+endif
+
+
+# Clang compiler-specific libc headers
+CLANG_CONFIG_EXTRA_HOST_C_INCLUDES := external/clang/lib/include
+CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES := external/clang/lib/include $(TARGET_OUT_HEADERS)/clang
+
+# Address sanitizer clang config
+ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fsanitize=address
+ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit
+ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl libasan_preload
+ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan
+
+# This allows us to use the superset of functionality that compiler-rt
+# provides to Clang (for supporting features like -ftrapv).
+COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras

core/clang/mips.mk

+# Clang flags for mips arch, target or host.
+
+CLANG_CONFIG_mips_EXTRA_ASFLAGS :=
+CLANG_CONFIG_mips_EXTRA_CFLAGS :=
+CLANG_CONFIG_mips_EXTRA_LDFLAGS :=
+
+# Include common unknown flags
+CLANG_CONFIG_mips_UNKNOWN_CFLAGS := \
+  $(CLANG_CONFIG_UNKNOWN_CFLAGS) \
+  -EL \
+  -mips32 \
+  -mips32r2 \
+  -mhard-float \
+  -fno-strict-volatile-bitfields \
+  -fgcse-after-reload \
+  -frerun-cse-after-loop \
+  -frename-registers \
+  -march=mips32r2 \
+  -mtune=mips32r2 \
+  -march=mips32 \
+  -mtune=mips32 \
+  -msynci \
+  -mno-fused-madd
+
+# We don't have any mips flags to substitute yet.
+define subst-clang-incompatible-mips-flags
+  $(1)
+endef

core/clang/mips64.mk

+# Clang flags for mips64 arch, target or host.
+
+$(warning Untested mips64 clang flags, fix me!)
+
+CLANG_CONFIG_mips64_EXTRA_ASFLAGS :=
+CLANG_CONFIG_mips64_EXTRA_CFLAGS :=
+CLANG_CONFIG_mips64_EXTRA_LDFLAGS :=
+
+# Include common unknown flags
+CLANG_CONFIG_mips64_UNKNOWN_CFLAGS := \
+  $(CLANG_CONFIG_UNKNOWN_CFLAGS) \
+  -EL \
+  -mips32 \
+  -mips32r2 \
+  -mhard-float \
+  -fno-strict-volatile-bitfields \
+  -fgcse-after-reload \
+  -frerun-cse-after-loop \
+  -frename-registers \
+  -march=mips32r2 \
+  -mtune=mips32r2 \
+  -march=mips32 \
+  -mtune=mips32 \
+  -msynci \
+  -mno-fused-madd
+
+# We don't have any mips64 flags to substitute yet.
+define subst-clang-incompatible-mips64-flags
+  $(1)
+endef

core/clang/x86.mk

+# Clang flags for x86 arch, target or host.
+
+CLANG_CONFIG_x86_EXTRA_ASFLAGS := \
+  -msse3
+CLANG_CONFIG_x86_EXTRA_CFLAGS :=
+CLANG_CONFIG_x86_EXTRA_LDFLAGS :=
+
+# Include common unknown flags
+CLANG_CONFIG_x86_UNKNOWN_CFLAGS := \
+  $(CLANG_CONFIG_UNKNOWN_CFLAGS) \
+  -finline-limit=300 \
+  -fno-inline-functions-called-once \
+  -mfpmath=sse \
+  -mbionic
+
+# We don't have any x86 flags to substitute yet.
+define subst-clang-incompatible-x86-flags
+  $(1)
+endef

core/clang/x86_64.mk

+# Clang flags for x86_64 arch, target or host.
+
+CLANG_CONFIG_x86_64_EXTRA_ASFLAGS :=
+CLANG_CONFIG_x86_64_EXTRA_CFLAGS :=
+CLANG_CONFIG_x86_64_EXTRA_LDFLAGS :=
+
+# Include common unknown flags
+CLANG_CONFIG_x86_64_UNKNOWN_CFLAGS := \
+  $(CLANG_CONFIG_UNKNOWN_CFLAGS) \
+  -finline-limit=300 \
+  -fno-inline-functions-called-once \
+  -mfpmath=sse \
+  -mbionic
+
+# We don't have any x86_64 flags to substitute yet.
+define subst-clang-incompatible-x86_64-flags
+  $(1)
+endef
   TARGET_DEFAULT_JAVA_LIBRARIES := core core-junit ext framework framework2
 endif
 
-# define llvm tools and global flags
-include $(BUILD_SYSTEM)/llvm_config.mk
+# define clang/llvm tools and global flags
+include $(BUILD_SYSTEM)/clang/config.mk
 
 # ###############################################################
 # Collect a list of the SDK versions that we could compile against

core/executable_internal.mk

 # Define PRIVATE_ variables from global vars
 my_target_global_ld_dirs := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS)
 ifeq ($(LOCAL_CLANG),true)
-my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
+my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_LDFLAGS)
 else
 my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
 endif

core/llvm_config.mk

-CLANG := $(HOST_OUT_EXECUTABLES)/clang$(HOST_EXECUTABLE_SUFFIX)
-CLANG_CXX := $(HOST_OUT_EXECUTABLES)/clang++$(HOST_EXECUTABLE_SUFFIX)
-LLVM_AS := $(HOST_OUT_EXECUTABLES)/llvm-as$(HOST_EXECUTABLE_SUFFIX)
-LLVM_LINK := $(HOST_OUT_EXECUTABLES)/llvm-link$(HOST_EXECUTABLE_SUFFIX)
-
-# Clang flags for all host or target rules
-CLANG_CONFIG_EXTRA_ASFLAGS :=
-CLANG_CONFIG_EXTRA_CPPFLAGS :=
-CLANG_CONFIG_EXTRA_LDFLAGS :=
-
-CLANG_CONFIG_EXTRA_CFLAGS := \
-  -D__compiler_offsetof=__builtin_offsetof
-
-CLANG_CONFIG_UNKNOWN_CFLAGS := \
-  -funswitch-loops \
-  -Wno-psabi \
-  -Wno-unused-but-set-variable \
-  -Wno-unused-but-set-parameter
-
-# Clang flags for all host rules
-CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
-CLANG_CONFIG_HOST_EXTRA_CFLAGS :=
-CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=
-CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=
-
-# Clang flags for all target rules
-CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=
-CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc
-CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc
-CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=
-
-# ARM
-llvm_arch := arm
-CLANG_CONFIG_arm_EXTRA_ASFLAGS :=
-CLANG_CONFIG_arm_EXTRA_CFLAGS := \
-  -mllvm -arm-enable-ehabi
-CLANG_CONFIG_arm_EXTRA_LDFLAGS :=
-CLANG_CONFIG_arm_UNKNOWN_CFLAGS := \
-  -mthumb-interwork \
-  -fgcse-after-reload \
-  -frerun-cse-after-loop \
-  -frename-registers \
-  -fno-builtin-sin \
-  -fno-strict-volatile-bitfields \
-  -fno-align-jumps \
-  -Wa,--noexecstack
-
-CLANG_CONFIG_arm_HOST_TRIPLE :=
-CLANG_CONFIG_arm_TARGET_TRIPLE := arm-linux-androideabi
-
-include $(BUILD_SYSTEM)/llvm_config_define_clang_flags.mk
-
-# MIPS
-llvm_arch := mips
-CLANG_CONFIG_mips_EXTRA_ASFLAGS :=
-CLANG_CONFIG_mips_EXTRA_CFLAGS :=
-CLANG_CONFIG_mips_EXTRA_LDFLAGS :=
-CLANG_CONFIG_mips_UNKNOWN_CFLAGS := \
-  -EL \
-  -mips32 \
-  -mips32r2 \
-  -mhard-float \
-  -fno-strict-volatile-bitfields \
-  -fgcse-after-reload \
-  -frerun-cse-after-loop \
-  -frename-registers \
-  -march=mips32r2 \
-  -mtune=mips32r2 \
-  -march=mips32 \
-  -mtune=mips32 \
-  -msynci \
-  -mno-fused-madd
-
-CLANG_CONFIG_mips_HOST_TRIPLE :=
-CLANG_CONFIG_mips_TARGET_TRIPLE := mipsel-linux-android
-
-include $(BUILD_SYSTEM)/llvm_config_define_clang_flags.mk
-
-# X86
-llvm_arch := x86
-CLANG_CONFIG_x86_EXTRA_ASFLAGS := \
-  -msse3
-CLANG_CONFIG_x86_EXTRA_CFLAGS :=
-CLANG_CONFIG_x86_EXTRA_LDFLAGS :=
-CLANG_CONFIG_x86_UNKNOWN_CFLAGS := \
-  -finline-limit=300 \
-  -fno-inline-functions-called-once \
-  -mfpmath=sse \
-  -mbionic
-
-ifeq ($(HOST_OS),linux)
-CLANG_CONFIG_x86_HOST_TRIPLE := i686-linux-gnu
-endif
-ifeq ($(HOST_OS),darwin)
-CLANG_CONFIG_x86_HOST_TRIPLE := i686-apple-darwin
-endif
-ifeq ($(HOST_OS),windows)
-CLANG_CONFIG_x86_HOST_TRIPLE := i686-pc-mingw32
-endif
-
-CLANG_CONFIG_x86_TARGET_TRIPLE := i686-linux-android
-CLANG_CONFIG_x86_TARGET_TOOLCHAIN_PREFIX := \
-  $(TARGET_TOOLCHAIN_ROOT)/x86_64-linux-android/bin
-
-include $(BUILD_SYSTEM)/llvm_config_define_clang_flags.mk
-
-# X86_64
-llvm_arch := x86_64
-CLANG_CONFIG_x86_64_EXTRA_ASFLAGS :=
-CLANG_CONFIG_x86_64_EXTRA_CFLAGS :=
-CLANG_CONFIG_x86_64_EXTRA_LDFLAGS :=
-CLANG_CONFIG_x86_64_UNKNOWN_CFLAGS := \
-  -finline-limit=300 \
-  -fno-inline-functions-called-once \
-  -mfpmath=sse \
-  -mbionic
-
-ifeq ($(HOST_OS),linux)
-CLANG_CONFIG_x86_64_HOST_TRIPLE := x86_64-linux-gnu
-endif
-ifeq ($(HOST_OS),darwin)
-CLANG_CONFIG_x86_64_HOST_TRIPLE := x86_64-apple-darwin
-endif
-ifeq ($(HOST_OS),windows)
-CLANG_CONFIG_x86_64_HOST_TRIPLE := x86_64-pc-mingw64
-endif
-CLANG_CONFIG_x86_64_TARGET_TRIPLE := x86_64-linux-android
-
-include $(BUILD_SYSTEM)/llvm_config_define_clang_flags.mk
-
-# Clang compiler-specific libc headers
-CLANG_CONFIG_EXTRA_HOST_C_INCLUDES := external/clang/lib/include
-CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES := external/clang/lib/include $(TARGET_OUT_HEADERS)/clang
-
-# Address sanitizer clang config
-ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fsanitize=address
-ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit
-ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl libasan_preload
-ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan
-
-# This allows us to use the superset of functionality that compiler-rt
-# provides to Clang (for supporting features like -ftrapv).
-COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras
-
-# Macros to convert gcc flags to clang flags
-define subst-clang-incompatible-flags
-  $(subst -march=armv5te,-march=armv5t,\
-  $(subst -march=armv5e,-march=armv5,\
-  $(subst -mcpu=cortex-a15,-march=armv7-a,\
-  $(1))))
-endef
-
-define convert-to-host-clang-flags
-  $(strip \
-  $(call subst-clang-incompatible-flags,\
-  $(filter-out $(CLANG_CONFIG_$(HOST_ARCH)_UNKNOWN_CFLAGS),\
-  $(1))))
-endef
-
-define convert-to-clang-flags
-  $(strip \
-  $(call subst-clang-incompatible-flags,\
-  $(filter-out $(CLANG_CONFIG_$(TARGET_ARCH)_UNKNOWN_CFLAGS),\
-  $(1))))
-endef
-
-# Define clang global flags
-define get-clang-host-global-flags
-  $(call convert-to-host-clang-flags,$(HOST_GLOBAL_$(1))) $(CLANG_CONFIG_$(HOST_ARCH)_HOST_EXTRA_$(1))
-endef
-
-define get-clang-global-flags
-  $(call convert-to-clang-flags,$(TARGET_GLOBAL_$(1))) $(CLANG_CONFIG_$(TARGET_ARCH)_TARGET_EXTRA_$(1))
-endef
-
-CLANG_HOST_GLOBAL_CFLAGS := $(call get-clang-host-global-flags,CFLAGS)
-CLANG_HOST_GLOBAL_CPPFLAGS := $(call get-clang-host-global-flags,CPPFLAGS)
-CLANG_HOST_GLOBAL_LDFLAGS := $(call get-clang-host-global-flags,LDFLAGS)
-
-CLANG_TARGET_GLOBAL_CFLAGS := $(call get-clang-global-flags,CFLAGS)
-CLANG_TARGET_GLOBAL_CPPFLAGS := $(call get-clang-global-flags,CPPFLAGS)
-CLANG_TARGET_GLOBAL_LDFLAGS := $(call get-clang-global-flags,LDFLAGS)
-
-# Renderscript clang target triple
-ifeq ($(TARGET_ARCH),arm)
-  RS_TRIPLE := armv7-none-linux-gnueabi
-endif
-ifeq ($(TARGET_ARCH),mips)
-  RS_TRIPLE := mipsel-unknown-linux
-endif
-ifeq ($(TARGET_ARCH),x86)
-  RS_TRIPLE := i686-unknown-linux
-endif
-ifeq ($(TARGET_ARCH),x86_64)
-  RS_TRIPLE := x86_64-unknown-linux
-endif

core/llvm_config_define_clang_flags.mk

-ifeq ($(strip $(llvm_arch)),)
-  $(error "$$(llvm_arch) should be defined.")
-endif
-
-ifeq ($(strip $(CLANG_CONFIG_$(llvm_arch)_TARGET_TRIPLE)),)
-  $(error "$$(CLANG_CONFIG_$(llvm_arch)_TARGET_TRIPLE) should be defined.")
-endif
-
-ifeq ($(strip $(CLANG_CONFIG_$(llvm_arch)_TARGET_TOOLCHAIN_PREFIX)),)
-CLANG_CONFIG_$(llvm_arch)_TARGET_TOOLCHAIN_PREFIX := \
-  $(TARGET_TOOLCHAIN_ROOT)/$(CLANG_CONFIG_$(llvm_arch)_TARGET_TRIPLE)/bin
-endif
-
-# Include common unknown flags
-CLANG_CONFIG_$(llvm_arch)_UNKNOWN_CFLAGS += \
-  $(CLANG_CONFIG_UNKNOWN_CFLAGS)
-
-# Clang extra flags for host
-CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_ASFLAGS := \
-  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
-  $(CLANG_CONFIG_HOST_EXTRA_ASFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_ASFLAGS)
-
-ifneq ($(strip $(CLANG_CONFIG_$(llvm_arch)_HOST_TRIPLE)),)
-CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_ASFLAGS += \
-  -target $(CLANG_CONFIG_$(llvm_arch)_HOST_TRIPLE)
-endif
-
-CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_CFLAGS := \
-  $(CLANG_CONFIG_EXTRA_CFLAGS) \
-  $(CLANG_CONFIG_HOST_EXTRA_CFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_CFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_ASFLAGS)
-
-CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_CPPFLAGS := \
-  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
-  $(CLANG_CONFIG_HOST_EXTRA_CPPFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_CPPFLAGS)
-
-CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_LDFLAGS := \
-  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
-  $(CLANG_CONFIG_HOST_EXTRA_LDFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_LDFLAGS)
-
-ifneq ($(strip $(CLANG_CONFIG_$(llvm_arch)_HOST_TRIPLE)),)
-CLANG_CONFIG_$(llvm_arch)_HOST_EXTRA_LDFLAGS += \
-  -target $(CLANG_CONFIG_$(llvm_arch)_HOST_TRIPLE)
-endif
-
-# Clang extra flags for target
-CLANG_CONFIG_$(llvm_arch)_TARGET_EXTRA_ASFLAGS := \
-  $(CLANG_CONFIG_EXTRA_ASFLAGS) \
-  $(CLANG_CONFIG_TARGET_EXTRA_ASFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_ASFLAGS) \
-  -target $(CLANG_CONFIG_$(llvm_arch)_TARGET_TRIPLE) \
-  -B$(CLANG_CONFIG_$(llvm_arch)_TARGET_TOOLCHAIN_PREFIX)
-
-CLANG_CONFIG_$(llvm_arch)_TARGET_EXTRA_CFLAGS := \
-  $(CLANG_CONFIG_EXTRA_CFLAGS) \
-  $(CLANG_CONFIG_TARGET_EXTRA_CFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_CFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_TARGET_EXTRA_ASFLAGS)
-
-CLANG_CONFIG_$(llvm_arch)_TARGET_EXTRA_CPPFLAGS := \
-  $(CLANG_CONFIG_EXTRA_CPPFLAGS) \
-  $(CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_CPPFLAGS)
-
-CLANG_CONFIG_$(llvm_arch)_TARGET_EXTRA_LDFLAGS := \
-  $(CLANG_CONFIG_EXTRA_LDFLAGS) \
-  $(CLANG_CONFIG_TARGET_EXTRA_LDFLAGS) \
-  $(CLANG_CONFIG_$(llvm_arch)_EXTRA_LDFLAGS) \
-  -target $(CLANG_CONFIG_$(llvm_arch)_TARGET_TRIPLE) \
-  -B$(CLANG_CONFIG_$(llvm_arch)_TARGET_TOOLCHAIN_PREFIX)
-
-llvm_arch :=

core/shared_library_internal.mk

 # Define PRIVATE_ variables from global vars
 my_target_global_ld_dirs := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS)
 ifeq ($(LOCAL_CLANG),true)
-my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
+my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_LDFLAGS)
 else
 my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
 endif