blob: 32674a9d23a880e4887330a0aef604b558613fa1 [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")
Chih-Hung Hsieh30485c92018-06-04 10:37:43 -070075 ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy")
76 ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip")
Dan Willemsena03cf6d2016-09-26 15:45:04 -070077 ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
Chih-Hung Hsiehb699c432018-08-27 16:19:59 -070078 ctx.Strict("PATH_TO_CLANG_TIDY_SHELL", "${config.ClangTidyShellPath}")
Colin Crossb98c8b02016-07-29 13:44:28 -070079 ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -080080
Jayant Chowdharye622d202017-02-01 19:19:52 -080081 ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}")
82 ctx.Strict("RS_LLVM_PREBUILTS_BASE", "${config.RSClangBase}")
83 ctx.Strict("RS_LLVM_PREBUILTS_PATH", "${config.RSLLVMPrebuiltsPath}")
Jayant Chowdhary715cac32017-04-20 06:53:59 -070084 ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}")
Jayant Chowdharye622d202017-02-01 19:19:52 -080085 ctx.Strict("RS_CLANG", "${config.RSLLVMPrebuiltsPath}/clang")
86 ctx.Strict("RS_LLVM_AS", "${config.RSLLVMPrebuiltsPath}/llvm-as")
87 ctx.Strict("RS_LLVM_LINK", "${config.RSLLVMPrebuiltsPath}/llvm-link")
88
Yi Kongcc80f8d2018-06-06 14:42:44 -070089 ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ClangExternalCflags}")
Dan Willemsen25cc01f2018-10-07 19:42:38 -070090 ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideClangGlobalCflags}")
Dan Willemsen5efc7062016-05-27 15:23:38 -070091 ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
Dan Willemsen97704ed2016-07-07 21:40:39 -070092 ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " "))
Dan Willemsen5efc7062016-05-27 15:23:38 -070093
Dan Willemsen3fb1fae2018-03-12 15:30:26 -070094 ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion())
Dan Willemsend2ede872016-11-18 14:54:24 -080095
Jiyong Parkab0fd5f2017-08-03 21:22:50 +090096 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(vndkCoreLibraries, " "))
97 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(vndkSpLibraries, " "))
98 ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " "))
Jiyong Park82e2bf32017-08-16 14:05:54 +090099 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " "))
Jiyong Parkab0fd5f2017-08-03 21:22:50 +0900100
Jiyong Park374510b2018-03-19 18:23:01 +0900101 // Filter vendor_public_library that are exported to make
102 exportedVendorPublicLibraries := []string{}
103 ctx.SingletonContext().VisitAllModules(func(module android.Module) {
104 if ccModule, ok := module.(*Module); ok {
105 baseName := ccModule.BaseModuleName()
106 if inList(baseName, vendorPublicLibraries) && module.ExportedToMake() {
107 if !inList(baseName, exportedVendorPublicLibraries) {
108 exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
109 }
110 }
111 }
112 })
113 sort.Strings(exportedVendorPublicLibraries)
114 ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " "))
115
Jayant Chowdharydcd33b62018-02-23 16:43:23 -0800116 sort.Strings(lsdumpPaths)
117 ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))
118
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800119 ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
120 ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWall))
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800121 ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoError))
Pirama Arumuga Nainar28316d42018-01-29 09:18:45 -0800122 ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFile))
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800123
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700124 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
125 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
126 ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " "))
Dan Willemsencbceaab2016-10-13 16:44:07 -0700127
Evgenii Stepanova6302332018-08-28 13:51:05 -0700128 ctx.Strict("HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(hwasanCflags, " "))
Evgenii Stepanov109029f2018-10-03 18:22:57 -0700129 ctx.Strict("HWADDRESS_SANITIZER_GLOBAL_OPTIONS", strings.Join(hwasanGlobalOptions, ","))
Evgenii Stepanova6302332018-08-28 13:51:05 -0700130
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700131 ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " "))
Evgenii Stepanovdbf1d4f2018-08-31 12:54:33 -0700132 ctx.Strict("CFI_EXTRA_ASFLAGS", strings.Join(cfiAsflags, " "))
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700133 ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " "))
Vishwath Mohanf3918d32017-02-14 07:59:33 -0800134
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700135 ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " "))
136
Colin Cross6f6a4282016-10-17 14:19:06 -0700137 ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion)
138 ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion)
Dan Albert043833c2017-02-03 16:13:38 -0800139 ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion)
140 ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion)
Colin Cross6f6a4282016-10-17 14:19:06 -0700141
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700142 ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}")
143 ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks))
144 ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}")
Chih-Hung Hsieh9e5d8a62018-09-21 15:12:44 -0700145 ctx.Strict("WITH_TIDY_FLAGS", "${config.TidyWithTidyFlags}")
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700146
Dan Willemsene1240db2016-11-03 14:28:51 -0700147 ctx.Strict("AIDL_CPP", "${aidlCmd}")
148
Colin Cross2a252be2017-05-01 17:37:24 -0700149 ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}")
150
Colin Crossd2e92da2018-09-07 23:16:36 -0700151 ctx.Strict("SOONG_STRIP_PATH", "${stripPath}")
152 ctx.Strict("XZ", "${xzCmd}")
153
Steven Moreland3cf63062017-07-18 13:29:35 -0700154 nativeHelperIncludeFlags, err := ctx.Eval("${config.CommonNativehelperInclude}")
155 if err != nil {
156 panic(err)
157 }
158 nativeHelperIncludes, nativeHelperSystemIncludes := splitSystemIncludes(ctx, nativeHelperIncludeFlags)
159 if len(nativeHelperSystemIncludes) > 0 {
160 panic("native helper may not have any system includes")
161 }
162 ctx.Strict("JNI_H_INCLUDE", strings.Join(nativeHelperIncludes, " "))
163
Colin Cross307d1452017-04-30 17:45:07 -0700164 includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}")
Colin Cross10c78c62016-07-20 12:14:19 -0700165 if err != nil {
166 panic(err)
167 }
168 includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
169 ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " "))
170 ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " "))
171
Dan Willemsen65905f82016-09-14 20:29:05 -0700172 sort.Strings(ndkMigratedLibs)
Dan Albert914449f2016-06-17 16:45:24 -0700173 ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " "))
174
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700175 hostTargets := ctx.Config().Targets[android.BuildOs]
Colin Crossa1ad8d12016-06-01 17:09:44 -0700176 makeVarsToolchain(ctx, "", hostTargets[0])
177 if len(hostTargets) > 1 {
178 makeVarsToolchain(ctx, "2ND_", hostTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800179 }
180
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700181 crossTargets := ctx.Config().Targets[android.Windows]
Colin Crossa1ad8d12016-06-01 17:09:44 -0700182 if len(crossTargets) > 0 {
183 makeVarsToolchain(ctx, "", crossTargets[0])
184 if len(crossTargets) > 1 {
185 makeVarsToolchain(ctx, "2ND_", crossTargets[1])
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800186 }
187 }
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 }
194}
195
Colin Cross635c3b02016-05-18 15:37:25 -0700196func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
Colin Crossa1ad8d12016-06-01 17:09:44 -0700197 target android.Target) {
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800198 var typePrefix string
Colin Crossa1ad8d12016-06-01 17:09:44 -0700199 switch target.Os.Class {
200 case android.Host:
201 typePrefix = "HOST_"
202 case android.HostCross:
203 typePrefix = "HOST_CROSS_"
204 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 {
Dan Willemsen25cc01f2018-10-07 19:42:38 -0700232 flags, err := toolchain.ClangInstructionSetFlags("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
Dan Willemsen25cc01f2018-10-07 19:42:38 -0700238 flags, err = toolchain.ClangInstructionSetFlags("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
246 clangExtras := "-target " + toolchain.ClangTriple()
247 clangExtras += " -B" + config.ToolPath(toolchain)
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800248
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700249 ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
250 toolchain.ClangCflags(),
251 "${config.CommonClangGlobalCflags}",
252 fmt.Sprintf("${config.%sClangGlobalCflags}", hod),
253 toolchain.ToolchainClangCflags(),
254 clangExtras,
255 productExtraCflags,
256 }, " "))
257 ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
258 "${config.CommonClangGlobalCppflags}",
259 fmt.Sprintf("${config.%sGlobalCppflags}", hod),
260 toolchain.ClangCppflags(),
261 }, " "))
262 ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
263 fmt.Sprintf("${config.%sGlobalLdflags}", hod),
264 toolchain.ClangLdflags(),
265 toolchain.ToolchainClangLdflags(),
266 productExtraLdflags,
267 clangExtras,
268 }, " "))
269 ctx.Strict(clangPrefix+"GLOBAL_LLDFLAGS", strings.Join([]string{
270 fmt.Sprintf("${config.%sGlobalLldflags}", hod),
271 toolchain.ClangLldflags(),
272 toolchain.ToolchainClangLdflags(),
273 productExtraLdflags,
274 clangExtras,
275 }, " "))
Dan Willemsen558e5172016-05-19 16:58:46 -0700276
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700277 if target.Os.Class == android.Device {
278 ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so"))
279 ctx.Strict(secondPrefix+"HWADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.HWAddressSanitizerRuntimeLibrary(toolchain), ".so"))
280 ctx.Strict(secondPrefix+"HWADDRESS_SANITIZER_STATIC_LIBRARY", strings.TrimSuffix(config.HWAddressSanitizerStaticLibrary(toolchain), ".a"))
281 ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so"))
282 ctx.Strict(secondPrefix+"UBSAN_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), ".a"))
283 ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so"))
284 ctx.Strict(secondPrefix+"SCUDO_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoRuntimeLibrary(toolchain), ".so"))
Kostya Kortchinskyad73b2e2018-10-11 08:38:39 -0700285 ctx.Strict(secondPrefix+"SCUDO_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoMinimalRuntimeLibrary(toolchain), ".so"))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800286 }
287
Dan Willemsenf640dbc2018-09-04 22:25:59 -0700288 // This is used by external/gentoo/...
289 ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE",
290 toolchain.ClangTriple())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800291
Colin Crossa1ad8d12016-06-01 17:09:44 -0700292 if target.Os == android.Darwin {
Colin Crossb98c8b02016-07-29 13:44:28 -0700293 ctx.Strict(makePrefix+"AR", "${config.MacArPath}")
Dan Willemsenfdb20d02018-06-03 16:13:40 -0700294 ctx.Strict(makePrefix+"NM", "${config.MacToolPath}/nm")
295 ctx.Strict(makePrefix+"OTOOL", "${config.MacToolPath}/otool")
296 ctx.Strict(makePrefix+"STRIP", "${config.MacStripPath}")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800297 } else {
Stephen Hinesf1addeb2018-01-09 23:29:04 -0800298 ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar")
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800299 ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
300 ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
Dan Willemsenfdb20d02018-06-03 16:13:40 -0700301 ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800302 }
Dan Willemsen73d21f22016-05-16 14:22:56 -0700303
Colin Crossa1ad8d12016-06-01 17:09:44 -0700304 if target.Os == android.Windows {
Dan Willemsen73d21f22016-05-16 14:22:56 -0700305 ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
306 }
307
Colin Crossa1ad8d12016-06-01 17:09:44 -0700308 if target.Os.Class == android.Device {
Dan Willemsen73d21f22016-05-16 14:22:56 -0700309 ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
310 ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
Dan Willemsen558e5172016-05-19 16:58:46 -0700311 ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion())
Chih-Hung Hsieh1e7d1bf2018-03-15 18:44:57 -0700312 ctx.Strict(makePrefix+"NDK_TRIPLE", config.NDKTriple(toolchain))
Dan Willemsen25cc01f2018-10-07 19:42:38 -0700313 ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
Dan Willemsen73d21f22016-05-16 14:22:56 -0700314 }
315
Dan Willemsen652b3832017-09-22 13:55:22 -0700316 if target.Os.Class == android.Host || target.Os.Class == android.HostCross {
317 ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " "))
318 }
319
Dan Willemsen558e5172016-05-19 16:58:46 -0700320 ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
321 ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix())
Dan Willemsen4b7d5de2016-01-12 23:20:28 -0800322}
Colin Cross10c78c62016-07-20 12:14:19 -0700323
324func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) {
325 flags, err := ctx.Eval(val)
326 if err != nil {
327 panic(err)
328 }
329
330 extract := func(flags string, dirs []string, prefix string) (string, []string, bool) {
331 if strings.HasPrefix(flags, prefix) {
332 flags = strings.TrimPrefix(flags, prefix)
333 flags = strings.TrimLeft(flags, " ")
334 s := strings.SplitN(flags, " ", 2)
335 dirs = append(dirs, s[0])
336 if len(s) > 1 {
337 return strings.TrimLeft(s[1], " "), dirs, true
338 }
339 return "", dirs, true
340 } else {
341 return flags, dirs, false
342 }
343 }
344
345 flags = strings.TrimLeft(flags, " ")
346 for flags != "" {
347 found := false
348 flags, includes, found = extract(flags, includes, "-I")
349 if !found {
350 flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ")
351 }
352 if !found {
353 panic(fmt.Errorf("Unexpected flag in %q", flags))
354 }
355 }
356
357 return includes, systemIncludes
358}
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700359
360func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string {
361 rets := make([]string, len(checks))
362 for i, check := range config.DefaultLocalTidyChecks {
363 rets[i] = check.PathPrefix + ":" + check.Checks
364 }
365 return strings.Join(rets, " ")
366}