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