config.mk revision dbd43849fb9aeb13ed85bccad453c6388b7f37ed
1## Clang configurations.
2
3LLVM_PREBUILTS_VERSION ?= 3.8
4LLVM_PREBUILTS_BASE ?= prebuilts/clang/host
5LLVM_PREBUILTS_PATH := $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/bin
6LLVM_RTLIB_PATH := $(LLVM_PREBUILTS_PATH)/../lib/clang/$(LLVM_PREBUILTS_VERSION)/lib/linux/
7
8CLANG := $(LLVM_PREBUILTS_PATH)/clang$(BUILD_EXECUTABLE_SUFFIX)
9CLANG_CXX := $(LLVM_PREBUILTS_PATH)/clang++$(BUILD_EXECUTABLE_SUFFIX)
10LLVM_AS := $(LLVM_PREBUILTS_PATH)/llvm-as$(BUILD_EXECUTABLE_SUFFIX)
11LLVM_LINK := $(LLVM_PREBUILTS_PATH)/llvm-link$(BUILD_EXECUTABLE_SUFFIX)
12
13CLANG_TBLGEN := $(BUILD_OUT_EXECUTABLES)/clang-tblgen$(BUILD_EXECUTABLE_SUFFIX)
14LLVM_TBLGEN := $(BUILD_OUT_EXECUTABLES)/llvm-tblgen$(BUILD_EXECUTABLE_SUFFIX)
15
16# Clang flags for all host or target rules
17CLANG_CONFIG_EXTRA_ASFLAGS :=
18CLANG_CONFIG_EXTRA_CFLAGS :=
19CLANG_CONFIG_EXTRA_CONLYFLAGS := -std=gnu99
20CLANG_CONFIG_EXTRA_CPPFLAGS :=
21CLANG_CONFIG_EXTRA_LDFLAGS :=
22
23CLANG_CONFIG_EXTRA_CFLAGS += \
24  -D__compiler_offsetof=__builtin_offsetof
25
26# Help catch common 32/64-bit errors.
27CLANG_CONFIG_EXTRA_CFLAGS += \
28  -Werror=int-conversion
29
30# Disable overly aggressive warning for macros defined with a leading underscore
31# This used to happen in AndroidConfig.h, which was included everywhere.
32# TODO: can we remove this now?
33CLANG_CONFIG_EXTRA_CFLAGS += \
34  -Wno-reserved-id-macro
35
36# Disable overly aggressive warning for format strings.
37# Bug: 20148343
38CLANG_CONFIG_EXTRA_CFLAGS += \
39  -Wno-format-pedantic
40
41# Workaround for ccache with clang.
42# See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
43CLANG_CONFIG_EXTRA_CFLAGS += \
44  -Wno-unused-command-line-argument
45
46# Disable -Winconsistent-missing-override until we can clean up the existing
47# codebase for it.
48CLANG_CONFIG_EXTRA_CPPFLAGS += \
49  -Wno-inconsistent-missing-override
50
51# Force clang to always output color diagnostics.  Ninja will strip the ANSI
52# color codes if it is not running in a terminal.
53ifdef BUILDING_WITH_NINJA
54CLANG_CONFIG_EXTRA_CFLAGS += \
55  -fcolor-diagnostics
56endif
57
58CLANG_CONFIG_UNKNOWN_CFLAGS := \
59  -finline-functions \
60  -finline-limit=64 \
61  -fno-canonical-system-headers \
62  -Wno-clobbered \
63  -fno-devirtualize \
64  -fno-tree-sra \
65  -fprefetch-loop-arrays \
66  -funswitch-loops \
67  -Werror=unused-but-set-parameter \
68  -Werror=unused-but-set-variable \
69  -Wmaybe-uninitialized \
70  -Wno-error=clobbered \
71  -Wno-error=maybe-uninitialized \
72  -Wno-error=unused-but-set-parameter \
73  -Wno-error=unused-but-set-variable \
74  -Wno-free-nonheap-object \
75  -Wno-literal-suffix \
76  -Wno-maybe-uninitialized \
77  -Wno-old-style-declaration \
78  -Wno-psabi \
79  -Wno-unused-but-set-parameter \
80  -Wno-unused-but-set-variable \
81  -Wno-unused-local-typedefs \
82  -Wunused-but-set-parameter \
83  -Wunused-but-set-variable \
84  -fdiagnostics-color \
85  -fdebug-prefix-map=/proc/self/cwd=
86
87# Clang flags for all host rules
88CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
89CLANG_CONFIG_HOST_EXTRA_CFLAGS :=
90CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=
91CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=
92
93# Clang flags for all host cross rules
94CLANG_CONFIG_HOST_CROSS_EXTRA_ASFLAGS :=
95CLANG_CONFIG_HOST_CROSS_EXTRA_CFLAGS :=
96CLANG_CONFIG_HOST_CROSS_EXTRA_CPPFLAGS :=
97CLANG_CONFIG_HOST_CROSS_EXTRA_LDFLAGS :=
98
99# Clang flags for all target rules
100CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=
101CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc
102CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc
103CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=
104
105CLANG_DEFAULT_UB_CHECKS := \
106  bool \
107  integer-divide-by-zero \
108  return \
109  returns-nonnull-attribute \
110  shift-exponent \
111  unreachable \
112  vla-bound \
113
114# TODO(danalbert): The following checks currently have compiler performance
115# issues.
116# CLANG_DEFAULT_UB_CHECKS += alignment
117# CLANG_DEFAULT_UB_CHECKS += bounds
118# CLANG_DEFAULT_UB_CHECKS += enum
119# CLANG_DEFAULT_UB_CHECKS += float-cast-overflow
120# CLANG_DEFAULT_UB_CHECKS += float-divide-by-zero
121# CLANG_DEFAULT_UB_CHECKS += nonnull-attribute
122# CLANG_DEFAULT_UB_CHECKS += null
123# CLANG_DEFAULT_UB_CHECKS += shift-base
124# CLANG_DEFAULT_UB_CHECKS += signed-integer-overflow
125
126# TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on.
127# https://llvm.org/PR19302
128# http://reviews.llvm.org/D6974
129# CLANG_DEFAULT_UB_CHECKS += object-size
130
131# HOST config
132clang_2nd_arch_prefix :=
133include $(BUILD_SYSTEM)/clang/HOST_$(HOST_ARCH).mk
134
135# HOST_2ND_ARCH config
136ifdef HOST_2ND_ARCH
137clang_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX)
138include $(BUILD_SYSTEM)/clang/HOST_$(HOST_2ND_ARCH).mk
139endif
140
141ifdef HOST_CROSS_OS
142include $(BUILD_SYSTEM)/clang/HOST_CROSS_$(HOST_CROSS_OS).mk
143endif
144
145# TARGET config
146clang_2nd_arch_prefix :=
147include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_ARCH).mk
148
149# TARGET_2ND_ARCH config
150ifdef TARGET_2ND_ARCH
151clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
152include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk
153endif
154
155ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fno-omit-frame-pointer
156ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit
157
158ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES :=
159ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan
160
161# This allows us to use the superset of functionality that compiler-rt
162# provides to Clang (for supporting features like -ftrapv).
163COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras
164
165ifeq ($(HOST_PREFER_32_BIT),true)
166# We don't have 32-bit prebuilt libLLVM/libclang, so force to build them from source.
167FORCE_BUILD_LLVM_COMPONENTS := true
168endif
169