blob: 8cf8de62b29bce580790bf12ce739ea2b85d6e35 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Cross4d9c2d12016-07-29 12:48:20 -070016
17import (
18 "strings"
19
20 "android/soong/android"
21)
22
Colin Cross4d9c2d12016-07-29 12:48:20 -070023var (
Leo Li8756b372017-05-22 16:11:34 -070024 // Flags used by lots of devices. Putting them in package static variables
25 // will save bytes in build.ninja so they aren't repeated for every file
Colin Cross4d9c2d12016-07-29 12:48:20 -070026 commonGlobalCflags = []string{
27 "-DANDROID",
28 "-fmessage-length=0",
29 "-W",
30 "-Wall",
31 "-Wno-unused",
32 "-Winit-self",
33 "-Wpointer-arith",
34
Colin Cross7278afc2017-11-02 22:38:32 -070035 // Make paths in deps files relative
36 "-no-canonical-prefixes",
Colin Cross39d450b2017-11-06 12:53:30 -080037 "-fno-canonical-system-headers",
Colin Cross7278afc2017-11-02 22:38:32 -070038
Colin Cross4d9c2d12016-07-29 12:48:20 -070039 "-DNDEBUG",
40 "-UDEBUG",
Colin Cross7278afc2017-11-02 22:38:32 -070041
42 "-fno-exceptions",
43 "-Wno-multichar",
44
45 "-O2",
46 "-g",
47
48 "-fno-strict-aliasing",
Dan Willemsen5d980c82019-08-27 19:37:10 -070049
50 "-Werror=date-time",
Colin Cross4d9c2d12016-07-29 12:48:20 -070051 }
52
Colin Cross6f6a4282016-10-17 14:19:06 -070053 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -070054
Colin Cross4d9c2d12016-07-29 12:48:20 -070055 deviceGlobalCflags = []string{
56 "-fdiagnostics-color",
57
Colin Cross133dbe72017-11-02 22:55:19 -070058 "-ffunction-sections",
Colin Crossea3141d2017-11-06 14:02:02 -080059 "-fdata-sections",
60 "-fno-short-enums",
Colin Cross133dbe72017-11-02 22:55:19 -070061 "-funwind-tables",
62 "-fstack-protector-strong",
63 "-Wa,--noexecstack",
64 "-D_FORTIFY_SOURCE=2",
65
66 "-Wstrict-aliasing=2",
67
Colin Cross4d9c2d12016-07-29 12:48:20 -070068 "-Werror=return-type",
69 "-Werror=non-virtual-dtor",
70 "-Werror=address",
71 "-Werror=sequence-point",
Colin Cross133dbe72017-11-02 22:55:19 -070072 "-Werror=format-security",
Colin Cross4d9c2d12016-07-29 12:48:20 -070073 }
74
Colin Cross26f14502017-11-06 13:59:48 -080075 deviceGlobalCppflags = []string{
76 "-fvisibility-inlines-hidden",
77 }
78
Colin Cross324a4572017-11-02 23:09:41 -070079 deviceGlobalLdflags = []string{
80 "-Wl,-z,noexecstack",
81 "-Wl,-z,relro",
82 "-Wl,-z,now",
83 "-Wl,--build-id=md5",
84 "-Wl,--warn-shared-textrel",
85 "-Wl,--fatal-warnings",
86 "-Wl,--no-undefined-version",
Christopher Ferrisc3a1e222019-04-10 17:57:50 -070087 "-Wl,--exclude-libs,libgcc.a",
Yi Kong3d8792f2019-05-06 16:18:33 -070088 "-Wl,--exclude-libs,libgcc_stripped.a",
Colin Cross4d9c2d12016-07-29 12:48:20 -070089 }
90
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070091 deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
92 []string{
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070093 "-fuse-ld=lld",
94 }...)
95
Colin Cross4d9c2d12016-07-29 12:48:20 -070096 hostGlobalCflags = []string{}
97
Colin Cross26f14502017-11-06 13:59:48 -080098 hostGlobalCppflags = []string{}
99
Colin Cross324a4572017-11-02 23:09:41 -0700100 hostGlobalLdflags = []string{}
101
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700102 hostGlobalLldflags = []string{"-fuse-ld=lld"}
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700103
Colin Cross4d9c2d12016-07-29 12:48:20 -0700104 commonGlobalCppflags = []string{
105 "-Wsign-promo",
106 }
107
108 noOverrideGlobalCflags = []string{
109 "-Werror=int-to-pointer-cast",
110 "-Werror=pointer-to-int-cast",
George Burgess IV6c691642019-09-18 17:52:05 -0700111 "-Werror=fortify-source",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700112 }
113
Colin Crossb98c8b02016-07-29 13:44:28 -0700114 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700115 "-w",
116 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700117
Dan Albert043833c2017-02-03 16:13:38 -0800118 CStdVersion = "gnu99"
Elliott Hughes34e4e412018-11-30 16:03:06 +0000119 CppStdVersion = "gnu++17"
Dan Albert043833c2017-02-03 16:13:38 -0800120 ExperimentalCStdVersion = "gnu11"
Elliott Hughes37976122018-11-28 14:16:39 -0800121 ExperimentalCppStdVersion = "gnu++2a"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700122
Dan Albertc715eda2018-01-16 16:21:06 -0800123 NdkMaxPrebuiltVersionInt = 27
Leo Li8756b372017-05-22 16:11:34 -0700124
125 // prebuilts/clang default settings.
126 ClangDefaultBase = "prebuilts/clang/host"
Yi Kongd255c7b2019-08-07 14:50:57 -0700127 ClangDefaultVersion = "clang-r365631"
128 ClangDefaultShortVersion = "9.0.6"
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800129
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800130 // Directories with warnings from Android.bp files.
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800131 WarningAllowedProjects = []string{
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800132 "device/",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800133 "vendor/",
134 }
135
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800136 // Directories with warnings from Android.mk files.
137 WarningAllowedOldProjects = []string{}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700138)
139
Colin Crossb98c8b02016-07-29 13:44:28 -0700140var pctx = android.NewPackageContext("android/soong/cc/config")
141
Colin Cross4d9c2d12016-07-29 12:48:20 -0700142func init() {
143 if android.BuildOs == android.Linux {
144 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
145 }
146
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700147 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Cross26f14502017-11-06 13:59:48 -0800148 pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
Colin Cross324a4572017-11-02 23:09:41 -0700149 pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700150 pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
Colin Cross26f14502017-11-06 13:59:48 -0800151 pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
Colin Cross324a4572017-11-02 23:09:41 -0700152 pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700153 pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700154
Stephen Hines66c8b442019-06-10 17:40:12 -0700155 pctx.VariableFunc("CommonClangGlobalCflags", func(ctx android.PackageVarContext) string {
156 flags := ClangFilterUnknownCflags(commonGlobalCflags)
157 flags = append(flags, "${ClangExtraCflags}")
158
159 // http://b/131390872
160 // Automatically initialize any uninitialized stack variables.
161 // Prefer zero-init if both options are set.
162 if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
163 flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
164 } else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
165 flags = append(flags, "-ftrivial-auto-var-init=pattern")
166 }
167
168 return strings.Join(flags, " ")
169 })
170
Doug Hornc32c6b02019-01-17 14:44:05 -0800171 pctx.VariableFunc("DeviceClangGlobalCflags", func(ctx android.PackageVarContext) string {
172 if ctx.Config().Fuchsia() {
173 return strings.Join(ClangFilterUnknownCflags(deviceGlobalCflags), " ")
174 } else {
175 return strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")
176 }
177 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700178 pctx.StaticVariable("HostClangGlobalCflags",
179 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
180 pctx.StaticVariable("NoOverrideClangGlobalCflags",
181 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700182
Colin Crossb98c8b02016-07-29 13:44:28 -0700183 pctx.StaticVariable("CommonClangGlobalCppflags",
184 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700185
Yi Kongcc80f8d2018-06-06 14:42:44 -0700186 pctx.StaticVariable("ClangExternalCflags", "${ClangExtraExternalCflags}")
187
Colin Cross1cfd89a2016-09-15 09:30:46 -0700188 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700189 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700190 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700191 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000192 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700193 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700194 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700195 "hardware/libhardware_legacy/include",
196 "hardware/ril/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700197 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800198 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700199 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700200 })
201 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
202 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700203 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Steven Moreland3afa3cd2017-09-25 11:22:02 -0700204 []string{"libnativehelper/include_jni"})
Colin Cross4d9c2d12016-07-29 12:48:20 -0700205
Leo Li8756b372017-05-22 16:11:34 -0700206 pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
Dan Willemsen54daaf02018-03-12 13:24:09 -0700207 pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
208 if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
209 return override
Colin Cross4d9c2d12016-07-29 12:48:20 -0700210 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700211 return "${ClangDefaultBase}"
Colin Cross4d9c2d12016-07-29 12:48:20 -0700212 })
Dan Willemsen54daaf02018-03-12 13:24:09 -0700213 pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
214 if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
215 return override
Colin Cross4d9c2d12016-07-29 12:48:20 -0700216 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700217 return ClangDefaultVersion
Colin Cross4d9c2d12016-07-29 12:48:20 -0700218 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700219 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
220 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
221
Dan Willemsen54daaf02018-03-12 13:24:09 -0700222 pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
223 if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
224 return override
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800225 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700226 return ClangDefaultShortVersion
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800227 })
Stephen Hines755fe072018-01-24 19:58:36 -0800228 pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700229
Jayant Chowdharye622d202017-02-01 19:19:52 -0800230 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
231 // being used for the rest of the build process.
232 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
233 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
234 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
235 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
236 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
237
Jeff Gaston734e3802017-04-10 15:47:24 -0700238 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700239 []string{
240 "external/clang/lib/Headers",
241 "frameworks/rs/script_api/include",
242 })
243
Dan Willemsen54daaf02018-03-12 13:24:09 -0700244 pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
245 if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
246 return override + " "
Alistair Strachan777475c2016-08-26 12:55:49 -0700247 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700248 return ""
Alistair Strachan777475c2016-08-26 12:55:49 -0700249 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700250}
251
252var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
253
Elliott Hughesde28deb2017-10-12 09:07:53 -0700254func bionicHeaders(kernelArch string) string {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700255 return strings.Join([]string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700256 "-isystem bionic/libc/include",
257 "-isystem bionic/libc/kernel/uapi",
258 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
Elliott Hughes98418a02017-05-25 17:16:10 -0700259 "-isystem bionic/libc/kernel/android/scsi",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700260 "-isystem bionic/libc/kernel/android/uapi",
261 }, " ")
262}