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 ( |
| 28 | modulesAddedWallKey = android.NewOnceKey("ModulesAddedWall") |
| 29 | modulesUsingWnoErrorKey = android.NewOnceKey("ModulesUsingWnoError") |
| 30 | modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile") |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 31 | ) |
| 32 | |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 33 | func init() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 34 | android.RegisterMakeVarsProvider(pctx, makeVarsProvider) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 37 | func getNamedMapForConfig(config android.Config, key android.OnceKey) *sync.Map { |
| 38 | return config.Once(key, func() interface{} { |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 39 | return &sync.Map{} |
| 40 | }).(*sync.Map) |
| 41 | } |
| 42 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 43 | func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string { |
| 44 | set := getNamedMapForConfig(ctx.Config(), key) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 45 | 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 | |
| 54 | func 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 Szczepaniak | e6fc507 | 2019-07-12 14:06:23 +0100 | [diff] [blame] | 66 | type notOnHostContext struct { |
| 67 | } |
| 68 | |
| 69 | func (c *notOnHostContext) Host() bool { |
| 70 | return false |
| 71 | } |
| 72 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 73 | func makeVarsProvider(ctx android.MakeVarsContext) { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 74 | vendorPublicLibraries := vendorPublicLibraries(ctx.Config()) |
| 75 | |
Dan Willemsen | 1009119 | 2016-12-14 15:50:54 -0800 | [diff] [blame] | 76 | ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 77 | ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}") |
| 78 | ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}") |
| 79 | ctx.Strict("LLVM_PREBUILTS_PATH", "${config.ClangBin}") |
| 80 | ctx.Strict("CLANG", "${config.ClangBin}/clang") |
| 81 | ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++") |
| 82 | ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as") |
| 83 | ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link") |
Chih-Hung Hsieh | 30485c9 | 2018-06-04 10:37:43 -0700 | [diff] [blame] | 84 | ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy") |
| 85 | ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 86 | ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 87 | ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " ")) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 88 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 89 | ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}") |
| 90 | ctx.Strict("RS_LLVM_PREBUILTS_BASE", "${config.RSClangBase}") |
| 91 | ctx.Strict("RS_LLVM_PREBUILTS_PATH", "${config.RSLLVMPrebuiltsPath}") |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 92 | ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}") |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 93 | ctx.Strict("RS_CLANG", "${config.RSLLVMPrebuiltsPath}/clang") |
| 94 | ctx.Strict("RS_LLVM_AS", "${config.RSLLVMPrebuiltsPath}/llvm-as") |
| 95 | ctx.Strict("RS_LLVM_LINK", "${config.RSLLVMPrebuiltsPath}/llvm-link") |
| 96 | |
Yi Kong | cc80f8d | 2018-06-06 14:42:44 -0700 | [diff] [blame] | 97 | ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ClangExternalCflags}") |
Dan Willemsen | 25cc01f | 2018-10-07 19:42:38 -0700 | [diff] [blame] | 98 | ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideClangGlobalCflags}") |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 99 | ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") |
Dan Willemsen | 97704ed | 2016-07-07 21:40:39 -0700 | [diff] [blame] | 100 | ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " ")) |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 101 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 102 | ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion()) |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 103 | |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 104 | // Filter vendor_public_library that are exported to make |
| 105 | exportedVendorPublicLibraries := []string{} |
Colin Cross | 65494b9 | 2019-02-07 14:25:51 -0800 | [diff] [blame] | 106 | ctx.VisitAllModules(func(module android.Module) { |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 107 | if ccModule, ok := module.(*Module); ok { |
| 108 | baseName := ccModule.BaseModuleName() |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 109 | if inList(baseName, *vendorPublicLibraries) && module.ExportedToMake() { |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 110 | if !inList(baseName, exportedVendorPublicLibraries) { |
| 111 | exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName) |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | }) |
| 116 | sort.Strings(exportedVendorPublicLibraries) |
| 117 | ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " ")) |
| 118 | |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame] | 119 | sort.Strings(lsdumpPaths) |
| 120 | ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " ")) |
| 121 | |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 122 | ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects()) |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 123 | ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWallKey)) |
| 124 | ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey)) |
| 125 | ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey)) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 126 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 127 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " ")) |
| 128 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " ")) |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 129 | |
Evgenii Stepanov | a630233 | 2018-08-28 13:51:05 -0700 | [diff] [blame] | 130 | ctx.Strict("HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(hwasanCflags, " ")) |
Evgenii Stepanov | 109029f | 2018-10-03 18:22:57 -0700 | [diff] [blame] | 131 | ctx.Strict("HWADDRESS_SANITIZER_GLOBAL_OPTIONS", strings.Join(hwasanGlobalOptions, ",")) |
Evgenii Stepanov | a630233 | 2018-08-28 13:51:05 -0700 | [diff] [blame] | 132 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 133 | ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " ")) |
Evgenii Stepanov | dbf1d4f | 2018-08-31 12:54:33 -0700 | [diff] [blame] | 134 | ctx.Strict("CFI_EXTRA_ASFLAGS", strings.Join(cfiAsflags, " ")) |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 135 | ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " ")) |
Vishwath Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 136 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 137 | ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " ")) |
| 138 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 139 | ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion) |
| 140 | ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion) |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 141 | ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion) |
| 142 | ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion) |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 143 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 144 | ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}") |
| 145 | ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks)) |
| 146 | ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}") |
Chih-Hung Hsieh | 9e5d8a6 | 2018-09-21 15:12:44 -0700 | [diff] [blame] | 147 | ctx.Strict("WITH_TIDY_FLAGS", "${config.TidyWithTidyFlags}") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 148 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 149 | ctx.Strict("AIDL_CPP", "${aidlCmd}") |
Ivan Lozano | d094d40 | 2019-11-26 10:32:50 -0800 | [diff] [blame^] | 150 | ctx.Strict("ALLOWED_MANUAL_INTERFACE_PATHS", strings.Join(allowedManualInterfacePaths, " ")) |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 151 | |
Dan Willemsen | c69d715 | 2019-06-19 10:54:50 -0700 | [diff] [blame] | 152 | ctx.Strict("M4", "${m4Cmd}") |
| 153 | |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 154 | ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}") |
| 155 | |
Colin Cross | d2e92da | 2018-09-07 23:16:36 -0700 | [diff] [blame] | 156 | ctx.Strict("SOONG_STRIP_PATH", "${stripPath}") |
| 157 | ctx.Strict("XZ", "${xzCmd}") |
| 158 | |
Steven Moreland | 3cf6306 | 2017-07-18 13:29:35 -0700 | [diff] [blame] | 159 | nativeHelperIncludeFlags, err := ctx.Eval("${config.CommonNativehelperInclude}") |
| 160 | if err != nil { |
| 161 | panic(err) |
| 162 | } |
| 163 | nativeHelperIncludes, nativeHelperSystemIncludes := splitSystemIncludes(ctx, nativeHelperIncludeFlags) |
| 164 | if len(nativeHelperSystemIncludes) > 0 { |
| 165 | panic("native helper may not have any system includes") |
| 166 | } |
| 167 | ctx.Strict("JNI_H_INCLUDE", strings.Join(nativeHelperIncludes, " ")) |
| 168 | |
Colin Cross | 307d145 | 2017-04-30 17:45:07 -0700 | [diff] [blame] | 169 | includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}") |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 170 | if err != nil { |
| 171 | panic(err) |
| 172 | } |
| 173 | includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) |
| 174 | ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " ")) |
| 175 | ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " ")) |
| 176 | |
Dan Willemsen | 65905f8 | 2016-09-14 20:29:05 -0700 | [diff] [blame] | 177 | sort.Strings(ndkMigratedLibs) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 178 | ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " ")) |
| 179 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 180 | hostTargets := ctx.Config().Targets[android.BuildOs] |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 181 | makeVarsToolchain(ctx, "", hostTargets[0]) |
| 182 | if len(hostTargets) > 1 { |
| 183 | makeVarsToolchain(ctx, "2ND_", hostTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 186 | deviceTargets := ctx.Config().Targets[android.Android] |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 187 | makeVarsToolchain(ctx, "", deviceTargets[0]) |
| 188 | if len(deviceTargets) > 1 { |
| 189 | makeVarsToolchain(ctx, "2ND_", deviceTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 193 | func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 194 | target android.Target) { |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 195 | var typePrefix string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 196 | switch target.Os.Class { |
| 197 | case android.Host: |
| 198 | typePrefix = "HOST_" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 199 | case android.Device: |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 200 | typePrefix = "TARGET_" |
| 201 | } |
| 202 | makePrefix := secondPrefix + typePrefix |
| 203 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 204 | toolchain := config.FindToolchain(target.Os, target.Arch) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 205 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 206 | var productExtraCflags string |
| 207 | var productExtraLdflags string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 208 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 209 | hod := "Host" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 210 | if target.Os.Class == android.Device { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 211 | hod = "Device" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 214 | if target.Os.Class == android.Host && ctx.Config().HostStaticBinaries() { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 215 | productExtraLdflags += "-static" |
Dan Willemsen | 06f4533 | 2016-05-16 19:32:33 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 218 | includeFlags, err := ctx.Eval(toolchain.IncludeFlags()) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 219 | if err != nil { |
| 220 | panic(err) |
| 221 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 222 | includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) |
| 223 | ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " ")) |
| 224 | ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 225 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 226 | if target.Arch.ArchType == android.Arm { |
Dan Willemsen | 25cc01f | 2018-10-07 19:42:38 -0700 | [diff] [blame] | 227 | flags, err := toolchain.ClangInstructionSetFlags("arm") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 228 | if err != nil { |
| 229 | panic(err) |
| 230 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 231 | ctx.Strict(makePrefix+"arm_CFLAGS", flags) |
| 232 | |
Dan Willemsen | 25cc01f | 2018-10-07 19:42:38 -0700 | [diff] [blame] | 233 | flags, err = toolchain.ClangInstructionSetFlags("thumb") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 234 | if err != nil { |
| 235 | panic(err) |
| 236 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 237 | ctx.Strict(makePrefix+"thumb_CFLAGS", flags) |
| 238 | } |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 239 | |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 240 | clangPrefix := secondPrefix + "CLANG_" + typePrefix |
Peter Collingbourne | b0e6143 | 2019-07-22 16:36:06 -0700 | [diff] [blame] | 241 | clangExtras := "-B" + config.ToolPath(toolchain) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 242 | |
Peter Collingbourne | b0e6143 | 2019-07-22 16:36:06 -0700 | [diff] [blame] | 243 | ctx.Strict(clangPrefix+"TRIPLE", toolchain.ClangTriple()) |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 244 | ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{ |
| 245 | toolchain.ClangCflags(), |
| 246 | "${config.CommonClangGlobalCflags}", |
| 247 | fmt.Sprintf("${config.%sClangGlobalCflags}", hod), |
| 248 | toolchain.ToolchainClangCflags(), |
| 249 | clangExtras, |
| 250 | productExtraCflags, |
| 251 | }, " ")) |
| 252 | ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{ |
| 253 | "${config.CommonClangGlobalCppflags}", |
| 254 | fmt.Sprintf("${config.%sGlobalCppflags}", hod), |
| 255 | toolchain.ClangCppflags(), |
| 256 | }, " ")) |
| 257 | ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ |
| 258 | fmt.Sprintf("${config.%sGlobalLdflags}", hod), |
| 259 | toolchain.ClangLdflags(), |
| 260 | toolchain.ToolchainClangLdflags(), |
| 261 | productExtraLdflags, |
| 262 | clangExtras, |
| 263 | }, " ")) |
| 264 | ctx.Strict(clangPrefix+"GLOBAL_LLDFLAGS", strings.Join([]string{ |
| 265 | fmt.Sprintf("${config.%sGlobalLldflags}", hod), |
| 266 | toolchain.ClangLldflags(), |
| 267 | toolchain.ToolchainClangLdflags(), |
| 268 | productExtraLdflags, |
| 269 | clangExtras, |
| 270 | }, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 271 | |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 272 | if target.Os.Class == android.Device { |
| 273 | ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so")) |
| 274 | ctx.Strict(secondPrefix+"HWADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.HWAddressSanitizerRuntimeLibrary(toolchain), ".so")) |
| 275 | ctx.Strict(secondPrefix+"HWADDRESS_SANITIZER_STATIC_LIBRARY", strings.TrimSuffix(config.HWAddressSanitizerStaticLibrary(toolchain), ".a")) |
| 276 | ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so")) |
| 277 | ctx.Strict(secondPrefix+"UBSAN_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), ".a")) |
| 278 | ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so")) |
| 279 | ctx.Strict(secondPrefix+"SCUDO_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoRuntimeLibrary(toolchain), ".so")) |
Kostya Kortchinsky | ad73b2e | 2018-10-11 08:38:39 -0700 | [diff] [blame] | 280 | ctx.Strict(secondPrefix+"SCUDO_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoMinimalRuntimeLibrary(toolchain), ".so")) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Dan Willemsen | f640dbc | 2018-09-04 22:25:59 -0700 | [diff] [blame] | 283 | // This is used by external/gentoo/... |
| 284 | ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE", |
| 285 | toolchain.ClangTriple()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 286 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 287 | if target.Os == android.Darwin { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 288 | ctx.Strict(makePrefix+"AR", "${config.MacArPath}") |
Dan Willemsen | fdb20d0 | 2018-06-03 16:13:40 -0700 | [diff] [blame] | 289 | ctx.Strict(makePrefix+"NM", "${config.MacToolPath}/nm") |
| 290 | ctx.Strict(makePrefix+"OTOOL", "${config.MacToolPath}/otool") |
| 291 | ctx.Strict(makePrefix+"STRIP", "${config.MacStripPath}") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 292 | } else { |
Stephen Hines | f1addeb | 2018-01-09 23:29:04 -0800 | [diff] [blame] | 293 | ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 294 | ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf")) |
| 295 | ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm")) |
Dan Willemsen | fdb20d0 | 2018-06-03 16:13:40 -0700 | [diff] [blame] | 296 | ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip")) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 297 | } |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 298 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 299 | if target.Os.Class == android.Device { |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 300 | ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy")) |
| 301 | ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 302 | ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion()) |
Chih-Hung Hsieh | 1e7d1bf | 2018-03-15 18:44:57 -0700 | [diff] [blame] | 303 | ctx.Strict(makePrefix+"NDK_TRIPLE", config.NDKTriple(toolchain)) |
Dan Willemsen | 25cc01f | 2018-10-07 19:42:38 -0700 | [diff] [blame] | 304 | ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, "")) |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Dan Willemsen | 96ce8e7 | 2019-01-25 17:00:45 -0800 | [diff] [blame] | 307 | if target.Os.Class == android.Host { |
Dan Willemsen | 652b383 | 2017-09-22 13:55:22 -0700 | [diff] [blame] | 308 | ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " ")) |
| 309 | } |
| 310 | |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 311 | ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix()) |
| 312 | ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 313 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 314 | |
| 315 | func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) { |
| 316 | flags, err := ctx.Eval(val) |
| 317 | if err != nil { |
| 318 | panic(err) |
| 319 | } |
| 320 | |
| 321 | extract := func(flags string, dirs []string, prefix string) (string, []string, bool) { |
| 322 | if strings.HasPrefix(flags, prefix) { |
| 323 | flags = strings.TrimPrefix(flags, prefix) |
| 324 | flags = strings.TrimLeft(flags, " ") |
| 325 | s := strings.SplitN(flags, " ", 2) |
| 326 | dirs = append(dirs, s[0]) |
| 327 | if len(s) > 1 { |
| 328 | return strings.TrimLeft(s[1], " "), dirs, true |
| 329 | } |
| 330 | return "", dirs, true |
| 331 | } else { |
| 332 | return flags, dirs, false |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | flags = strings.TrimLeft(flags, " ") |
| 337 | for flags != "" { |
| 338 | found := false |
| 339 | flags, includes, found = extract(flags, includes, "-I") |
| 340 | if !found { |
| 341 | flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ") |
| 342 | } |
| 343 | if !found { |
| 344 | panic(fmt.Errorf("Unexpected flag in %q", flags)) |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | return includes, systemIncludes |
| 349 | } |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 350 | |
| 351 | func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string { |
| 352 | rets := make([]string, len(checks)) |
| 353 | for i, check := range config.DefaultLocalTidyChecks { |
| 354 | rets[i] = check.PathPrefix + ":" + check.Checks |
| 355 | } |
| 356 | return strings.Join(rets, " ") |
| 357 | } |