blob: 8fc9ff2949873ad5f7d59618ed4e747b1f261be8 [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",
Christopher Ferrisc3a1e222019-04-10 17:57:50 -070086 "-Wl,--exclude-libs,libgcc.a",
Colin Cross4d9c2d12016-07-29 12:48:20 -070087 }
88
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070089 deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
90 []string{
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070091 "-fuse-ld=lld",
92 }...)
93
Colin Cross4d9c2d12016-07-29 12:48:20 -070094 hostGlobalCflags = []string{}
95
Colin Cross26f14502017-11-06 13:59:48 -080096 hostGlobalCppflags = []string{}
97
Colin Cross324a4572017-11-02 23:09:41 -070098 hostGlobalLdflags = []string{}
99
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700100 hostGlobalLldflags = []string{"-fuse-ld=lld"}
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700101
Colin Cross4d9c2d12016-07-29 12:48:20 -0700102 commonGlobalCppflags = []string{
103 "-Wsign-promo",
104 }
105
106 noOverrideGlobalCflags = []string{
107 "-Werror=int-to-pointer-cast",
108 "-Werror=pointer-to-int-cast",
109 }
110
Colin Crossb98c8b02016-07-29 13:44:28 -0700111 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700112 "-w",
113 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700114
Dan Albert043833c2017-02-03 16:13:38 -0800115 CStdVersion = "gnu99"
Elliott Hughes34e4e412018-11-30 16:03:06 +0000116 CppStdVersion = "gnu++17"
Dan Albert043833c2017-02-03 16:13:38 -0800117 ExperimentalCStdVersion = "gnu11"
Elliott Hughes37976122018-11-28 14:16:39 -0800118 ExperimentalCppStdVersion = "gnu++2a"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700119
Dan Albertc715eda2018-01-16 16:21:06 -0800120 NdkMaxPrebuiltVersionInt = 27
Leo Li8756b372017-05-22 16:11:34 -0700121
122 // prebuilts/clang default settings.
123 ClangDefaultBase = "prebuilts/clang/host"
Yi Kong5d7aeea2019-03-26 16:13:25 -0700124 ClangDefaultVersion = "clang-r353983b"
125 ClangDefaultShortVersion = "9.0.2"
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800126
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800127 // Directories with warnings from Android.bp files.
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800128 WarningAllowedProjects = []string{
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800129 "device/",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800130 "vendor/",
131 }
132
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800133 // Directories with warnings from Android.mk files.
134 WarningAllowedOldProjects = []string{}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700135)
136
Colin Crossb98c8b02016-07-29 13:44:28 -0700137var pctx = android.NewPackageContext("android/soong/cc/config")
138
Colin Cross4d9c2d12016-07-29 12:48:20 -0700139func init() {
140 if android.BuildOs == android.Linux {
141 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
142 }
143
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700144 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Cross26f14502017-11-06 13:59:48 -0800145 pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
Colin Cross324a4572017-11-02 23:09:41 -0700146 pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700147 pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
Colin Cross26f14502017-11-06 13:59:48 -0800148 pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
Colin Cross324a4572017-11-02 23:09:41 -0700149 pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700150 pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700151
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 pctx.StaticVariable("CommonClangGlobalCflags",
153 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
Doug Hornc32c6b02019-01-17 14:44:05 -0800154 pctx.VariableFunc("DeviceClangGlobalCflags", func(ctx android.PackageVarContext) string {
155 if ctx.Config().Fuchsia() {
156 return strings.Join(ClangFilterUnknownCflags(deviceGlobalCflags), " ")
157 } else {
158 return strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")
159 }
160 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700161 pctx.StaticVariable("HostClangGlobalCflags",
162 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
163 pctx.StaticVariable("NoOverrideClangGlobalCflags",
164 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700165
Colin Crossb98c8b02016-07-29 13:44:28 -0700166 pctx.StaticVariable("CommonClangGlobalCppflags",
167 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700168
Yi Kongcc80f8d2018-06-06 14:42:44 -0700169 pctx.StaticVariable("ClangExternalCflags", "${ClangExtraExternalCflags}")
170
Colin Cross1cfd89a2016-09-15 09:30:46 -0700171 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700172 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700173 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700174 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000175 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700176 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700177 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700178 "hardware/libhardware_legacy/include",
179 "hardware/ril/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700180 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800181 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700182 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700183 })
184 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
185 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700186 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Steven Moreland3afa3cd2017-09-25 11:22:02 -0700187 []string{"libnativehelper/include_jni"})
Colin Cross4d9c2d12016-07-29 12:48:20 -0700188
Leo Li8756b372017-05-22 16:11:34 -0700189 pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
Dan Willemsen54daaf02018-03-12 13:24:09 -0700190 pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
191 if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
192 return override
Colin Cross4d9c2d12016-07-29 12:48:20 -0700193 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700194 return "${ClangDefaultBase}"
Colin Cross4d9c2d12016-07-29 12:48:20 -0700195 })
Dan Willemsen54daaf02018-03-12 13:24:09 -0700196 pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
197 if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
198 return override
Colin Cross4d9c2d12016-07-29 12:48:20 -0700199 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700200 return ClangDefaultVersion
Colin Cross4d9c2d12016-07-29 12:48:20 -0700201 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700202 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
203 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
204
Dan Willemsen54daaf02018-03-12 13:24:09 -0700205 pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
206 if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
207 return override
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800208 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700209 return ClangDefaultShortVersion
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800210 })
Stephen Hines755fe072018-01-24 19:58:36 -0800211 pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700212
Jayant Chowdharye622d202017-02-01 19:19:52 -0800213 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
214 // being used for the rest of the build process.
215 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
216 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
217 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
218 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
219 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
220
Jeff Gaston734e3802017-04-10 15:47:24 -0700221 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700222 []string{
223 "external/clang/lib/Headers",
224 "frameworks/rs/script_api/include",
225 })
226
Dan Willemsen54daaf02018-03-12 13:24:09 -0700227 pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
228 if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
229 return override + " "
Alistair Strachan777475c2016-08-26 12:55:49 -0700230 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700231 return ""
Alistair Strachan777475c2016-08-26 12:55:49 -0700232 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700233}
234
235var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
236
Elliott Hughesde28deb2017-10-12 09:07:53 -0700237func bionicHeaders(kernelArch string) string {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700238 return strings.Join([]string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700239 "-isystem bionic/libc/include",
240 "-isystem bionic/libc/kernel/uapi",
241 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
Elliott Hughes98418a02017-05-25 17:16:10 -0700242 "-isystem bionic/libc/kernel/android/scsi",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700243 "-isystem bionic/libc/kernel/android/uapi",
244 }, " ")
245}