summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorYing Wang <wangying@android.com>2014-01-09 18:52:06 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-01-09 18:52:06 +0000
commitaed499879210c7432c1c5b3869f383b27b17dafc (patch)
treeb100995cac9e2279395619d168eacd34d64960c5 /core
parent8530e25ff666987c7c968c2a323a8b1e7867bcca (diff)
parente6f65438a45f0e1b519fb3cd2799f44ca87911a7 (diff)
downloadbuild-aed499879210c7432c1c5b3869f383b27b17dafc.zip
build-aed499879210c7432c1c5b3869f383b27b17dafc.tar.gz
build-aed499879210c7432c1c5b3869f383b27b17dafc.tar.bz2
Merge "Allow clang to build host binaries."
Diffstat (limited to 'core')
-rw-r--r--core/binary.mk46
-rw-r--r--core/definitions.mk14
-rw-r--r--core/executable.mk4
-rw-r--r--core/llvm_config.mk274
-rw-r--r--core/llvm_config_define_clang_flags.mk76
-rw-r--r--core/shared_library.mk4
6 files changed, 296 insertions, 122 deletions
diff --git a/core/binary.mk b/core/binary.mk
index 8685060..cfa9923 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -118,9 +118,6 @@ endif
my_compiler_dependencies :=
ifeq ($(strip $(LOCAL_CLANG)),true)
- LOCAL_CFLAGS += $(CLANG_CONFIG_EXTRA_CFLAGS)
- LOCAL_ASFLAGS += $(CLANG_CONFIG_EXTRA_ASFLAGS)
- LOCAL_LDFLAGS += $(CLANG_CONFIG_EXTRA_LDFLAGS)
my_compiler_dependencies := $(CLANG) $(CLANG_CXX)
endif
@@ -162,16 +159,40 @@ my_target_c_includes := $(TARGET_C_INCLUDES)
endif # LOCAL_SDK_VERSION
ifeq ($(LOCAL_CLANG),true)
-my_target_global_cflags := $(TARGET_GLOBAL_CLANG_FLAGS)
+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_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
else
my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS)
+my_target_global_cppflags := $(TARGET_GLOBAL_CPPFLAGS)
+my_target_global_ldflags := $(TARGET_GLOBAL_LDFLAGS)
endif # LOCAL_CLANG
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
-$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(TARGET_GLOBAL_CPPFLAGS)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
+
+ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
+ifeq ($(LOCAL_CLANG),true)
+my_host_global_cflags := $(CLANG_HOST_GLOBAL_CFLAGS)
+my_host_global_cppflags := $(CLANG_HOST_GLOBAL_CPPFLAGS)
+my_host_global_ldflags := $(CLANG_HOST_GLOBAL_LDFLAGS)
+my_host_c_includes := $(HOST_C_INCLUDES) $(CLANG_CONFIG_EXTRA_HOST_C_INCLUDES)
+else
+my_host_global_cflags := $(HOST_GLOBAL_CFLAGS)
+my_host_global_cppflags := $(HOST_GLOBAL_CPPFLAGS)
+my_host_global_ldflags := $(HOST_GLOBAL_LDFLAGS)
+my_host_c_includes := $(HOST_C_INCLUDES)
+endif # LOCAL_CLANG
+
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_C_INCLUDES := $(my_host_c_includes)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
+endif # LOCAL_IS_HOST_MODULE
###########################################################
## Define PRIVATE_ variables used by multiple module types
@@ -257,12 +278,11 @@ normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
# Read the values from something like TARGET_arm_CFLAGS or
# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
# actually used (although they are usually empty).
-ifeq ($(strip $(LOCAL_CLANG)),true)
-arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CLANG_CFLAGS)
-normal_objects_cflags := $($(my_prefix)$(normal_objects_mode)_CLANG_CFLAGS)
-else
arm_objects_cflags := $($(my_prefix)$(arm_objects_mode)_CFLAGS)
normal_objects_cflags := $($(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))
endif
else
@@ -751,6 +771,14 @@ endif
###########################################################
# Rule-specific variable definitions
###########################################################
+
+ifeq ($(LOCAL_CLANG),true)
+LOCAL_CFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_CFLAGS))
+LOCAL_CPPFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_CPPFLAGS))
+LOCAL_ASFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_ASFLAGS))
+LOCAL_LDFLAGS := $(call convert-to-$(my_host)clang-flags,$(LOCAL_LDFLAGS))
+endif
+
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(LOCAL_CONLYFLAGS)
diff --git a/core/definitions.mk b/core/definitions.mk
index 4e1a25d..fe54bca 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1032,11 +1032,11 @@ $(hide) $(PRIVATE_CXX) \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
$(filter-out $(PRIVATE_C_INCLUDES), \
$(HOST_PROJECT_INCLUDES) \
- $(HOST_C_INCLUDES)))) \
+ $(PRIVATE_HOST_C_INCLUDES)))) \
-c \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
- $(HOST_GLOBAL_CFLAGS) \
- $(HOST_GLOBAL_CPPFLAGS) \
+ $(PRIVATE_HOST_GLOBAL_CFLAGS) \
+ $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
) \
$(PRIVATE_CFLAGS) \
$(PRIVATE_CPPFLAGS) \
@@ -1060,10 +1060,10 @@ $(hide) $(PRIVATE_CC) \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
$(filter-out $(PRIVATE_C_INCLUDES), \
$(HOST_PROJECT_INCLUDES) \
- $(HOST_C_INCLUDES)))) \
+ $(PRIVATE_HOST_C_INCLUDES)))) \
-c \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
- $(HOST_GLOBAL_CFLAGS) \
+ $(PRIVATE_HOST_GLOBAL_CFLAGS) \
) \
$(1) \
-MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
@@ -1207,7 +1207,7 @@ $(hide) $(PRIVATE_CXX) \
$(PRIVATE_LDFLAGS) \
$(HOST_GLOBAL_LD_DIRS) \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
- $(HOST_GLOBAL_LDFLAGS) \
+ $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
) \
$(PRIVATE_ALL_OBJECTS) \
-Wl,--whole-archive \
@@ -1367,7 +1367,7 @@ $(hide) $(PRIVATE_CXX) \
$(HOST_GLOBAL_LD_DIRS) \
$(PRIVATE_LDFLAGS) \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
- $(HOST_GLOBAL_LDFLAGS) \
+ $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
-fPIE -pie \
) \
-o $@ \
diff --git a/core/executable.mk b/core/executable.mk
index 52bf0cb..d6b342e 100644
--- a/core/executable.mk
+++ b/core/executable.mk
@@ -39,7 +39,11 @@ include $(BUILD_SYSTEM)/dynamic_binary.mk
# Define PRIVATE_ variables from global vars
my_target_global_ld_dirs := $(TARGET_GLOBAL_LD_DIRS)
+ifeq ($(LOCAL_CLANG),true)
+my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
+else
my_target_global_ldflags := $(TARGET_GLOBAL_LDFLAGS)
+endif
my_target_fdo_lib := $(TARGET_FDO_LIB)
my_target_libgcc := $(TARGET_LIBGCC)
my_target_crtbegin_dynamic_o := $(TARGET_CRTBEGIN_DYNAMIC_O)
diff --git a/core/llvm_config.mk b/core/llvm_config.mk
index 19fe790..89cd208 100644
--- a/core/llvm_config.mk
+++ b/core/llvm_config.mk
@@ -3,127 +3,136 @@ 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)
-define do-clang-flags-subst
- TARGET_GLOBAL_CLANG_FLAGS := $(subst $(1),$(2),$(TARGET_GLOBAL_CLANG_FLAGS))
- HOST_GLOBAL_CLANG_FLAGS := $(subst $(1),$(2),$(HOST_GLOBAL_CLANG_FLAGS))
-endef
-
-define clang-flags-subst
- $(eval $(call do-clang-flags-subst,$(1),$(2)))
-endef
-
+# 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 \
+ -D__compiler_offsetof=__builtin_offsetof
CLANG_CONFIG_UNKNOWN_CFLAGS := \
- -funswitch-loops
+ -funswitch-loops \
+ -Wno-psabi \
+ -Wno-unused-but-set-variable \
+ -Wno-unused-but-set-parameter
-ifeq ($(TARGET_ARCH),arm)
- RS_TRIPLE := armv7-none-linux-gnueabi
- CLANG_CONFIG_EXTRA_ASFLAGS += \
- -target arm-linux-androideabi \
- -nostdlibinc \
- -B$(TARGET_TOOLCHAIN_ROOT)/arm-linux-androideabi/bin
- CLANG_CONFIG_EXTRA_CFLAGS += \
- $(CLANG_CONFIG_EXTRA_ASFLAGS) \
- -mllvm -arm-enable-ehabi
- CLANG_CONFIG_EXTRA_LDFLAGS += \
- -target arm-linux-androideabi \
- -B$(TARGET_TOOLCHAIN_ROOT)/arm-linux-androideabi/bin
- 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
-endif
-ifeq ($(TARGET_ARCH),mips)
- RS_TRIPLE := mipsel-unknown-linux
- CLANG_CONFIG_EXTRA_ASFLAGS += \
- -target mipsel-linux-androideabi \
- -nostdlibinc \
- -B$(TARGET_TOOLCHAIN_ROOT)/mipsel-linux-android/bin
- CLANG_CONFIG_EXTRA_CFLAGS += $(CLANG_CONFIG_EXTRA_ASFLAGS)
- CLANG_CONFIG_EXTRA_LDFLAGS += \
- -target mipsel-linux-androideabi \
- -B$(TARGET_TOOLCHAIN_ROOT)/mipsel-linux-android/bin
- 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
+# 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 ($(TARGET_ARCH),x86)
- RS_TRIPLE := i686-unknown-linux
- CLANG_CONFIG_EXTRA_ASFLAGS += \
- -target i686-linux-android \
- -msse3 \
- -nostdlibinc \
- -B$(TARGET_TOOLCHAIN_ROOT)/x86_64-linux-android/bin
- CLANG_CONFIG_EXTRA_CFLAGS += $(CLANG_CONFIG_EXTRA_ASFLAGS)
- CLANG_CONFIG_EXTRA_LDFLAGS += \
- -target i686-linux-android \
- -B$(TARGET_TOOLCHAIN_ROOT)/x86_64-linux-android/bin
- CLANG_CONFIG_UNKNOWN_CFLAGS += \
- -finline-limit=300 \
- -fno-inline-functions-called-once \
- -mfpmath=sse \
- -mbionic
+ifeq ($(HOST_OS),darwin)
+CLANG_CONFIG_x86_HOST_TRIPLE := i686-apple-darwin
endif
-ifeq ($(TARGET_ARCH),x86_64)
- RS_TRIPLE := x86_64-unknown-linux
- CLANG_CONFIG_EXTRA_ASFLAGS += \
- -target x86_64-linux-android \
- -nostdlibinc \
- -B$(TARGET_TOOLCHAIN_ROOT)/x86_64-linux-android/bin
- CLANG_CONFIG_EXTRA_CFLAGS += $(CLANG_CONFIG_EXTRA_ASFLAGS)
- CLANG_CONFIG_EXTRA_LDFLAGS += \
- -target x86_64-linux-android \
- -B$(TARGET_TOOLCHAIN_ROOT)/x86_64-linux-android/bin
- CLANG_CONFIG_UNKNOWN_CFLAGS += \
- -finline-limit=300 \
- -fno-inline-functions-called-once \
- -mfpmath=sse \
- -mbionic
+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
-CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES := external/clang/lib/include $(TARGET_OUT_HEADERS)/clang
-
-# remove unknown flags to define CLANG_FLAGS
-TARGET_GLOBAL_CLANG_FLAGS += $(filter-out $(CLANG_CONFIG_UNKNOWN_CFLAGS),$(TARGET_GLOBAL_CFLAGS))
-HOST_GLOBAL_CLANG_FLAGS += $(filter-out $(CLANG_CONFIG_UNKNOWN_CFLAGS),$(HOST_GLOBAL_CFLAGS))
+include $(BUILD_SYSTEM)/llvm_config_define_clang_flags.mk
-TARGET_arm_CLANG_CFLAGS += $(filter-out $(CLANG_CONFIG_UNKNOWN_CFLAGS),$(TARGET_arm_CFLAGS))
-TARGET_thumb_CLANG_CFLAGS += $(filter-out $(CLANG_CONFIG_UNKNOWN_CFLAGS),$(TARGET_thumb_CFLAGS))
+# 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
-# llvm does not yet support -march=armv5e nor -march=armv5te, fall back to armv5 or armv5t
-$(call clang-flags-subst,-march=armv5te,-march=armv5t)
-$(call clang-flags-subst,-march=armv5e,-march=armv5)
+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
-# clang does not support -Wno-psabi, -Wno-unused-but-set-variable, and
-# -Wno-unused-but-set-parameter
-$(call clang-flags-subst,-Wno-psabi,)
-$(call clang-flags-subst,-Wno-unused-but-set-variable,)
-$(call clang-flags-subst,-Wno-unused-but-set-parameter,)
+include $(BUILD_SYSTEM)/llvm_config_define_clang_flags.mk
-# clang does not support -mcpu=cortex-a15 yet - fall back to armv7-a for now
-$(call clang-flags-subst,-mcpu=cortex-a15,-march=armv7-a)
+# 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
@@ -132,3 +141,56 @@ 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
diff --git a/core/llvm_config_define_clang_flags.mk b/core/llvm_config_define_clang_flags.mk
new file mode 100644
index 0000000..b7b57e2
--- /dev/null
+++ b/core/llvm_config_define_clang_flags.mk
@@ -0,0 +1,76 @@
+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 :=
diff --git a/core/shared_library.mk b/core/shared_library.mk
index 10012df..5619274 100644
--- a/core/shared_library.mk
+++ b/core/shared_library.mk
@@ -52,7 +52,11 @@ include $(BUILD_SYSTEM)/dynamic_binary.mk
# Define PRIVATE_ variables from global vars
my_target_global_ld_dirs := $(TARGET_GLOBAL_LD_DIRS)
+ifeq ($(LOCAL_CLANG),true)
+my_target_global_ldflags := $(CLANG_TARGET_GLOBAL_LDFLAGS)
+else
my_target_global_ldflags := $(TARGET_GLOBAL_LDFLAGS)
+endif
my_target_fdo_lib := $(TARGET_FDO_LIB)
my_target_libgcc := $(TARGET_LIBGCC)
my_target_crtbegin_so_o := $(TARGET_CRTBEGIN_SO_O)