blob: ccfd0f2fee9d8175b2ecb5ccc22b2b246f41a64d [file] [log] [blame]
Ying Wangba8b3772014-03-10 18:23:08 -07001## Clang configurations.
2
Dan Albert8b1d1772015-11-13 23:06:07 -08003LLVM_PREBUILTS_PATH := $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/bin
Stephen Hinescdb52b52016-02-04 11:43:41 -08004LLVM_RTLIB_PATH := $(LLVM_PREBUILTS_PATH)/../lib64/clang/$(LLVM_RELEASE_VERSION)/lib/linux/
Ying Wang1f982832014-02-06 18:08:44 -08005
Stephen Hinesb34b7ae2014-09-30 02:37:20 -07006CLANG_TBLGEN := $(BUILD_OUT_EXECUTABLES)/clang-tblgen$(BUILD_EXECUTABLE_SUFFIX)
7LLVM_TBLGEN := $(BUILD_OUT_EXECUTABLES)/llvm-tblgen$(BUILD_EXECUTABLE_SUFFIX)
Stephen Hines7bc754b2014-02-19 09:03:00 -08008
Stephen Hines96d2a8c2016-01-21 23:50:53 -08009# RenderScript-specific tools
10# These are tied to the version of LLVM directly in external/, so they might
11# trail the host prebuilts being used for the rest of the build process.
Stephen Hines348b81a2016-04-29 16:50:48 -070012RS_LLVM_PREBUILTS_VERSION := clang-2812033
Stephen Hines96d2a8c2016-01-21 23:50:53 -080013RS_LLVM_PREBUILTS_BASE := prebuilts/clang/host
14RS_LLVM_PREBUILTS_PATH := $(RS_LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(RS_LLVM_PREBUILTS_VERSION)/bin
Stephen Hines49b69532016-01-22 15:11:34 -080015RS_CLANG := $(RS_LLVM_PREBUILTS_PATH)/clang$(BUILD_EXECUTABLE_SUFFIX)
Stephen Hines96d2a8c2016-01-21 23:50:53 -080016RS_LLVM_AS := $(RS_LLVM_PREBUILTS_PATH)/llvm-as$(BUILD_EXECUTABLE_SUFFIX)
17RS_LLVM_LINK := $(RS_LLVM_PREBUILTS_PATH)/llvm-link$(BUILD_EXECUTABLE_SUFFIX)
18
Ying Wang1f982832014-02-06 18:08:44 -080019# Clang flags for all host or target rules
20CLANG_CONFIG_EXTRA_ASFLAGS :=
21CLANG_CONFIG_EXTRA_CFLAGS :=
Stephen Hines433f1612014-11-26 00:57:34 -080022CLANG_CONFIG_EXTRA_CONLYFLAGS := -std=gnu99
Ying Wang1f982832014-02-06 18:08:44 -080023CLANG_CONFIG_EXTRA_CPPFLAGS :=
24CLANG_CONFIG_EXTRA_LDFLAGS :=
25
Brian Carlstrom338d1e72014-06-17 14:36:05 -070026CLANG_CONFIG_EXTRA_CFLAGS += \
Ying Wang1f982832014-02-06 18:08:44 -080027 -D__compiler_offsetof=__builtin_offsetof
28
Brian Carlstrom338d1e72014-06-17 14:36:05 -070029# Help catch common 32/64-bit errors.
30CLANG_CONFIG_EXTRA_CFLAGS += \
31 -Werror=int-conversion
32
Stephen Hinesf6800212015-03-17 14:42:11 -070033# Disable overly aggressive warning for macros defined with a leading underscore
Elliott Hughes43146112015-08-28 10:31:28 -070034# This used to happen in AndroidConfig.h, which was included everywhere.
35# TODO: can we remove this now?
Stephen Hinesf6800212015-03-17 14:42:11 -070036CLANG_CONFIG_EXTRA_CFLAGS += \
37 -Wno-reserved-id-macro
38
Stephen Hinesb992bfc2015-04-10 09:06:12 -070039# Disable overly aggressive warning for format strings.
40# Bug: 20148343
41CLANG_CONFIG_EXTRA_CFLAGS += \
42 -Wno-format-pedantic
43
Ying Wang24e03362014-10-17 15:07:24 -070044# Workaround for ccache with clang.
45# See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
46CLANG_CONFIG_EXTRA_CFLAGS += \
Stephen Hinesc141b852014-11-03 23:39:49 -080047 -Wno-unused-command-line-argument
Ying Wang24e03362014-10-17 15:07:24 -070048
Stephen Hines433f1612014-11-26 00:57:34 -080049# Disable -Winconsistent-missing-override until we can clean up the existing
50# codebase for it.
51CLANG_CONFIG_EXTRA_CPPFLAGS += \
52 -Wno-inconsistent-missing-override
53
Colin Cross63e3b022015-09-24 22:14:25 -070054# Force clang to always output color diagnostics. Ninja will strip the ANSI
55# color codes if it is not running in a terminal.
Colin Crossdbd43842016-01-04 14:31:25 -080056ifdef BUILDING_WITH_NINJA
Colin Cross63e3b022015-09-24 22:14:25 -070057CLANG_CONFIG_EXTRA_CFLAGS += \
58 -fcolor-diagnostics
Colin Crossdbd43842016-01-04 14:31:25 -080059endif
Colin Cross63e3b022015-09-24 22:14:25 -070060
Ying Wang1f982832014-02-06 18:08:44 -080061CLANG_CONFIG_UNKNOWN_CFLAGS := \
Stephen Hines433f1612014-11-26 00:57:34 -080062 -finline-functions \
Bernhard Rosenkraenzerd6e11822014-05-12 16:05:14 +020063 -finline-limit=64 \
Chih-Hung Hsiehfb482c62014-08-26 16:37:00 -070064 -fno-canonical-system-headers \
Chih-Hung Hsieh0ba68ba2015-05-01 14:53:59 -070065 -Wno-clobbered \
66 -fno-devirtualize \
Chih-Hung Hsiehfb482c62014-08-26 16:37:00 -070067 -fno-tree-sra \
Chih-Hung Hsieh78df8322015-03-05 16:02:04 -080068 -fprefetch-loop-arrays \
Chih-Hung Hsiehfb482c62014-08-26 16:37:00 -070069 -funswitch-loops \
Chih-Hung Hsieh7e44d7f2015-03-19 15:17:06 -070070 -Werror=unused-but-set-parameter \
Elliott Hughes3101e612015-04-03 07:43:46 -070071 -Werror=unused-but-set-variable \
Chih-Hung Hsiehfb482c62014-08-26 16:37:00 -070072 -Wmaybe-uninitialized \
Chih-Hung Hsieh0ba68ba2015-05-01 14:53:59 -070073 -Wno-error=clobbered \
Chih-Hung Hsiehfb482c62014-08-26 16:37:00 -070074 -Wno-error=maybe-uninitialized \
Chih-Hung Hsieh7e44d7f2015-03-19 15:17:06 -070075 -Wno-error=unused-but-set-parameter \
Chih-Hung Hsieh9205bc12015-04-02 14:42:20 -070076 -Wno-error=unused-but-set-variable \
Chih-Hung Hsieh22b6c5c2014-10-23 16:39:09 -070077 -Wno-free-nonheap-object \
Chih-Hung Hsiehfb482c62014-08-26 16:37:00 -070078 -Wno-literal-suffix \
79 -Wno-maybe-uninitialized \
80 -Wno-old-style-declaration \
Ying Wang1f982832014-02-06 18:08:44 -080081 -Wno-psabi \
Andrew Hsieh48f239c2014-05-09 14:13:13 +080082 -Wno-unused-but-set-parameter \
Chih-Hung Hsieh9205bc12015-04-02 14:42:20 -070083 -Wno-unused-but-set-variable \
84 -Wno-unused-local-typedefs \
85 -Wunused-but-set-parameter \
Colin Cross63e3b022015-09-24 22:14:25 -070086 -Wunused-but-set-variable \
Dan Willemsen6a66a882015-10-14 16:44:53 -070087 -fdiagnostics-color \
Dan Willemsen02268f02016-05-19 14:39:25 -070088 -mthumb-interwork \
89 -fgcse-after-reload \
90 -frerun-cse-after-loop \
91 -frename-registers \
92 -fno-align-jumps \
93 -fno-builtin-sin \
94 -fno-caller-saves \
95 -fno-early-inlining \
96 -fno-move-loop-invariants \
97 -fno-partial-inlining \
98 -fno-strict-volatile-bitfields \
99 -fno-tree-copy-prop \
100 -fno-tree-loop-optimize \
101 -msynci \
102 -mno-synci \
103 -mno-fused-madd \
104 -finline-limit=300 \
105 -fno-inline-functions-called-once \
106 -mfpmath=sse \
107 -mbionic
108
109define convert-to-clang-flags
110$(strip $(filter-out $(CLANG_CONFIG_UNKNOWN_CFLAGS),$(1)))
111endef
Ying Wang1f982832014-02-06 18:08:44 -0800112
113# Clang flags for all host rules
Tim Murrayd318ba62014-04-21 14:00:31 -0700114CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
115CLANG_CONFIG_HOST_EXTRA_CFLAGS :=
116CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=
117CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=
Ying Wang1f982832014-02-06 18:08:44 -0800118
Dan Willemsen057aaea2015-08-14 12:59:50 -0700119# Clang flags for all host cross rules
120CLANG_CONFIG_HOST_CROSS_EXTRA_ASFLAGS :=
121CLANG_CONFIG_HOST_CROSS_EXTRA_CFLAGS :=
122CLANG_CONFIG_HOST_CROSS_EXTRA_CPPFLAGS :=
123CLANG_CONFIG_HOST_CROSS_EXTRA_LDFLAGS :=
124
Ying Wang1f982832014-02-06 18:08:44 -0800125# Clang flags for all target rules
126CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=
127CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc
Dan Willemsen7701eaa2016-05-17 00:41:25 -0700128CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS :=
Ying Wang1f982832014-02-06 18:08:44 -0800129CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=
130
Dan Albertb5b2ffe2015-04-16 18:07:07 -0700131CLANG_DEFAULT_UB_CHECKS := \
132 bool \
133 integer-divide-by-zero \
134 return \
135 returns-nonnull-attribute \
136 shift-exponent \
137 unreachable \
138 vla-bound \
139
140# TODO(danalbert): The following checks currently have compiler performance
141# issues.
142# CLANG_DEFAULT_UB_CHECKS += alignment
143# CLANG_DEFAULT_UB_CHECKS += bounds
144# CLANG_DEFAULT_UB_CHECKS += enum
145# CLANG_DEFAULT_UB_CHECKS += float-cast-overflow
146# CLANG_DEFAULT_UB_CHECKS += float-divide-by-zero
147# CLANG_DEFAULT_UB_CHECKS += nonnull-attribute
148# CLANG_DEFAULT_UB_CHECKS += null
149# CLANG_DEFAULT_UB_CHECKS += shift-base
150# CLANG_DEFAULT_UB_CHECKS += signed-integer-overflow
151
152# TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on.
153# https://llvm.org/PR19302
154# http://reviews.llvm.org/D6974
155# CLANG_DEFAULT_UB_CHECKS += object-size
156
Ying Wang1f982832014-02-06 18:08:44 -0800157# HOST config
Ying Wang6feb6d52014-04-17 10:03:35 -0700158clang_2nd_arch_prefix :=
Ying Wang1f982832014-02-06 18:08:44 -0800159include $(BUILD_SYSTEM)/clang/HOST_$(HOST_ARCH).mk
Ying Wang6feb6d52014-04-17 10:03:35 -0700160
161# HOST_2ND_ARCH config
162ifdef HOST_2ND_ARCH
163clang_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX)
164include $(BUILD_SYSTEM)/clang/HOST_$(HOST_2ND_ARCH).mk
Tim Murray02cefc92014-03-20 13:48:35 -0700165endif
Ying Wang1f982832014-02-06 18:08:44 -0800166
Dan Willemsen9ecbf832016-02-05 16:20:19 -0800167ifdef HOST_CROSS_ARCH
168clang_2nd_arch_prefix :=
169include $(BUILD_SYSTEM)/clang/HOST_CROSS_$(HOST_CROSS_ARCH).mk
170ifdef HOST_CROSS_2ND_ARCH
171clang_2nd_arch_prefix := $(HOST_CROSS_2ND_ARCH_VAR_PREFIX)
172include $(BUILD_SYSTEM)/clang/HOST_CROSS_$(HOST_CROSS_2ND_ARCH).mk
173endif
Dan Willemsen057aaea2015-08-14 12:59:50 -0700174endif
175
Ying Wang1f982832014-02-06 18:08:44 -0800176# TARGET config
177clang_2nd_arch_prefix :=
178include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_ARCH).mk
179
180# TARGET_2ND_ARCH config
181ifdef TARGET_2ND_ARCH
182clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
183include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk
184endif
185
Dan Albert08cca282014-12-11 18:56:26 -0800186ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fno-omit-frame-pointer
Ying Wang1f982832014-02-06 18:08:44 -0800187ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit
Dan Albert2daceaa2014-10-20 11:37:18 -0700188
Dan Albertb58fb4a2014-11-14 17:15:00 -0800189ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan
Ying Wang1f982832014-02-06 18:08:44 -0800190
191# This allows us to use the superset of functionality that compiler-rt
192# provides to Clang (for supporting features like -ftrapv).
193COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras
Ying Wange5d4e742014-11-06 14:11:33 -0800194
195ifeq ($(HOST_PREFER_32_BIT),true)
196# We don't have 32-bit prebuilt libLLVM/libclang, so force to build them from source.
197FORCE_BUILD_LLVM_COMPONENTS := true
198endif
Chih-Hung Hsieh460171a2016-04-21 15:37:24 -0700199
200include $(BUILD_SYSTEM)/clang/tidy.mk