blob: 8fd59144fbcf0f6a73f37549dfd67a765034eca2 [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",
Colin Cross4d9c2d12016-07-29 12:48:20 -070049 }
50
Colin Cross6f6a4282016-10-17 14:19:06 -070051 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -070052
Colin Cross4d9c2d12016-07-29 12:48:20 -070053 deviceGlobalCflags = []string{
54 "-fdiagnostics-color",
55
Colin Cross133dbe72017-11-02 22:55:19 -070056 "-ffunction-sections",
Colin Crossea3141d2017-11-06 14:02:02 -080057 "-fdata-sections",
58 "-fno-short-enums",
Colin Cross133dbe72017-11-02 22:55:19 -070059 "-funwind-tables",
60 "-fstack-protector-strong",
61 "-Wa,--noexecstack",
62 "-D_FORTIFY_SOURCE=2",
63
64 "-Wstrict-aliasing=2",
65
Colin Cross4d9c2d12016-07-29 12:48:20 -070066 "-Werror=return-type",
67 "-Werror=non-virtual-dtor",
68 "-Werror=address",
69 "-Werror=sequence-point",
70 "-Werror=date-time",
Colin Cross133dbe72017-11-02 22:55:19 -070071 "-Werror=format-security",
Colin Cross4d9c2d12016-07-29 12:48:20 -070072 }
73
Colin Cross26f14502017-11-06 13:59:48 -080074 deviceGlobalCppflags = []string{
75 "-fvisibility-inlines-hidden",
76 }
77
Colin Cross324a4572017-11-02 23:09:41 -070078 deviceGlobalLdflags = []string{
79 "-Wl,-z,noexecstack",
80 "-Wl,-z,relro",
81 "-Wl,-z,now",
82 "-Wl,--build-id=md5",
83 "-Wl,--warn-shared-textrel",
84 "-Wl,--fatal-warnings",
85 "-Wl,--no-undefined-version",
Colin Cross4d9c2d12016-07-29 12:48:20 -070086 }
87
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070088 deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
89 []string{
Rahul Chaudhry1ffac8e2018-07-02 11:20:43 -070090 "-Wl,--pack-dyn-relocs=android+relr",
91 "-Wl,--use-android-relr-tags",
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070092 "-fuse-ld=lld",
93 }...)
94
Colin Cross4d9c2d12016-07-29 12:48:20 -070095 hostGlobalCflags = []string{}
96
Colin Cross26f14502017-11-06 13:59:48 -080097 hostGlobalCppflags = []string{}
98
Colin Cross324a4572017-11-02 23:09:41 -070099 hostGlobalLdflags = []string{}
100
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700101 hostGlobalLldflags = []string{"-fuse-ld=lld"}
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700102
Colin Cross4d9c2d12016-07-29 12:48:20 -0700103 commonGlobalCppflags = []string{
104 "-Wsign-promo",
105 }
106
107 noOverrideGlobalCflags = []string{
108 "-Werror=int-to-pointer-cast",
109 "-Werror=pointer-to-int-cast",
110 }
111
Colin Crossb98c8b02016-07-29 13:44:28 -0700112 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700113 "-w",
114 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700115
Dan Albert043833c2017-02-03 16:13:38 -0800116 CStdVersion = "gnu99"
Nikita Iashchenko7a782202018-11-30 11:15:16 +0000117 CppStdVersion = "gnu++14"
Dan Albert043833c2017-02-03 16:13:38 -0800118 ExperimentalCStdVersion = "gnu11"
Elliott Hughes37976122018-11-28 14:16:39 -0800119 ExperimentalCppStdVersion = "gnu++2a"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700120
Dan Albertc715eda2018-01-16 16:21:06 -0800121 NdkMaxPrebuiltVersionInt = 27
Leo Li8756b372017-05-22 16:11:34 -0700122
123 // prebuilts/clang default settings.
124 ClangDefaultBase = "prebuilts/clang/host"
Pirama Arumuga Nainar538be1f2018-11-12 10:19:58 -0800125 ClangDefaultVersion = "clang-r344140b"
126 ClangDefaultShortVersion = "8.0.4"
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800127
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800128 // Directories with warnings from Android.bp files.
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800129 WarningAllowedProjects = []string{
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800130 "device/",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800131 "vendor/",
132 }
133
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800134 // Directories with warnings from Android.mk files.
135 WarningAllowedOldProjects = []string{}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700136)
137
Colin Crossb98c8b02016-07-29 13:44:28 -0700138var pctx = android.NewPackageContext("android/soong/cc/config")
139
Colin Cross4d9c2d12016-07-29 12:48:20 -0700140func init() {
141 if android.BuildOs == android.Linux {
142 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
143 }
144
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700145 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Cross26f14502017-11-06 13:59:48 -0800146 pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
Colin Cross324a4572017-11-02 23:09:41 -0700147 pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700148 pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
Colin Cross26f14502017-11-06 13:59:48 -0800149 pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
Colin Cross324a4572017-11-02 23:09:41 -0700150 pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700151 pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700152
Colin Crossb98c8b02016-07-29 13:44:28 -0700153 pctx.StaticVariable("CommonClangGlobalCflags",
154 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
155 pctx.StaticVariable("DeviceClangGlobalCflags",
156 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
157 pctx.StaticVariable("HostClangGlobalCflags",
158 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
159 pctx.StaticVariable("NoOverrideClangGlobalCflags",
160 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700161
Colin Crossb98c8b02016-07-29 13:44:28 -0700162 pctx.StaticVariable("CommonClangGlobalCppflags",
163 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700164
Yi Kongcc80f8d2018-06-06 14:42:44 -0700165 pctx.StaticVariable("ClangExternalCflags", "${ClangExtraExternalCflags}")
166
Colin Cross1cfd89a2016-09-15 09:30:46 -0700167 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700168 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700169 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700170 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000171 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700172 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700173 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700174 "hardware/libhardware_legacy/include",
175 "hardware/ril/include",
176 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700177 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800178 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700179 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700180 })
181 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
182 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700183 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Steven Moreland3afa3cd2017-09-25 11:22:02 -0700184 []string{"libnativehelper/include_jni"})
Colin Cross4d9c2d12016-07-29 12:48:20 -0700185
Leo Li8756b372017-05-22 16:11:34 -0700186 pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
Dan Willemsen54daaf02018-03-12 13:24:09 -0700187 pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
188 if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
189 return override
Colin Cross4d9c2d12016-07-29 12:48:20 -0700190 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700191 return "${ClangDefaultBase}"
Colin Cross4d9c2d12016-07-29 12:48:20 -0700192 })
Dan Willemsen54daaf02018-03-12 13:24:09 -0700193 pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
194 if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
195 return override
Colin Cross4d9c2d12016-07-29 12:48:20 -0700196 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700197 return ClangDefaultVersion
Colin Cross4d9c2d12016-07-29 12:48:20 -0700198 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700199 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
200 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
Chih-Hung Hsiehb699c432018-08-27 16:19:59 -0700201 pctx.StaticVariable("ClangTidyShellPath", "build/soong/scripts/clang-tidy.sh")
Colin Crossb98c8b02016-07-29 13:44:28 -0700202
Dan Willemsen54daaf02018-03-12 13:24:09 -0700203 pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
204 if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
205 return override
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800206 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700207 return ClangDefaultShortVersion
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800208 })
Stephen Hines755fe072018-01-24 19:58:36 -0800209 pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700210
Jayant Chowdharye622d202017-02-01 19:19:52 -0800211 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
212 // being used for the rest of the build process.
213 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
214 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
215 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
216 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
217 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
218
Jeff Gaston734e3802017-04-10 15:47:24 -0700219 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700220 []string{
221 "external/clang/lib/Headers",
222 "frameworks/rs/script_api/include",
223 })
224
Dan Willemsen54daaf02018-03-12 13:24:09 -0700225 pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
226 if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
227 return override + " "
Alistair Strachan777475c2016-08-26 12:55:49 -0700228 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700229 return ""
Alistair Strachan777475c2016-08-26 12:55:49 -0700230 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700231}
232
233var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
234
Elliott Hughesde28deb2017-10-12 09:07:53 -0700235func bionicHeaders(kernelArch string) string {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700236 return strings.Join([]string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700237 "-isystem bionic/libc/include",
238 "-isystem bionic/libc/kernel/uapi",
239 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
Elliott Hughes98418a02017-05-25 17:16:10 -0700240 "-isystem bionic/libc/kernel/android/scsi",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700241 "-isystem bionic/libc/kernel/android/uapi",
242 }, " ")
243}