blob: 9d29affcd3fd81a4b0c492a40036c26c1c0d411f [file] [log] [blame]
Dan Willemsen4b7d5de2016-01-12 23:20:28 -08001// 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
15package cc
16
17import (
18 "fmt"
Dan Willemsen65905f82016-09-14 20:29:05 -070019 "sort"
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080020 "strings"
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080021 "sync"
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080022
Colin Cross635c3b02016-05-18 15:37:25 -070023 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070024 "android/soong/cc/config"
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080025)
26
Colin Cross571cccf2019-02-04 11:22:08 -080027var (
Yi Kongde936472022-05-19 20:11:10 +080028 modulesWarningsAllowedKey = android.NewOnceKey("ModulesWarningsAllowed")
Colin Cross571cccf2019-02-04 11:22:08 -080029 modulesUsingWnoErrorKey = android.NewOnceKey("ModulesUsingWnoError")
30 modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile")
Kiyoung Kim0d8908c2024-05-07 14:47:35 +090031 sanitizerVariables = map[string]string{
32 "ADDRESS_SANITIZER_RUNTIME_LIBRARY": config.AddressSanitizerRuntimeLibrary(),
33 "HWADDRESS_SANITIZER_RUNTIME_LIBRARY": config.HWAddressSanitizerRuntimeLibrary(),
34 "HWADDRESS_SANITIZER_STATIC_LIBRARY": config.HWAddressSanitizerStaticLibrary(),
35 "UBSAN_RUNTIME_LIBRARY": config.UndefinedBehaviorSanitizerRuntimeLibrary(),
36 "UBSAN_MINIMAL_RUNTIME_LIBRARY": config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(),
37 "TSAN_RUNTIME_LIBRARY": config.ThreadSanitizerRuntimeLibrary(),
38 "SCUDO_RUNTIME_LIBRARY": config.ScudoRuntimeLibrary(),
39 "SCUDO_MINIMAL_RUNTIME_LIBRARY": config.ScudoMinimalRuntimeLibrary(),
40 }
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080041)
42
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080043func init() {
Colin Cross635c3b02016-05-18 15:37:25 -070044 android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080045}
46
Colin Cross571cccf2019-02-04 11:22:08 -080047func getNamedMapForConfig(config android.Config, key android.OnceKey) *sync.Map {
48 return config.Once(key, func() interface{} {
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080049 return &sync.Map{}
50 }).(*sync.Map)
51}
52
Colin Cross571cccf2019-02-04 11:22:08 -080053func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string {
54 set := getNamedMapForConfig(ctx.Config(), key)
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080055 keys := []string{}
56 set.Range(func(key interface{}, value interface{}) bool {
57 keys = append(keys, key.(string))
58 return true
59 })
60 sort.Strings(keys)
61 return strings.Join(keys, " ")
62}
63
64func makeStringOfWarningAllowedProjects() string {
65 allProjects := append([]string{}, config.WarningAllowedProjects...)
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080066 sort.Strings(allProjects)
67 // Makefile rules use pattern "path/%" to match module paths.
68 if len(allProjects) > 0 {
69 return strings.Join(allProjects, "% ") + "%"
70 } else {
71 return ""
72 }
73}
74
Przemyslaw Szczepaniake6fc5072019-07-12 14:06:23 +010075type notOnHostContext struct {
76}
77
78func (c *notOnHostContext) Host() bool {
79 return false
80}
81
Colin Cross635c3b02016-05-18 15:37:25 -070082func makeVarsProvider(ctx android.MakeVarsContext) {
Dan Willemsen10091192016-12-14 15:50:54 -080083 ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
Colin Crossb98c8b02016-07-29 13:44:28 -070084 ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
85 ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}")
86 ctx.Strict("LLVM_PREBUILTS_PATH", "${config.ClangBin}")
87 ctx.Strict("CLANG", "${config.ClangBin}/clang")
88 ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++")
89 ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as")
90 ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link")
Chih-Hung Hsieh30485c92018-06-04 10:37:43 -070091 ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy")
92 ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip")
Dan Willemsena03cf6d2016-09-26 15:45:04 -070093 ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
Colin Crossb98c8b02016-07-29 13:44:28 -070094 ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080095
Jayant Chowdharye622d202017-02-01 19:19:52 -080096 ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}")
97 ctx.Strict("RS_LLVM_PREBUILTS_BASE", "${config.RSClangBase}")
98 ctx.Strict("RS_LLVM_PREBUILTS_PATH", "${config.RSLLVMPrebuiltsPath}")
Jayant Chowdhary715cac32017-04-20 06:53:59 -070099 ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}")
Jayant Chowdharye622d202017-02-01 19:19:52 -0800100 ctx.Strict("RS_CLANG", "${config.RSLLVMPrebuiltsPath}/clang")
101 ctx.Strict("RS_LLVM_AS", "${config.RSLLVMPrebuiltsPath}/llvm-as")
102 ctx.Strict("RS_LLVM_LINK", "${config.RSLLVMPrebuiltsPath}/llvm-link")
103
Colin Cross0523ba22021-07-14 18:45:05 -0700104 ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ExternalCflags}")
105 ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}")
zijunzhao933e3802023-01-12 07:26:20 +0000106 ctx.Strict("GLOBAL_CLANG_CFLAGS_64_NO_OVERRIDE", "${config.NoOverride64GlobalCflags}")
Dan Willemsen5efc7062016-05-27 15:23:38 -0700107 ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
Stephen Hinese24303f2021-12-14 15:07:08 -0800108 ctx.Strict("GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideExternalGlobalCflags}")
Dan Willemsen5efc7062016-05-27 15:23:38 -0700109
Jiyong Park374510b2018-03-19 18:23:01 +0900110 // Filter vendor_public_library that are exported to make
111 exportedVendorPublicLibraries := []string{}
Colin Cross65494b92019-02-07 14:25:51 -0800112 ctx.VisitAllModules(func(module android.Module) {
Jiyong Park374510b2018-03-19 18:23:01 +0900113 if ccModule, ok := module.(*Module); ok {
114 baseName := ccModule.BaseModuleName()
Colin Cross5271fea2021-04-27 13:06:04 -0700115 if ccModule.IsVendorPublicLibrary() && module.ExportedToMake() {
Jiyong Park374510b2018-03-19 18:23:01 +0900116 if !inList(baseName, exportedVendorPublicLibraries) {
117 exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
118 }
119 }
120 }
121 })
122 sort.Strings(exportedVendorPublicLibraries)
123 ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " "))
124
Jayant Chowdharydcd33b62018-02-23 16:43:23 -0800125 sort.Strings(lsdumpPaths)
126 ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))
127
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800128 ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
Yi Kongde936472022-05-19 20:11:10 +0800129 ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeStringOfKeys(ctx, modulesWarningsAllowedKey))
Colin Cross571cccf2019-02-04 11:22:08 -0800130 ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey))
131 ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey))
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800132
Kiyoung Kim37693d02024-04-04 09:56:15 +0900133 ctx.Strict("CLANG_COVERAGE_CONFIG_CFLAGS", strings.Join(clangCoverageCFlags, " "))
134 ctx.Strict("CLANG_COVERAGE_CONFIG_COMMFLAGS", strings.Join(clangCoverageCommonFlags, " "))
135 ctx.Strict("CLANG_COVERAGE_HOST_LDFLAGS", strings.Join(clangCoverageHostLdFlags, " "))
136 ctx.Strict("CLANG_COVERAGE_INSTR_PROFILE", profileInstrFlag)
137 ctx.Strict("CLANG_COVERAGE_CONTINUOUS_FLAGS", strings.Join(clangContinuousCoverageFlags, " "))
138 ctx.Strict("CLANG_COVERAGE_HWASAN_FLAGS", strings.Join(clangCoverageHWASanFlags, " "))
Gabriel Chen1589c962023-11-30 20:29:44 -0800139
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700140 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
141 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
Dan Willemsencbceaab2016-10-13 16:44:07 -0700142
Evgenii Stepanova6302332018-08-28 13:51:05 -0700143 ctx.Strict("HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(hwasanCflags, " "))
Evgenii Stepanov109029f2018-10-03 18:22:57 -0700144 ctx.Strict("HWADDRESS_SANITIZER_GLOBAL_OPTIONS", strings.Join(hwasanGlobalOptions, ","))
Evgenii Stepanova6302332018-08-28 13:51:05 -0700145
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700146 ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " "))
Evgenii Stepanovdbf1d4f2018-08-31 12:54:33 -0700147 ctx.Strict("CFI_EXTRA_ASFLAGS", strings.Join(cfiAsflags, " "))
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700148 ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " "))
Vishwath Mohanf3918d32017-02-14 07:59:33 -0800149
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700150 ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " "))
151
Colin Cross6f6a4282016-10-17 14:19:06 -0700152 ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion)
153 ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion)
Dan Albert043833c2017-02-03 16:13:38 -0800154 ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion)
155 ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion)
Colin Cross6f6a4282016-10-17 14:19:06 -0700156
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700157 ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}")
158 ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks))
159 ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}")
Chih-Hung Hsieh9e5d8a62018-09-21 15:12:44 -0700160 ctx.Strict("WITH_TIDY_FLAGS", "${config.TidyWithTidyFlags}")
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700161
Dan Willemsene1240db2016-11-03 14:28:51 -0700162 ctx.Strict("AIDL_CPP", "${aidlCmd}")
Ivan Lozanod094d402019-11-26 10:32:50 -0800163 ctx.Strict("ALLOWED_MANUAL_INTERFACE_PATHS", strings.Join(allowedManualInterfacePaths, " "))
Dan Willemsene1240db2016-11-03 14:28:51 -0700164
Colin Cross2a252be2017-05-01 17:37:24 -0700165 ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}")
166
Colin Crossd2e92da2018-09-07 23:16:36 -0700167 ctx.Strict("SOONG_STRIP_PATH", "${stripPath}")
168 ctx.Strict("XZ", "${xzCmd}")
David Srbecky69315e42021-04-29 21:06:47 +0100169 ctx.Strict("CREATE_MINIDEBUGINFO", "${createMiniDebugInfo}")
Colin Crossd2e92da2018-09-07 23:16:36 -0700170
Colin Cross307d1452017-04-30 17:45:07 -0700171 includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}")
Colin Cross10c78c62016-07-20 12:14:19 -0700172 if err != nil {
173 panic(err)
174 }
175 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
176 ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " "))
177 ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " "))
178
Colin Cross95f1ca02020-10-29 20:47:22 -0700179 ndkKnownLibs := *getNDKKnownLibs(ctx.Config())
Dan Albertde5aade2020-06-30 12:32:51 -0700180 sort.Strings(ndkKnownLibs)
Dan Albertf164a942020-06-30 12:46:21 -0700181 ctx.Strict("NDK_KNOWN_LIBS", strings.Join(ndkKnownLibs, " "))
Dan Albert914449f2016-06-17 16:45:24 -0700182
Colin Cross0c66bc62021-07-20 09:47:41 -0700183 hostTargets := ctx.Config().Targets[ctx.Config().BuildOS]
Colin Crossa1ad8d12016-06-01 17:09:44 -0700184 makeVarsToolchain(ctx, "", hostTargets[0])
185 if len(hostTargets) > 1 {
186 makeVarsToolchain(ctx, "2ND_", hostTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800187 }
188
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700189 deviceTargets := ctx.Config().Targets[android.Android]
Colin Crossa1ad8d12016-06-01 17:09:44 -0700190 makeVarsToolchain(ctx, "", deviceTargets[0])
191 if len(deviceTargets) > 1 {
192 makeVarsToolchain(ctx, "2ND_", deviceTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800193 }
Kiyoung Kim37693d02024-04-04 09:56:15 +0900194
195 makeLlndkVars(ctx)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800196}
197
Colin Cross635c3b02016-05-18 15:37:25 -0700198func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
Colin Crossa1ad8d12016-06-01 17:09:44 -0700199 target android.Target) {
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800200 var typePrefix string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700201 switch target.Os.Class {
202 case android.Host:
203 typePrefix = "HOST_"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700204 case android.Device:
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800205 typePrefix = "TARGET_"
206 }
207 makePrefix := secondPrefix + typePrefix
208
Colin Crossb98c8b02016-07-29 13:44:28 -0700209 toolchain := config.FindToolchain(target.Os, target.Arch)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800210
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700211 var productExtraCflags string
212 var productExtraLdflags string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700213
Colin Crossb98c8b02016-07-29 13:44:28 -0700214 hod := "Host"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700215 if target.Os.Class == android.Device {
Colin Crossb98c8b02016-07-29 13:44:28 -0700216 hod = "Device"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700217 }
218
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700219 if target.Os.Class == android.Host && ctx.Config().HostStaticBinaries() {
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700220 productExtraLdflags += "-static"
Dan Willemsen06f45332016-05-16 19:32:33 -0700221 }
222
Dan Willemsen558e5172016-05-19 16:58:46 -0700223 includeFlags, err := ctx.Eval(toolchain.IncludeFlags())
Colin Crossa1ad8d12016-06-01 17:09:44 -0700224 if err != nil {
225 panic(err)
226 }
Colin Cross10c78c62016-07-20 12:14:19 -0700227 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
228 ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " "))
229 ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700230
Colin Crossa1ad8d12016-06-01 17:09:44 -0700231 if target.Arch.ArchType == android.Arm {
Colin Cross33bac242021-07-14 17:03:16 -0700232 flags, err := toolchain.InstructionSetFlags("arm")
Colin Crossa1ad8d12016-06-01 17:09:44 -0700233 if err != nil {
234 panic(err)
235 }
Dan Willemsen558e5172016-05-19 16:58:46 -0700236 ctx.Strict(makePrefix+"arm_CFLAGS", flags)
237
Colin Cross33bac242021-07-14 17:03:16 -0700238 flags, err = toolchain.InstructionSetFlags("thumb")
Colin Crossa1ad8d12016-06-01 17:09:44 -0700239 if err != nil {
240 panic(err)
241 }
Dan Willemsen558e5172016-05-19 16:58:46 -0700242 ctx.Strict(makePrefix+"thumb_CFLAGS", flags)
243 }
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800244
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700245 clangPrefix := secondPrefix + "CLANG_" + typePrefix
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800246
Peter Collingbourneb0e61432019-07-22 16:36:06 -0700247 ctx.Strict(clangPrefix+"TRIPLE", toolchain.ClangTriple())
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700248 ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
Colin Cross33bac242021-07-14 17:03:16 -0700249 toolchain.Cflags(),
Colin Cross0523ba22021-07-14 18:45:05 -0700250 "${config.CommonGlobalCflags}",
251 fmt.Sprintf("${config.%sGlobalCflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700252 toolchain.ToolchainCflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700253 productExtraCflags,
254 }, " "))
255 ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
Colin Cross0523ba22021-07-14 18:45:05 -0700256 "${config.CommonGlobalCppflags}",
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700257 fmt.Sprintf("${config.%sGlobalCppflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700258 toolchain.Cppflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700259 }, " "))
260 ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
261 fmt.Sprintf("${config.%sGlobalLdflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700262 toolchain.Ldflags(),
263 toolchain.ToolchainLdflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700264 productExtraLdflags,
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700265 }, " "))
266 ctx.Strict(clangPrefix+"GLOBAL_LLDFLAGS", strings.Join([]string{
267 fmt.Sprintf("${config.%sGlobalLldflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700268 toolchain.Lldflags(),
269 toolchain.ToolchainLdflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700270 productExtraLdflags,
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700271 }, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700272
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700273 if target.Os.Class == android.Device {
Colin Crossdd5655b2022-02-17 11:16:08 -0800274 for variable, value := range sanitizerVariables {
275 ctx.Strict(secondPrefix+variable, value)
276 }
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800277 }
278
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700279 // This is used by external/gentoo/...
280 ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE",
281 toolchain.ClangTriple())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800282
Colin Crossa1ad8d12016-06-01 17:09:44 -0700283 if target.Os == android.Darwin {
Colin Crossb98c8b02016-07-29 13:44:28 -0700284 ctx.Strict(makePrefix+"AR", "${config.MacArPath}")
Dan Willemsenfdb20d02018-06-03 16:13:40 -0700285 ctx.Strict(makePrefix+"NM", "${config.MacToolPath}/nm")
286 ctx.Strict(makePrefix+"OTOOL", "${config.MacToolPath}/otool")
287 ctx.Strict(makePrefix+"STRIP", "${config.MacStripPath}")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800288 } else {
Stephen Hinesf1addeb2018-01-09 23:29:04 -0800289 ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar")
Elliott Hughesa960a0d2021-04-21 10:22:55 -0700290 ctx.Strict(makePrefix+"READELF", "${config.ClangBin}/llvm-readelf")
291 ctx.Strict(makePrefix+"NM", "${config.ClangBin}/llvm-nm")
292 ctx.Strict(makePrefix+"STRIP", "${config.ClangBin}/llvm-strip")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800293 }
Dan Willemsen73d21f22016-05-16 14:22:56 -0700294
Colin Crossa1ad8d12016-06-01 17:09:44 -0700295 if target.Os.Class == android.Device {
Elliott Hughesb6788c02021-05-04 22:38:05 -0700296 ctx.Strict(makePrefix+"OBJCOPY", "${config.ClangBin}/llvm-objcopy")
297 ctx.Strict(makePrefix+"LD", "${config.ClangBin}/lld")
Chih-Hung Hsieh1e7d1bf2018-03-15 18:44:57 -0700298 ctx.Strict(makePrefix+"NDK_TRIPLE", config.NDKTriple(toolchain))
Elliott Hughescd9ff092021-05-07 11:55:30 -0700299 ctx.Strict(makePrefix+"TOOLS_PREFIX", "${config.ClangBin}/llvm-")
Dan Willemsen73d21f22016-05-16 14:22:56 -0700300 }
301
Dan Willemsen96ce8e72019-01-25 17:00:45 -0800302 if target.Os.Class == android.Host {
Dan Willemsen652b3832017-09-22 13:55:22 -0700303 ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " "))
304 }
305
Dan Willemsen558e5172016-05-19 16:58:46 -0700306 ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
307 ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800308}
Colin Cross10c78c62016-07-20 12:14:19 -0700309
310func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) {
311 flags, err := ctx.Eval(val)
312 if err != nil {
313 panic(err)
314 }
315
316 extract := func(flags string, dirs []string, prefix string) (string, []string, bool) {
317 if strings.HasPrefix(flags, prefix) {
318 flags = strings.TrimPrefix(flags, prefix)
319 flags = strings.TrimLeft(flags, " ")
320 s := strings.SplitN(flags, " ", 2)
321 dirs = append(dirs, s[0])
322 if len(s) > 1 {
323 return strings.TrimLeft(s[1], " "), dirs, true
324 }
325 return "", dirs, true
326 } else {
327 return flags, dirs, false
328 }
329 }
330
331 flags = strings.TrimLeft(flags, " ")
332 for flags != "" {
333 found := false
334 flags, includes, found = extract(flags, includes, "-I")
335 if !found {
336 flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ")
337 }
338 if !found {
339 panic(fmt.Errorf("Unexpected flag in %q", flags))
340 }
341 }
342
343 return includes, systemIncludes
344}
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700345
346func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string {
347 rets := make([]string, len(checks))
348 for i, check := range config.DefaultLocalTidyChecks {
349 rets[i] = check.PathPrefix + ":" + check.Checks
350 }
351 return strings.Join(rets, " ")
352}