config.mk revision 78df8324818ab2527e243e90ab3bfdb66639c325
1## Clang configurations.
2
3# WITHOUT_CLANG covers both HOST and TARGET
4ifeq ($(WITHOUT_CLANG),true)
5WITHOUT_TARGET_CLANG := true
6WITHOUT_HOST_CLANG := true
7endif
8
9LLVM_PREBUILTS_VERSION := 3.6
10LLVM_PREBUILTS_PATH := prebuilts/clang/$(BUILD_OS)-x86/host/$(LLVM_PREBUILTS_VERSION)/bin
11
12CLANG := $(LLVM_PREBUILTS_PATH)/clang$(BUILD_EXECUTABLE_SUFFIX)
13CLANG_CXX := $(LLVM_PREBUILTS_PATH)/clang++$(BUILD_EXECUTABLE_SUFFIX)
14LLVM_AS := $(LLVM_PREBUILTS_PATH)/llvm-as$(BUILD_EXECUTABLE_SUFFIX)
15LLVM_LINK := $(LLVM_PREBUILTS_PATH)/llvm-link$(BUILD_EXECUTABLE_SUFFIX)
16
17CLANG_TBLGEN := $(BUILD_OUT_EXECUTABLES)/clang-tblgen$(BUILD_EXECUTABLE_SUFFIX)
18LLVM_TBLGEN := $(BUILD_OUT_EXECUTABLES)/llvm-tblgen$(BUILD_EXECUTABLE_SUFFIX)
19
20# The C/C++ compiler can be wrapped by setting the CC/CXX_WRAPPER vars.
21ifdef CC_WRAPPER
22  ifneq ($(CC_WRAPPER),$(firstword $(CLANG)))
23    CLANG := $(CC_WRAPPER) $(CLANG)
24  endif
25endif
26ifdef CXX_WRAPPER
27  ifneq ($(CXX_WRAPPER),$(firstword $(CLANG_CXX)))
28    CLANG_CXX := $(CXX_WRAPPER) $(CLANG_CXX)
29  endif
30endif
31
32# Clang flags for all host or target rules
33CLANG_CONFIG_EXTRA_ASFLAGS :=
34CLANG_CONFIG_EXTRA_CFLAGS :=
35CLANG_CONFIG_EXTRA_CONLYFLAGS := -std=gnu99
36CLANG_CONFIG_EXTRA_CPPFLAGS :=
37CLANG_CONFIG_EXTRA_LDFLAGS :=
38
39CLANG_CONFIG_EXTRA_CFLAGS += \
40  -D__compiler_offsetof=__builtin_offsetof
41
42# Help catch common 32/64-bit errors.
43CLANG_CONFIG_EXTRA_CFLAGS += \
44  -Werror=int-conversion
45
46# Workaround for ccache with clang.
47# See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
48CLANG_CONFIG_EXTRA_CFLAGS += \
49  -Wno-unused-command-line-argument
50
51# Disable -Winconsistent-missing-override until we can clean up the existing
52# codebase for it.
53CLANG_CONFIG_EXTRA_CPPFLAGS += \
54  -Wno-inconsistent-missing-override
55
56CLANG_CONFIG_UNKNOWN_CFLAGS := \
57  -finline-functions \
58  -finline-limit=64 \
59  -fno-canonical-system-headers \
60  -fno-tree-sra \
61  -fprefetch-loop-arrays \
62  -funswitch-loops \
63  -Wmaybe-uninitialized \
64  -Wno-error=maybe-uninitialized \
65  -Wno-free-nonheap-object \
66  -Wno-literal-suffix \
67  -Wno-maybe-uninitialized \
68  -Wno-old-style-declaration \
69  -Wno-psabi \
70  -Wno-unused-but-set-variable \
71  -Wno-unused-but-set-parameter \
72  -Wno-unused-local-typedefs
73
74# Clang flags for all host rules
75CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
76CLANG_CONFIG_HOST_EXTRA_CFLAGS :=
77CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=
78CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=
79
80# Clang flags for all target rules
81CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=
82CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc
83CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc
84CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=
85
86# HOST config
87clang_2nd_arch_prefix :=
88include $(BUILD_SYSTEM)/clang/HOST_$(HOST_ARCH).mk
89
90# HOST_2ND_ARCH config
91ifdef HOST_2ND_ARCH
92clang_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX)
93include $(BUILD_SYSTEM)/clang/HOST_$(HOST_2ND_ARCH).mk
94endif
95
96# TARGET config
97clang_2nd_arch_prefix :=
98include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_ARCH).mk
99
100# TARGET_2ND_ARCH config
101ifdef TARGET_2ND_ARCH
102clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
103include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk
104endif
105
106# Address sanitizer clang config
107ADDRESS_SANITIZER_RUNTIME_LIBRARY := libclang_rt.asan_$(TARGET_ARCH)_android
108ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fsanitize=address -fno-omit-frame-pointer
109ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit
110
111ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl $(ADDRESS_SANITIZER_RUNTIME_LIBRARY)
112ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan
113
114# This allows us to use the superset of functionality that compiler-rt
115# provides to Clang (for supporting features like -ftrapv).
116COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras
117
118ifeq ($(HOST_PREFER_32_BIT),true)
119# We don't have 32-bit prebuilt libLLVM/libclang, so force to build them from source.
120FORCE_BUILD_LLVM_COMPONENTS := true
121endif
122