Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Dan Willemsen | 65905f8 | 2016-09-14 20:29:05 -0700 | [diff] [blame] | 19 | "sort" |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 20 | "strings" |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 21 | "sync" |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 22 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 23 | "android/soong/android" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 24 | "android/soong/cc/config" |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 27 | var ( |
Yi Kong | de93647 | 2022-05-19 20:11:10 +0800 | [diff] [blame] | 28 | modulesWarningsAllowedKey = android.NewOnceKey("ModulesWarningsAllowed") |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 29 | modulesUsingWnoErrorKey = android.NewOnceKey("ModulesUsingWnoError") |
| 30 | modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile") |
Kiyoung Kim | 0d8908c | 2024-05-07 14:47:35 +0900 | [diff] [blame] | 31 | 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 Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 41 | ) |
| 42 | |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 43 | func init() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 44 | android.RegisterMakeVarsProvider(pctx, makeVarsProvider) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 47 | func getNamedMapForConfig(config android.Config, key android.OnceKey) *sync.Map { |
| 48 | return config.Once(key, func() interface{} { |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 49 | return &sync.Map{} |
| 50 | }).(*sync.Map) |
| 51 | } |
| 52 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 53 | func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string { |
| 54 | set := getNamedMapForConfig(ctx.Config(), key) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 55 | 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 | |
| 64 | func makeStringOfWarningAllowedProjects() string { |
| 65 | allProjects := append([]string{}, config.WarningAllowedProjects...) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 66 | 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 Szczepaniak | e6fc507 | 2019-07-12 14:06:23 +0100 | [diff] [blame] | 75 | type notOnHostContext struct { |
| 76 | } |
| 77 | |
| 78 | func (c *notOnHostContext) Host() bool { |
| 79 | return false |
| 80 | } |
| 81 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 82 | func makeVarsProvider(ctx android.MakeVarsContext) { |
Dan Willemsen | 1009119 | 2016-12-14 15:50:54 -0800 | [diff] [blame] | 83 | ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 84 | 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 Hsieh | 30485c9 | 2018-06-04 10:37:43 -0700 | [diff] [blame] | 91 | ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy") |
| 92 | ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 93 | ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 94 | ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " ")) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 95 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 96 | 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 Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 99 | ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}") |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 100 | 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 Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 104 | ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ExternalCflags}") |
| 105 | ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}") |
zijunzhao | 933e380 | 2023-01-12 07:26:20 +0000 | [diff] [blame] | 106 | ctx.Strict("GLOBAL_CLANG_CFLAGS_64_NO_OVERRIDE", "${config.NoOverride64GlobalCflags}") |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 107 | ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") |
Stephen Hines | e24303f | 2021-12-14 15:07:08 -0800 | [diff] [blame] | 108 | ctx.Strict("GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideExternalGlobalCflags}") |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 109 | |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 110 | // Filter vendor_public_library that are exported to make |
| 111 | exportedVendorPublicLibraries := []string{} |
Colin Cross | 65494b9 | 2019-02-07 14:25:51 -0800 | [diff] [blame] | 112 | ctx.VisitAllModules(func(module android.Module) { |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 113 | if ccModule, ok := module.(*Module); ok { |
| 114 | baseName := ccModule.BaseModuleName() |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 115 | if ccModule.IsVendorPublicLibrary() && module.ExportedToMake() { |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 116 | 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 Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 125 | sort.Strings(lsdumpPaths) |
| 126 | ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " ")) |
| 127 | |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 128 | ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects()) |
Yi Kong | de93647 | 2022-05-19 20:11:10 +0800 | [diff] [blame] | 129 | ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeStringOfKeys(ctx, modulesWarningsAllowedKey)) |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 130 | ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey)) |
| 131 | ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey)) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 132 | |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 133 | 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 Chen | 1589c96 | 2023-11-30 20:29:44 -0800 | [diff] [blame] | 139 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 140 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " ")) |
| 141 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " ")) |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 142 | |
Evgenii Stepanov | a630233 | 2018-08-28 13:51:05 -0700 | [diff] [blame] | 143 | ctx.Strict("HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(hwasanCflags, " ")) |
Evgenii Stepanov | 109029f | 2018-10-03 18:22:57 -0700 | [diff] [blame] | 144 | ctx.Strict("HWADDRESS_SANITIZER_GLOBAL_OPTIONS", strings.Join(hwasanGlobalOptions, ",")) |
Evgenii Stepanov | a630233 | 2018-08-28 13:51:05 -0700 | [diff] [blame] | 145 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 146 | ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " ")) |
Evgenii Stepanov | dbf1d4f | 2018-08-31 12:54:33 -0700 | [diff] [blame] | 147 | ctx.Strict("CFI_EXTRA_ASFLAGS", strings.Join(cfiAsflags, " ")) |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 148 | ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " ")) |
Vishwath Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 149 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 150 | ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " ")) |
| 151 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 152 | ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion) |
| 153 | ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion) |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 154 | ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion) |
| 155 | ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion) |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 156 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 157 | 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 Hsieh | 9e5d8a6 | 2018-09-21 15:12:44 -0700 | [diff] [blame] | 160 | ctx.Strict("WITH_TIDY_FLAGS", "${config.TidyWithTidyFlags}") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 161 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 162 | ctx.Strict("AIDL_CPP", "${aidlCmd}") |
Ivan Lozano | d094d40 | 2019-11-26 10:32:50 -0800 | [diff] [blame] | 163 | ctx.Strict("ALLOWED_MANUAL_INTERFACE_PATHS", strings.Join(allowedManualInterfacePaths, " ")) |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 164 | |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 165 | ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}") |
| 166 | |
Colin Cross | d2e92da | 2018-09-07 23:16:36 -0700 | [diff] [blame] | 167 | ctx.Strict("SOONG_STRIP_PATH", "${stripPath}") |
| 168 | ctx.Strict("XZ", "${xzCmd}") |
David Srbecky | 69315e4 | 2021-04-29 21:06:47 +0100 | [diff] [blame] | 169 | ctx.Strict("CREATE_MINIDEBUGINFO", "${createMiniDebugInfo}") |
Colin Cross | d2e92da | 2018-09-07 23:16:36 -0700 | [diff] [blame] | 170 | |
Colin Cross | 307d145 | 2017-04-30 17:45:07 -0700 | [diff] [blame] | 171 | includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}") |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 172 | 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 Cross | 95f1ca0 | 2020-10-29 20:47:22 -0700 | [diff] [blame] | 179 | ndkKnownLibs := *getNDKKnownLibs(ctx.Config()) |
Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 180 | sort.Strings(ndkKnownLibs) |
Dan Albert | f164a94 | 2020-06-30 12:46:21 -0700 | [diff] [blame] | 181 | ctx.Strict("NDK_KNOWN_LIBS", strings.Join(ndkKnownLibs, " ")) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 182 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 183 | hostTargets := ctx.Config().Targets[ctx.Config().BuildOS] |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 184 | makeVarsToolchain(ctx, "", hostTargets[0]) |
| 185 | if len(hostTargets) > 1 { |
| 186 | makeVarsToolchain(ctx, "2ND_", hostTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 189 | deviceTargets := ctx.Config().Targets[android.Android] |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 190 | makeVarsToolchain(ctx, "", deviceTargets[0]) |
| 191 | if len(deviceTargets) > 1 { |
| 192 | makeVarsToolchain(ctx, "2ND_", deviceTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 193 | } |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 194 | |
| 195 | makeLlndkVars(ctx) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 198 | func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 199 | target android.Target) { |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 200 | var typePrefix string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 201 | switch target.Os.Class { |
| 202 | case android.Host: |
| 203 | typePrefix = "HOST_" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 204 | case android.Device: |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 205 | typePrefix = "TARGET_" |
| 206 | } |
| 207 | makePrefix := secondPrefix + typePrefix |
| 208 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 209 | toolchain := config.FindToolchain(target.Os, target.Arch) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 210 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 211 | var productExtraCflags string |
| 212 | var productExtraLdflags string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 213 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 214 | hod := "Host" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 215 | if target.Os.Class == android.Device { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 216 | hod = "Device" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 219 | if target.Os.Class == android.Host && ctx.Config().HostStaticBinaries() { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 220 | productExtraLdflags += "-static" |
Dan Willemsen | 06f4533 | 2016-05-16 19:32:33 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 223 | includeFlags, err := ctx.Eval(toolchain.IncludeFlags()) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 224 | if err != nil { |
| 225 | panic(err) |
| 226 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 227 | 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 Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 230 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 231 | if target.Arch.ArchType == android.Arm { |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 232 | flags, err := toolchain.InstructionSetFlags("arm") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 233 | if err != nil { |
| 234 | panic(err) |
| 235 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 236 | ctx.Strict(makePrefix+"arm_CFLAGS", flags) |
| 237 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 238 | flags, err = toolchain.InstructionSetFlags("thumb") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 239 | if err != nil { |
| 240 | panic(err) |
| 241 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 242 | ctx.Strict(makePrefix+"thumb_CFLAGS", flags) |
| 243 | } |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 244 | |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 245 | clangPrefix := secondPrefix + "CLANG_" + typePrefix |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 246 | |
Peter Collingbourne | b0e6143 | 2019-07-22 16:36:06 -0700 | [diff] [blame] | 247 | ctx.Strict(clangPrefix+"TRIPLE", toolchain.ClangTriple()) |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 248 | ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{ |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 249 | toolchain.Cflags(), |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 250 | "${config.CommonGlobalCflags}", |
| 251 | fmt.Sprintf("${config.%sGlobalCflags}", hod), |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 252 | toolchain.ToolchainCflags(), |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 253 | productExtraCflags, |
| 254 | }, " ")) |
| 255 | ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{ |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 256 | "${config.CommonGlobalCppflags}", |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 257 | fmt.Sprintf("${config.%sGlobalCppflags}", hod), |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 258 | toolchain.Cppflags(), |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 259 | }, " ")) |
| 260 | ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ |
| 261 | fmt.Sprintf("${config.%sGlobalLdflags}", hod), |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 262 | toolchain.Ldflags(), |
| 263 | toolchain.ToolchainLdflags(), |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 264 | productExtraLdflags, |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 265 | }, " ")) |
| 266 | ctx.Strict(clangPrefix+"GLOBAL_LLDFLAGS", strings.Join([]string{ |
| 267 | fmt.Sprintf("${config.%sGlobalLldflags}", hod), |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 268 | toolchain.Lldflags(), |
| 269 | toolchain.ToolchainLdflags(), |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 270 | productExtraLdflags, |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 271 | }, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 272 | |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 273 | if target.Os.Class == android.Device { |
Colin Cross | dd5655b | 2022-02-17 11:16:08 -0800 | [diff] [blame] | 274 | for variable, value := range sanitizerVariables { |
| 275 | ctx.Strict(secondPrefix+variable, value) |
| 276 | } |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 279 | // This is used by external/gentoo/... |
| 280 | ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE", |
| 281 | toolchain.ClangTriple()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 282 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 283 | if target.Os == android.Darwin { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 284 | ctx.Strict(makePrefix+"AR", "${config.MacArPath}") |
Dan Willemsen | fdb20d0 | 2018-06-03 16:13:40 -0700 | [diff] [blame] | 285 | ctx.Strict(makePrefix+"NM", "${config.MacToolPath}/nm") |
| 286 | ctx.Strict(makePrefix+"OTOOL", "${config.MacToolPath}/otool") |
| 287 | ctx.Strict(makePrefix+"STRIP", "${config.MacStripPath}") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 288 | } else { |
Stephen Hines | f1addeb | 2018-01-09 23:29:04 -0800 | [diff] [blame] | 289 | ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar") |
Elliott Hughes | a960a0d | 2021-04-21 10:22:55 -0700 | [diff] [blame] | 290 | 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 Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 293 | } |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 294 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 295 | if target.Os.Class == android.Device { |
Elliott Hughes | b6788c0 | 2021-05-04 22:38:05 -0700 | [diff] [blame] | 296 | ctx.Strict(makePrefix+"OBJCOPY", "${config.ClangBin}/llvm-objcopy") |
| 297 | ctx.Strict(makePrefix+"LD", "${config.ClangBin}/lld") |
Chih-Hung Hsieh | 1e7d1bf | 2018-03-15 18:44:57 -0700 | [diff] [blame] | 298 | ctx.Strict(makePrefix+"NDK_TRIPLE", config.NDKTriple(toolchain)) |
Elliott Hughes | cd9ff09 | 2021-05-07 11:55:30 -0700 | [diff] [blame] | 299 | ctx.Strict(makePrefix+"TOOLS_PREFIX", "${config.ClangBin}/llvm-") |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Dan Willemsen | 96ce8e7 | 2019-01-25 17:00:45 -0800 | [diff] [blame] | 302 | if target.Os.Class == android.Host { |
Dan Willemsen | 652b383 | 2017-09-22 13:55:22 -0700 | [diff] [blame] | 303 | ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " ")) |
| 304 | } |
| 305 | |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 306 | ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix()) |
| 307 | ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 308 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 309 | |
| 310 | func 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 Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 345 | |
| 346 | func 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 | } |