blob: 779de8f3a182f3069c104fa72f8aec8eadd03a3e [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
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080027const (
Pirama Arumuga Nainar28316d42018-01-29 09:18:45 -080028 modulesAddedWall = "ModulesAddedWall"
29 modulesUsingWnoError = "ModulesUsingWnoError"
30 modulesMissingProfileFile = "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
Pirama Arumuga Nainar28316d42018-01-29 09:18:45 -080037func getNamedMapForConfig(config android.Config, name string) *sync.Map {
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -080038 return config.Once(name, func() interface{} {
39 return &sync.Map{}
40 }).(*sync.Map)
41}
42
43func makeStringOfKeys(ctx android.MakeVarsContext, setName string) string {
Pirama Arumuga Nainar28316d42018-01-29 09:18:45 -080044 set := getNamedMapForConfig(ctx.Config(), setName)
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
Colin Cross635c3b02016-05-18 15:37:25 -070066func makeVarsProvider(ctx android.MakeVarsContext) {
Dan Willemsen10091192016-12-14 15:50:54 -080067 ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
Colin Crossb98c8b02016-07-29 13:44:28 -070068 ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
69 ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}")
70 ctx.Strict("LLVM_PREBUILTS_PATH", "${config.ClangBin}")
71 ctx.Strict("CLANG", "${config.ClangBin}/clang")
72 ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++")
73 ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as")
74 ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link")
Dan Willemsena03cf6d2016-09-26 15:45:04 -070075 ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
Colin Crossb98c8b02016-07-29 13:44:28 -070076 ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080077
Jayant Chowdharye622d202017-02-01 19:19:52 -080078 ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}")
79 ctx.Strict("RS_LLVM_PREBUILTS_BASE", "${config.RSClangBase}")
80 ctx.Strict("RS_LLVM_PREBUILTS_PATH", "${config.RSLLVMPrebuiltsPath}")
Jayant Chowdhary715cac32017-04-20 06:53:59 -070081 ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}")
Jayant Chowdharye622d202017-02-01 19:19:52 -080082 ctx.Strict("RS_CLANG", "${config.RSLLVMPrebuiltsPath}/clang")
83 ctx.Strict("RS_LLVM_AS", "${config.RSLLVMPrebuiltsPath}/llvm-as")
84 ctx.Strict("RS_LLVM_LINK", "${config.RSLLVMPrebuiltsPath}/llvm-link")
85
Colin Crossb98c8b02016-07-29 13:44:28 -070086 ctx.Strict("GLOBAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}")
87 ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.ClangExtraNoOverrideCflags}")
Dan Willemsen5efc7062016-05-27 15:23:38 -070088 ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "")
89 ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
Dan Willemsen97704ed2016-07-07 21:40:39 -070090 ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " "))
Dan Willemsen5efc7062016-05-27 15:23:38 -070091
Dan Willemsend2ede872016-11-18 14:54:24 -080092 if ctx.Config().ProductVariables.DeviceVndkVersion != nil {
93 ctx.Strict("BOARD_VNDK_VERSION", *ctx.Config().ProductVariables.DeviceVndkVersion)
94 } else {
95 ctx.Strict("BOARD_VNDK_VERSION", "")
96 }
Dan Willemsend2ede872016-11-18 14:54:24 -080097
Jiyong Parkab0fd5f2017-08-03 21:22:50 +090098 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(vndkCoreLibraries, " "))
99 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(vndkSpLibraries, " "))
100 ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " "))
Jiyong Park82e2bf32017-08-16 14:05:54 +0900101 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " "))
Jiyong Parkab0fd5f2017-08-03 21:22:50 +0900102
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800103 ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
104 ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWall))
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800105 ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoError))
Pirama Arumuga Nainar28316d42018-01-29 09:18:45 -0800106 ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFile))
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800107
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700108 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
109 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
110 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " "))
Dan Willemsencbceaab2016-10-13 16:44:07 -0700111
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700112 ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " "))
113 ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " "))
Vishwath Mohanf3918d32017-02-14 07:59:33 -0800114
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700115 ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " "))
116
Colin Cross6f6a4282016-10-17 14:19:06 -0700117 ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion)
118 ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion)
119 ctx.Strict("DEFAULT_GCC_CPP_STD_VERSION", config.GccCppStdVersion)
Dan Albert043833c2017-02-03 16:13:38 -0800120 ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion)
121 ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion)
Colin Cross6f6a4282016-10-17 14:19:06 -0700122
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700123 ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}")
124 ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks))
125 ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}")
126
Dan Willemsene1240db2016-11-03 14:28:51 -0700127 ctx.Strict("AIDL_CPP", "${aidlCmd}")
128
Colin Cross2a252be2017-05-01 17:37:24 -0700129 ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}")
130
Steven Moreland3cf63062017-07-18 13:29:35 -0700131 nativeHelperIncludeFlags, err := ctx.Eval("${config.CommonNativehelperInclude}")
132 if err != nil {
133 panic(err)
134 }
135 nativeHelperIncludes, nativeHelperSystemIncludes := splitSystemIncludes(ctx, nativeHelperIncludeFlags)
136 if len(nativeHelperSystemIncludes) > 0 {
137 panic("native helper may not have any system includes")
138 }
139 ctx.Strict("JNI_H_INCLUDE", strings.Join(nativeHelperIncludes, " "))
140
Colin Cross307d1452017-04-30 17:45:07 -0700141 includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}")
Colin Cross10c78c62016-07-20 12:14:19 -0700142 if err != nil {
143 panic(err)
144 }
145 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
146 ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " "))
147 ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " "))
148
Dan Willemsen65905f82016-09-14 20:29:05 -0700149 sort.Strings(ndkMigratedLibs)
Dan Albert914449f2016-06-17 16:45:24 -0700150 ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " "))
151
Colin Crossa1ad8d12016-06-01 17:09:44 -0700152 hostTargets := ctx.Config().Targets[android.Host]
153 makeVarsToolchain(ctx, "", hostTargets[0])
154 if len(hostTargets) > 1 {
155 makeVarsToolchain(ctx, "2ND_", hostTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800156 }
157
Colin Crossa1ad8d12016-06-01 17:09:44 -0700158 crossTargets := ctx.Config().Targets[android.HostCross]
159 if len(crossTargets) > 0 {
160 makeVarsToolchain(ctx, "", crossTargets[0])
161 if len(crossTargets) > 1 {
162 makeVarsToolchain(ctx, "2ND_", crossTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800163 }
164 }
165
Colin Crossa1ad8d12016-06-01 17:09:44 -0700166 deviceTargets := ctx.Config().Targets[android.Device]
167 makeVarsToolchain(ctx, "", deviceTargets[0])
168 if len(deviceTargets) > 1 {
169 makeVarsToolchain(ctx, "2ND_", deviceTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800170 }
171}
172
Colin Cross635c3b02016-05-18 15:37:25 -0700173func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
Colin Crossa1ad8d12016-06-01 17:09:44 -0700174 target android.Target) {
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800175 var typePrefix string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700176 switch target.Os.Class {
177 case android.Host:
178 typePrefix = "HOST_"
179 case android.HostCross:
180 typePrefix = "HOST_CROSS_"
181 case android.Device:
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800182 typePrefix = "TARGET_"
183 }
184 makePrefix := secondPrefix + typePrefix
185
Colin Crossb98c8b02016-07-29 13:44:28 -0700186 toolchain := config.FindToolchain(target.Os, target.Arch)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800187
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700188 var productExtraCflags string
189 var productExtraLdflags string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700190
Colin Crossb98c8b02016-07-29 13:44:28 -0700191 hod := "Host"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700192 if target.Os.Class == android.Device {
Colin Crossb98c8b02016-07-29 13:44:28 -0700193 hod = "Device"
Colin Crossa1ad8d12016-06-01 17:09:44 -0700194 }
195
196 if target.Os.Class == android.Device && Bool(ctx.Config().ProductVariables.Brillo) {
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700197 productExtraCflags += "-D__BRILLO__"
198 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700199 if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) {
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700200 productExtraLdflags += "-static"
Dan Willemsen06f45332016-05-16 19:32:33 -0700201 }
202
Dan Willemsen9598e102016-05-19 16:59:04 -0700203 ctx.Strict(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{
Dan Willemsend26a7132016-05-18 23:00:57 -0700204 toolchain.Cflags(),
Colin Crossb98c8b02016-07-29 13:44:28 -0700205 "${config.CommonGlobalCflags}",
206 fmt.Sprintf("${config.%sGlobalCflags}", hod),
Dan Willemsend26a7132016-05-18 23:00:57 -0700207 toolchain.ToolchainCflags(),
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700208 productExtraCflags,
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800209 }, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700210 ctx.Strict(makePrefix+"GLOBAL_CONLYFLAGS", strings.Join([]string{
211 "${config.CommonGlobalConlyflags}",
212 }, " "))
Dan Willemsen9598e102016-05-19 16:59:04 -0700213 ctx.Strict(makePrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700214 "${config.CommonGlobalCppflags}",
Colin Cross26f14502017-11-06 13:59:48 -0800215 fmt.Sprintf("${config.%sGlobalCppflags}", hod),
Dan Willemsen216a4592016-05-16 23:56:53 -0700216 toolchain.Cppflags(),
217 }, " "))
Dan Willemsen9598e102016-05-19 16:59:04 -0700218 ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
Colin Cross324a4572017-11-02 23:09:41 -0700219 fmt.Sprintf("${config.%sGlobalLdflags}", hod),
Dan Willemsend26a7132016-05-18 23:00:57 -0700220 toolchain.Ldflags(),
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800221 toolchain.ToolchainLdflags(),
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700222 productExtraLdflags,
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800223 }, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700224
225 includeFlags, err := ctx.Eval(toolchain.IncludeFlags())
Colin Crossa1ad8d12016-06-01 17:09:44 -0700226 if err != nil {
227 panic(err)
228 }
Colin Cross10c78c62016-07-20 12:14:19 -0700229 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
230 ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " "))
231 ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700232
Colin Crossa1ad8d12016-06-01 17:09:44 -0700233 if target.Arch.ArchType == android.Arm {
Dan Willemsen558e5172016-05-19 16:58:46 -0700234 flags, err := toolchain.InstructionSetFlags("arm")
Colin Crossa1ad8d12016-06-01 17:09:44 -0700235 if err != nil {
236 panic(err)
237 }
Dan Willemsen558e5172016-05-19 16:58:46 -0700238 ctx.Strict(makePrefix+"arm_CFLAGS", flags)
239
240 flags, err = toolchain.InstructionSetFlags("thumb")
Colin Crossa1ad8d12016-06-01 17:09:44 -0700241 if err != nil {
242 panic(err)
243 }
Dan Willemsen558e5172016-05-19 16:58:46 -0700244 ctx.Strict(makePrefix+"thumb_CFLAGS", flags)
245 }
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800246
247 if toolchain.ClangSupported() {
248 clangPrefix := secondPrefix + "CLANG_" + typePrefix
Dan Willemsen3772da12016-05-16 18:01:46 -0700249 clangExtras := "-target " + toolchain.ClangTriple()
Dan Willemsen300151b2017-03-13 12:40:30 -0700250 clangExtras += " -B" + config.ToolPath(toolchain)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800251
Dan Willemsen9598e102016-05-19 16:59:04 -0700252 ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800253 toolchain.ClangCflags(),
Colin Crossb98c8b02016-07-29 13:44:28 -0700254 "${config.CommonClangGlobalCflags}",
255 fmt.Sprintf("${config.%sClangGlobalCflags}", hod),
Dan Willemsend26a7132016-05-18 23:00:57 -0700256 toolchain.ToolchainClangCflags(),
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800257 clangExtras,
Dan Willemsend26a7132016-05-18 23:00:57 -0700258 productExtraCflags,
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800259 }, " "))
Dan Willemsen9598e102016-05-19 16:59:04 -0700260 ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700261 "${config.CommonClangGlobalCppflags}",
Colin Cross26f14502017-11-06 13:59:48 -0800262 fmt.Sprintf("${config.%sGlobalCppflags}", hod),
Dan Willemsen216a4592016-05-16 23:56:53 -0700263 toolchain.ClangCppflags(),
264 }, " "))
Dan Willemsen9598e102016-05-19 16:59:04 -0700265 ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
Colin Cross324a4572017-11-02 23:09:41 -0700266 fmt.Sprintf("${config.%sGlobalLdflags}", hod),
Dan Willemsend26a7132016-05-18 23:00:57 -0700267 toolchain.ClangLdflags(),
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800268 toolchain.ToolchainClangLdflags(),
Dan Willemsen36cff8b2016-05-17 16:35:02 -0700269 productExtraLdflags,
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800270 clangExtras,
271 }, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700272
Colin Crossa1ad8d12016-06-01 17:09:44 -0700273 if target.Os.Class == android.Device {
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700274 ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so"))
275 ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so"))
Pirama Arumuga Nainar16b626b2017-03-27 11:00:38 -0700276 ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so"))
Dan Willemsen558e5172016-05-19 16:58:46 -0700277 }
278
279 // This is used by external/gentoo/...
Colin Crossa1ad8d12016-06-01 17:09:44 -0700280 ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE",
Dan Willemsen558e5172016-05-19 16:58:46 -0700281 toolchain.ClangTriple())
Dan Willemsen7b6d9b92017-11-29 20:48:03 -0800282
283 ctx.Strict(makePrefix+"CLANG_SUPPORTED", "true")
284 } else {
285 ctx.Strict(makePrefix+"CLANG_SUPPORTED", "")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800286 }
287
288 ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
289 ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
290
Colin Crossa1ad8d12016-06-01 17:09:44 -0700291 if target.Os == android.Darwin {
Colin Crossb98c8b02016-07-29 13:44:28 -0700292 ctx.Strict(makePrefix+"AR", "${config.MacArPath}")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800293 } else {
Stephen Hinesf1addeb2018-01-09 23:29:04 -0800294 ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800295 ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
296 ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
297 }
Dan Willemsen73d21f22016-05-16 14:22:56 -0700298
Colin Crossa1ad8d12016-06-01 17:09:44 -0700299 if target.Os == android.Windows {
Dan Willemsen73d21f22016-05-16 14:22:56 -0700300 ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
301 }
302
Colin Crossa1ad8d12016-06-01 17:09:44 -0700303 if target.Os.Class == android.Device {
Dan Willemsen73d21f22016-05-16 14:22:56 -0700304 ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
305 ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
306 ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))
Dan Willemsen558e5172016-05-19 16:58:46 -0700307 ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion())
308 ctx.Strict(makePrefix+"NDK_GCC_VERSION", toolchain.GccVersion())
Dan Albert914449f2016-06-17 16:45:24 -0700309 ctx.Strict(makePrefix+"NDK_TRIPLE", toolchain.ClangTriple())
Dan Willemsen73d21f22016-05-16 14:22:56 -0700310 }
311
Dan Willemsen652b3832017-09-22 13:55:22 -0700312 if target.Os.Class == android.Host || target.Os.Class == android.HostCross {
313 ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " "))
314 }
315
Dan Willemsen0bd58872016-05-26 15:23:07 -0700316 ctx.Strict(makePrefix+"TOOLCHAIN_ROOT", toolchain.GccRoot())
Dan Willemsen73d21f22016-05-16 14:22:56 -0700317 ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
Dan Willemsen558e5172016-05-19 16:58:46 -0700318 ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
319 ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800320}
Colin Cross10c78c62016-07-20 12:14:19 -0700321
322func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) {
323 flags, err := ctx.Eval(val)
324 if err != nil {
325 panic(err)
326 }
327
328 extract := func(flags string, dirs []string, prefix string) (string, []string, bool) {
329 if strings.HasPrefix(flags, prefix) {
330 flags = strings.TrimPrefix(flags, prefix)
331 flags = strings.TrimLeft(flags, " ")
332 s := strings.SplitN(flags, " ", 2)
333 dirs = append(dirs, s[0])
334 if len(s) > 1 {
335 return strings.TrimLeft(s[1], " "), dirs, true
336 }
337 return "", dirs, true
338 } else {
339 return flags, dirs, false
340 }
341 }
342
343 flags = strings.TrimLeft(flags, " ")
344 for flags != "" {
345 found := false
346 flags, includes, found = extract(flags, includes, "-I")
347 if !found {
348 flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ")
349 }
350 if !found {
351 panic(fmt.Errorf("Unexpected flag in %q", flags))
352 }
353 }
354
355 return includes, systemIncludes
356}
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700357
358func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string {
359 rets := make([]string, len(checks))
360 for i, check := range config.DefaultLocalTidyChecks {
361 rets[i] = check.PathPrefix + ":" + check.Checks
362 }
363 return strings.Join(rets, " ")
364}