blob: 6752f8cde56e57a48781d3013825f57d44e7b04b [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 (
28 modulesAddedWallKey = android.NewOnceKey("ModulesAddedWall")
29 modulesUsingWnoErrorKey = android.NewOnceKey("ModulesUsingWnoError")
30 modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile")
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080031)
32
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080033func init() {
Colin Cross635c3b02016-05-18 15:37:25 -070034 android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080035}
36
Colin Cross571cccf2019-02-04 11:22:08 -080037func getNamedMapForConfig(config android.Config, key android.OnceKey) *sync.Map {
38 return config.Once(key, func() interface{} {
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080039 return &sync.Map{}
40 }).(*sync.Map)
41}
42
Colin Cross571cccf2019-02-04 11:22:08 -080043func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string {
44 set := getNamedMapForConfig(ctx.Config(), key)
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080045 keys := []string{}
46 set.Range(func(key interface{}, value interface{}) bool {
47 keys = append(keys, key.(string))
48 return true
49 })
50 sort.Strings(keys)
51 return strings.Join(keys, " ")
52}
53
54func makeStringOfWarningAllowedProjects() string {
55 allProjects := append([]string{}, config.WarningAllowedProjects...)
56 allProjects = append(allProjects, config.WarningAllowedOldProjects...)
57 sort.Strings(allProjects)
58 // Makefile rules use pattern "path/%" to match module paths.
59 if len(allProjects) > 0 {
60 return strings.Join(allProjects, "% ") + "%"
61 } else {
62 return ""
63 }
64}
65
Przemyslaw Szczepaniake6fc5072019-07-12 14:06:23 +010066type notOnHostContext struct {
67}
68
69func (c *notOnHostContext) Host() bool {
70 return false
71}
72
Colin Cross635c3b02016-05-18 15:37:25 -070073func makeVarsProvider(ctx android.MakeVarsContext) {
Dan Willemsen10091192016-12-14 15:50:54 -080074 ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
Colin Crossb98c8b02016-07-29 13:44:28 -070075 ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
76 ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}")
77 ctx.Strict("LLVM_PREBUILTS_PATH", "${config.ClangBin}")
78 ctx.Strict("CLANG", "${config.ClangBin}/clang")
79 ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++")
80 ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as")
81 ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link")
Chih-Hung Hsieh30485c92018-06-04 10:37:43 -070082 ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy")
83 ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip")
Dan Willemsena03cf6d2016-09-26 15:45:04 -070084 ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
Colin Crossb98c8b02016-07-29 13:44:28 -070085 ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080086
Jayant Chowdharye622d202017-02-01 19:19:52 -080087 ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}")
88 ctx.Strict("RS_LLVM_PREBUILTS_BASE", "${config.RSClangBase}")
89 ctx.Strict("RS_LLVM_PREBUILTS_PATH", "${config.RSLLVMPrebuiltsPath}")
Jayant Chowdhary715cac32017-04-20 06:53:59 -070090 ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}")
Jayant Chowdharye622d202017-02-01 19:19:52 -080091 ctx.Strict("RS_CLANG", "${config.RSLLVMPrebuiltsPath}/clang")
92 ctx.Strict("RS_LLVM_AS", "${config.RSLLVMPrebuiltsPath}/llvm-as")
93 ctx.Strict("RS_LLVM_LINK", "${config.RSLLVMPrebuiltsPath}/llvm-link")
94
Colin Cross0523ba22021-07-14 18:45:05 -070095 ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ExternalCflags}")
96 ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}")
Dan Willemsen5efc7062016-05-27 15:23:38 -070097 ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
Stephen Hinese24303f2021-12-14 15:07:08 -080098 ctx.Strict("GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideExternalGlobalCflags}")
Dan Willemsen5efc7062016-05-27 15:23:38 -070099
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700100 ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion())
Jose Galmes6f843bc2020-12-11 13:36:29 -0800101 ctx.Strict("RECOVERY_SNAPSHOT_VERSION", ctx.DeviceConfig().RecoverySnapshotVersion())
Dan Willemsend2ede872016-11-18 14:54:24 -0800102
Jiyong Park374510b2018-03-19 18:23:01 +0900103 // Filter vendor_public_library that are exported to make
104 exportedVendorPublicLibraries := []string{}
Colin Cross65494b92019-02-07 14:25:51 -0800105 ctx.VisitAllModules(func(module android.Module) {
Jiyong Park374510b2018-03-19 18:23:01 +0900106 if ccModule, ok := module.(*Module); ok {
107 baseName := ccModule.BaseModuleName()
Colin Cross5271fea2021-04-27 13:06:04 -0700108 if ccModule.IsVendorPublicLibrary() && module.ExportedToMake() {
Jiyong Park374510b2018-03-19 18:23:01 +0900109 if !inList(baseName, exportedVendorPublicLibraries) {
110 exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
111 }
112 }
113 }
114 })
115 sort.Strings(exportedVendorPublicLibraries)
116 ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " "))
117
Jayant Chowdharydcd33b62018-02-23 16:43:23 -0800118 sort.Strings(lsdumpPaths)
119 ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))
120
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800121 ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
Colin Cross571cccf2019-02-04 11:22:08 -0800122 ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWallKey))
123 ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey))
124 ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey))
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800125
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700126 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
127 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
Dan Willemsencbceaab2016-10-13 16:44:07 -0700128
Evgenii Stepanova6302332018-08-28 13:51:05 -0700129 ctx.Strict("HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(hwasanCflags, " "))
Evgenii Stepanov109029f2018-10-03 18:22:57 -0700130 ctx.Strict("HWADDRESS_SANITIZER_GLOBAL_OPTIONS", strings.Join(hwasanGlobalOptions, ","))
Evgenii Stepanova6302332018-08-28 13:51:05 -0700131
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700132 ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " "))
Evgenii Stepanovdbf1d4f2018-08-31 12:54:33 -0700133 ctx.Strict("CFI_EXTRA_ASFLAGS", strings.Join(cfiAsflags, " "))
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700134 ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " "))
Vishwath Mohanf3918d32017-02-14 07:59:33 -0800135
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700136 ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " "))
137
Colin Cross6f6a4282016-10-17 14:19:06 -0700138 ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion)
139 ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion)
Dan Albert043833c2017-02-03 16:13:38 -0800140 ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion)
141 ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion)
Colin Cross6f6a4282016-10-17 14:19:06 -0700142
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700143 ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}")
144 ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks))
145 ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}")
Chih-Hung Hsieh9e5d8a62018-09-21 15:12:44 -0700146 ctx.Strict("WITH_TIDY_FLAGS", "${config.TidyWithTidyFlags}")
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700147
Dan Willemsene1240db2016-11-03 14:28:51 -0700148 ctx.Strict("AIDL_CPP", "${aidlCmd}")
Ivan Lozanod094d402019-11-26 10:32:50 -0800149 ctx.Strict("ALLOWED_MANUAL_INTERFACE_PATHS", strings.Join(allowedManualInterfacePaths, " "))
Dan Willemsene1240db2016-11-03 14:28:51 -0700150
Colin Cross2a252be2017-05-01 17:37:24 -0700151 ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}")
152
Colin Crossd2e92da2018-09-07 23:16:36 -0700153 ctx.Strict("SOONG_STRIP_PATH", "${stripPath}")
154 ctx.Strict("XZ", "${xzCmd}")
David Srbecky69315e42021-04-29 21:06:47 +0100155 ctx.Strict("CREATE_MINIDEBUGINFO", "${createMiniDebugInfo}")
Colin Crossd2e92da2018-09-07 23:16:36 -0700156
Colin Cross307d1452017-04-30 17:45:07 -0700157 includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}")
Colin Cross10c78c62016-07-20 12:14:19 -0700158 if err != nil {
159 panic(err)
160 }
161 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
162 ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " "))
163 ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " "))
164
Colin Cross95f1ca02020-10-29 20:47:22 -0700165 ndkKnownLibs := *getNDKKnownLibs(ctx.Config())
Dan Albertde5aade2020-06-30 12:32:51 -0700166 sort.Strings(ndkKnownLibs)
Dan Albertf164a942020-06-30 12:46:21 -0700167 ctx.Strict("NDK_KNOWN_LIBS", strings.Join(ndkKnownLibs, " "))
Dan Albert914449f2016-06-17 16:45:24 -0700168
Colin Cross0c66bc62021-07-20 09:47:41 -0700169 hostTargets := ctx.Config().Targets[ctx.Config().BuildOS]
Colin Crossa1ad8d12016-06-01 17:09:44 -0700170 makeVarsToolchain(ctx, "", hostTargets[0])
171 if len(hostTargets) > 1 {
172 makeVarsToolchain(ctx, "2ND_", hostTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800173 }
174
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700175 deviceTargets := ctx.Config().Targets[android.Android]
Colin Crossa1ad8d12016-06-01 17:09:44 -0700176 makeVarsToolchain(ctx, "", deviceTargets[0])
177 if len(deviceTargets) > 1 {
178 makeVarsToolchain(ctx, "2ND_", deviceTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800179 }
180}
181
Colin Cross635c3b02016-05-18 15:37:25 -0700182func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
Colin Crossa1ad8d12016-06-01 17:09:44 -0700183 target android.Target) {
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800184 var typePrefix string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700185 switch target.Os.Class {
186 case android.Host:
187 typePrefix = "HOST_"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700188 case android.Device:
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800189 typePrefix = "TARGET_"
190 }
191 makePrefix := secondPrefix + typePrefix
192
Colin Crossb98c8b02016-07-29 13:44:28 -0700193 toolchain := config.FindToolchain(target.Os, target.Arch)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800194
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700195 var productExtraCflags string
196 var productExtraLdflags string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700197
Colin Crossb98c8b02016-07-29 13:44:28 -0700198 hod := "Host"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700199 if target.Os.Class == android.Device {
Colin Crossb98c8b02016-07-29 13:44:28 -0700200 hod = "Device"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700201 }
202
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700203 if target.Os.Class == android.Host && ctx.Config().HostStaticBinaries() {
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700204 productExtraLdflags += "-static"
Dan Willemsen06f45332016-05-16 19:32:33 -0700205 }
206
Dan Willemsen558e5172016-05-19 16:58:46 -0700207 includeFlags, err := ctx.Eval(toolchain.IncludeFlags())
Colin Crossa1ad8d12016-06-01 17:09:44 -0700208 if err != nil {
209 panic(err)
210 }
Colin Cross10c78c62016-07-20 12:14:19 -0700211 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
212 ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " "))
213 ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700214
Colin Crossa1ad8d12016-06-01 17:09:44 -0700215 if target.Arch.ArchType == android.Arm {
Colin Cross33bac242021-07-14 17:03:16 -0700216 flags, err := toolchain.InstructionSetFlags("arm")
Colin Crossa1ad8d12016-06-01 17:09:44 -0700217 if err != nil {
218 panic(err)
219 }
Dan Willemsen558e5172016-05-19 16:58:46 -0700220 ctx.Strict(makePrefix+"arm_CFLAGS", flags)
221
Colin Cross33bac242021-07-14 17:03:16 -0700222 flags, err = toolchain.InstructionSetFlags("thumb")
Colin Crossa1ad8d12016-06-01 17:09:44 -0700223 if err != nil {
224 panic(err)
225 }
Dan Willemsen558e5172016-05-19 16:58:46 -0700226 ctx.Strict(makePrefix+"thumb_CFLAGS", flags)
227 }
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800228
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700229 clangPrefix := secondPrefix + "CLANG_" + typePrefix
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800230
Peter Collingbourneb0e61432019-07-22 16:36:06 -0700231 ctx.Strict(clangPrefix+"TRIPLE", toolchain.ClangTriple())
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700232 ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
Colin Cross33bac242021-07-14 17:03:16 -0700233 toolchain.Cflags(),
Colin Cross0523ba22021-07-14 18:45:05 -0700234 "${config.CommonGlobalCflags}",
235 fmt.Sprintf("${config.%sGlobalCflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700236 toolchain.ToolchainCflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700237 productExtraCflags,
238 }, " "))
239 ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
Colin Cross0523ba22021-07-14 18:45:05 -0700240 "${config.CommonGlobalCppflags}",
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700241 fmt.Sprintf("${config.%sGlobalCppflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700242 toolchain.Cppflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700243 }, " "))
244 ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
245 fmt.Sprintf("${config.%sGlobalLdflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700246 toolchain.Ldflags(),
247 toolchain.ToolchainLdflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700248 productExtraLdflags,
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700249 }, " "))
250 ctx.Strict(clangPrefix+"GLOBAL_LLDFLAGS", strings.Join([]string{
251 fmt.Sprintf("${config.%sGlobalLldflags}", hod),
Colin Cross33bac242021-07-14 17:03:16 -0700252 toolchain.Lldflags(),
253 toolchain.ToolchainLdflags(),
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700254 productExtraLdflags,
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700255 }, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700256
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700257 if target.Os.Class == android.Device {
Colin Crossdd5655b2022-02-17 11:16:08 -0800258 sanitizerVariables := map[string]string{
259 "ADDRESS_SANITIZER_RUNTIME_LIBRARY": config.AddressSanitizerRuntimeLibrary(toolchain),
260 "HWADDRESS_SANITIZER_RUNTIME_LIBRARY": config.HWAddressSanitizerRuntimeLibrary(toolchain),
261 "HWADDRESS_SANITIZER_STATIC_LIBRARY": config.HWAddressSanitizerStaticLibrary(toolchain),
262 "UBSAN_RUNTIME_LIBRARY": config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain),
263 "UBSAN_MINIMAL_RUNTIME_LIBRARY": config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain),
264 "TSAN_RUNTIME_LIBRARY": config.ThreadSanitizerRuntimeLibrary(toolchain),
265 "SCUDO_RUNTIME_LIBRARY": config.ScudoRuntimeLibrary(toolchain),
266 "SCUDO_MINIMAL_RUNTIME_LIBRARY": config.ScudoMinimalRuntimeLibrary(toolchain),
267 }
268
269 for variable, value := range sanitizerVariables {
270 ctx.Strict(secondPrefix+variable, value)
271 }
272
273 sanitizerLibs := android.SortedStringValues(sanitizerVariables)
274 var sanitizerLibStems []string
275 ctx.VisitAllModules(func(m android.Module) {
276 if !m.Enabled() {
277 return
278 }
279
280 ccModule, _ := m.(*Module)
281 if ccModule == nil || ccModule.library == nil || !ccModule.library.shared() {
282 return
283 }
284
285 if android.InList(strings.TrimPrefix(ctx.ModuleName(m), "prebuilt_"), sanitizerLibs) &&
286 m.Target().Os == target.Os && m.Target().Arch.ArchType == target.Arch.ArchType {
287 outputFile := ccModule.outputFile
288 if outputFile.Valid() {
289 sanitizerLibStems = append(sanitizerLibStems, outputFile.Path().Base())
290 }
291 }
292 })
293 sanitizerLibStems = android.SortedUniqueStrings(sanitizerLibStems)
294 ctx.Strict(secondPrefix+"SANITIZER_STEMS", strings.Join(sanitizerLibStems, " "))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800295 }
296
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700297 // This is used by external/gentoo/...
298 ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE",
299 toolchain.ClangTriple())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800300
Colin Crossa1ad8d12016-06-01 17:09:44 -0700301 if target.Os == android.Darwin {
Colin Crossb98c8b02016-07-29 13:44:28 -0700302 ctx.Strict(makePrefix+"AR", "${config.MacArPath}")
Dan Willemsenfdb20d02018-06-03 16:13:40 -0700303 ctx.Strict(makePrefix+"NM", "${config.MacToolPath}/nm")
304 ctx.Strict(makePrefix+"OTOOL", "${config.MacToolPath}/otool")
305 ctx.Strict(makePrefix+"STRIP", "${config.MacStripPath}")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800306 } else {
Stephen Hinesf1addeb2018-01-09 23:29:04 -0800307 ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar")
Elliott Hughesa960a0d2021-04-21 10:22:55 -0700308 ctx.Strict(makePrefix+"READELF", "${config.ClangBin}/llvm-readelf")
309 ctx.Strict(makePrefix+"NM", "${config.ClangBin}/llvm-nm")
310 ctx.Strict(makePrefix+"STRIP", "${config.ClangBin}/llvm-strip")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800311 }
Dan Willemsen73d21f22016-05-16 14:22:56 -0700312
Colin Crossa1ad8d12016-06-01 17:09:44 -0700313 if target.Os.Class == android.Device {
Elliott Hughesb6788c02021-05-04 22:38:05 -0700314 ctx.Strict(makePrefix+"OBJCOPY", "${config.ClangBin}/llvm-objcopy")
315 ctx.Strict(makePrefix+"LD", "${config.ClangBin}/lld")
Chih-Hung Hsieh1e7d1bf2018-03-15 18:44:57 -0700316 ctx.Strict(makePrefix+"NDK_TRIPLE", config.NDKTriple(toolchain))
Elliott Hughescd9ff092021-05-07 11:55:30 -0700317 ctx.Strict(makePrefix+"TOOLS_PREFIX", "${config.ClangBin}/llvm-")
Elliott Hughesb6788c02021-05-04 22:38:05 -0700318 // TODO: GCC version is obsolete now that GCC has been removed.
319 ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion())
Dan Willemsen73d21f22016-05-16 14:22:56 -0700320 }
321
Dan Willemsen96ce8e72019-01-25 17:00:45 -0800322 if target.Os.Class == android.Host {
Dan Willemsen652b3832017-09-22 13:55:22 -0700323 ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " "))
324 }
325
Dan Willemsen558e5172016-05-19 16:58:46 -0700326 ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
327 ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800328}
Colin Cross10c78c62016-07-20 12:14:19 -0700329
330func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) {
331 flags, err := ctx.Eval(val)
332 if err != nil {
333 panic(err)
334 }
335
336 extract := func(flags string, dirs []string, prefix string) (string, []string, bool) {
337 if strings.HasPrefix(flags, prefix) {
338 flags = strings.TrimPrefix(flags, prefix)
339 flags = strings.TrimLeft(flags, " ")
340 s := strings.SplitN(flags, " ", 2)
341 dirs = append(dirs, s[0])
342 if len(s) > 1 {
343 return strings.TrimLeft(s[1], " "), dirs, true
344 }
345 return "", dirs, true
346 } else {
347 return flags, dirs, false
348 }
349 }
350
351 flags = strings.TrimLeft(flags, " ")
352 for flags != "" {
353 found := false
354 flags, includes, found = extract(flags, includes, "-I")
355 if !found {
356 flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ")
357 }
358 if !found {
359 panic(fmt.Errorf("Unexpected flag in %q", flags))
360 }
361 }
362
363 return includes, systemIncludes
364}
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700365
366func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string {
367 rets := make([]string, len(checks))
368 for i, check := range config.DefaultLocalTidyChecks {
369 rets[i] = check.PathPrefix + ":" + check.Checks
370 }
371 return strings.Join(rets, " ")
372}