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 | |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 27 | const ( |
Pirama Arumuga Nainar | 28316d4 | 2018-01-29 09:18:45 -0800 | [diff] [blame] | 28 | modulesAddedWall = "ModulesAddedWall" |
| 29 | modulesUsingWnoError = "ModulesUsingWnoError" |
| 30 | modulesMissingProfileFile = "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 | |
Pirama Arumuga Nainar | 28316d4 | 2018-01-29 09:18:45 -0800 | [diff] [blame] | 37 | func getNamedMapForConfig(config android.Config, name string) *sync.Map { |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 38 | return config.Once(name, func() interface{} { |
| 39 | return &sync.Map{} |
| 40 | }).(*sync.Map) |
| 41 | } |
| 42 | |
| 43 | func makeStringOfKeys(ctx android.MakeVarsContext, setName string) string { |
Pirama Arumuga Nainar | 28316d4 | 2018-01-29 09:18:45 -0800 | [diff] [blame] | 44 | set := getNamedMapForConfig(ctx.Config(), setName) |
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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 66 | func makeVarsProvider(ctx android.MakeVarsContext) { |
Dan Willemsen | 1009119 | 2016-12-14 15:50:54 -0800 | [diff] [blame] | 67 | ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 68 | 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 Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 75 | ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 76 | ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " ")) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 77 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 78 | 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 Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 81 | ctx.Strict("RS_LLVM_INCLUDES", "${config.RSIncludePath}") |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 82 | 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 Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 86 | ctx.Strict("GLOBAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}") |
| 87 | ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.ClangExtraNoOverrideCflags}") |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 88 | ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "") |
| 89 | ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") |
Dan Willemsen | 97704ed | 2016-07-07 21:40:39 -0700 | [diff] [blame] | 90 | ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " ")) |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 91 | |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 92 | 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 Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 97 | |
Jiyong Park | ab0fd5f | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 98 | 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 Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 101 | ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " ")) |
Jiyong Park | ab0fd5f | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 102 | |
Jayant Chowdhary | dcd33b6 | 2018-02-23 16:43:23 -0800 | [diff] [blame^] | 103 | sort.Strings(lsdumpPaths) |
| 104 | ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " ")) |
| 105 | |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 106 | ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects()) |
| 107 | ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWall)) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 108 | ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoError)) |
Pirama Arumuga Nainar | 28316d4 | 2018-01-29 09:18:45 -0800 | [diff] [blame] | 109 | ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFile)) |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 110 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 111 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " ")) |
| 112 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " ")) |
| 113 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " ")) |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 114 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 115 | ctx.Strict("CFI_EXTRA_CFLAGS", strings.Join(cfiCflags, " ")) |
| 116 | ctx.Strict("CFI_EXTRA_LDFLAGS", strings.Join(cfiLdflags, " ")) |
Vishwath Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 117 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 118 | ctx.Strict("INTEGER_OVERFLOW_EXTRA_CFLAGS", strings.Join(intOverflowCflags, " ")) |
| 119 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 120 | ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion) |
| 121 | ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion) |
| 122 | ctx.Strict("DEFAULT_GCC_CPP_STD_VERSION", config.GccCppStdVersion) |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 123 | ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion) |
| 124 | ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion) |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 125 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 126 | ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}") |
| 127 | ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks)) |
| 128 | ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}") |
| 129 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 130 | ctx.Strict("AIDL_CPP", "${aidlCmd}") |
| 131 | |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 132 | ctx.Strict("RS_GLOBAL_INCLUDES", "${config.RsGlobalIncludes}") |
| 133 | |
Steven Moreland | 3cf6306 | 2017-07-18 13:29:35 -0700 | [diff] [blame] | 134 | nativeHelperIncludeFlags, err := ctx.Eval("${config.CommonNativehelperInclude}") |
| 135 | if err != nil { |
| 136 | panic(err) |
| 137 | } |
| 138 | nativeHelperIncludes, nativeHelperSystemIncludes := splitSystemIncludes(ctx, nativeHelperIncludeFlags) |
| 139 | if len(nativeHelperSystemIncludes) > 0 { |
| 140 | panic("native helper may not have any system includes") |
| 141 | } |
| 142 | ctx.Strict("JNI_H_INCLUDE", strings.Join(nativeHelperIncludes, " ")) |
| 143 | |
Colin Cross | 307d145 | 2017-04-30 17:45:07 -0700 | [diff] [blame] | 144 | includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}") |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 145 | if err != nil { |
| 146 | panic(err) |
| 147 | } |
| 148 | includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) |
| 149 | ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " ")) |
| 150 | ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " ")) |
| 151 | |
Dan Willemsen | 65905f8 | 2016-09-14 20:29:05 -0700 | [diff] [blame] | 152 | sort.Strings(ndkMigratedLibs) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 153 | ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " ")) |
| 154 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 155 | hostTargets := ctx.Config().Targets[android.Host] |
| 156 | makeVarsToolchain(ctx, "", hostTargets[0]) |
| 157 | if len(hostTargets) > 1 { |
| 158 | makeVarsToolchain(ctx, "2ND_", hostTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 161 | crossTargets := ctx.Config().Targets[android.HostCross] |
| 162 | if len(crossTargets) > 0 { |
| 163 | makeVarsToolchain(ctx, "", crossTargets[0]) |
| 164 | if len(crossTargets) > 1 { |
| 165 | makeVarsToolchain(ctx, "2ND_", crossTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 169 | deviceTargets := ctx.Config().Targets[android.Device] |
| 170 | makeVarsToolchain(ctx, "", deviceTargets[0]) |
| 171 | if len(deviceTargets) > 1 { |
| 172 | makeVarsToolchain(ctx, "2ND_", deviceTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 176 | func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 177 | target android.Target) { |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 178 | var typePrefix string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 179 | switch target.Os.Class { |
| 180 | case android.Host: |
| 181 | typePrefix = "HOST_" |
| 182 | case android.HostCross: |
| 183 | typePrefix = "HOST_CROSS_" |
| 184 | case android.Device: |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 185 | typePrefix = "TARGET_" |
| 186 | } |
| 187 | makePrefix := secondPrefix + typePrefix |
| 188 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 189 | toolchain := config.FindToolchain(target.Os, target.Arch) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 190 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 191 | var productExtraCflags string |
| 192 | var productExtraLdflags string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 193 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 194 | hod := "Host" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 195 | if target.Os.Class == android.Device { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 196 | hod = "Device" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if target.Os.Class == android.Device && Bool(ctx.Config().ProductVariables.Brillo) { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 200 | productExtraCflags += "-D__BRILLO__" |
| 201 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 202 | if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 203 | productExtraLdflags += "-static" |
Dan Willemsen | 06f4533 | 2016-05-16 19:32:33 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 206 | ctx.Strict(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{ |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 207 | toolchain.Cflags(), |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 208 | "${config.CommonGlobalCflags}", |
| 209 | fmt.Sprintf("${config.%sGlobalCflags}", hod), |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 210 | toolchain.ToolchainCflags(), |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 211 | productExtraCflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 212 | }, " ")) |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 213 | ctx.Strict(makePrefix+"GLOBAL_CONLYFLAGS", strings.Join([]string{ |
| 214 | "${config.CommonGlobalConlyflags}", |
| 215 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 216 | ctx.Strict(makePrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 217 | "${config.CommonGlobalCppflags}", |
Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 218 | fmt.Sprintf("${config.%sGlobalCppflags}", hod), |
Dan Willemsen | 216a459 | 2016-05-16 23:56:53 -0700 | [diff] [blame] | 219 | toolchain.Cppflags(), |
| 220 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 221 | ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 222 | fmt.Sprintf("${config.%sGlobalLdflags}", hod), |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 223 | toolchain.Ldflags(), |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 224 | toolchain.ToolchainLdflags(), |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 225 | productExtraLdflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 226 | }, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 227 | |
| 228 | includeFlags, err := ctx.Eval(toolchain.IncludeFlags()) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 229 | if err != nil { |
| 230 | panic(err) |
| 231 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 232 | includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) |
| 233 | ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " ")) |
| 234 | ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 235 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 236 | if target.Arch.ArchType == android.Arm { |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 237 | flags, err := toolchain.InstructionSetFlags("arm") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 238 | if err != nil { |
| 239 | panic(err) |
| 240 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 241 | ctx.Strict(makePrefix+"arm_CFLAGS", flags) |
| 242 | |
| 243 | flags, err = toolchain.InstructionSetFlags("thumb") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 244 | if err != nil { |
| 245 | panic(err) |
| 246 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 247 | ctx.Strict(makePrefix+"thumb_CFLAGS", flags) |
| 248 | } |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 249 | |
| 250 | if toolchain.ClangSupported() { |
| 251 | clangPrefix := secondPrefix + "CLANG_" + typePrefix |
Dan Willemsen | 3772da1 | 2016-05-16 18:01:46 -0700 | [diff] [blame] | 252 | clangExtras := "-target " + toolchain.ClangTriple() |
Dan Willemsen | 300151b | 2017-03-13 12:40:30 -0700 | [diff] [blame] | 253 | clangExtras += " -B" + config.ToolPath(toolchain) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 254 | |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 255 | ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{ |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 256 | toolchain.ClangCflags(), |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 257 | "${config.CommonClangGlobalCflags}", |
| 258 | fmt.Sprintf("${config.%sClangGlobalCflags}", hod), |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 259 | toolchain.ToolchainClangCflags(), |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 260 | clangExtras, |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 261 | productExtraCflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 262 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 263 | ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 264 | "${config.CommonClangGlobalCppflags}", |
Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 265 | fmt.Sprintf("${config.%sGlobalCppflags}", hod), |
Dan Willemsen | 216a459 | 2016-05-16 23:56:53 -0700 | [diff] [blame] | 266 | toolchain.ClangCppflags(), |
| 267 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 268 | ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 269 | fmt.Sprintf("${config.%sGlobalLdflags}", hod), |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 270 | toolchain.ClangLdflags(), |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 271 | toolchain.ToolchainClangLdflags(), |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 272 | productExtraLdflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 273 | clangExtras, |
| 274 | }, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 275 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 276 | if target.Os.Class == android.Device { |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 277 | ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so")) |
| 278 | ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so")) |
Pirama Arumuga Nainar | 16b626b | 2017-03-27 11:00:38 -0700 | [diff] [blame] | 279 | ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // This is used by external/gentoo/... |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 283 | ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE", |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 284 | toolchain.ClangTriple()) |
Dan Willemsen | 7b6d9b9 | 2017-11-29 20:48:03 -0800 | [diff] [blame] | 285 | |
| 286 | ctx.Strict(makePrefix+"CLANG_SUPPORTED", "true") |
| 287 | } else { |
| 288 | ctx.Strict(makePrefix+"CLANG_SUPPORTED", "") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc")) |
| 292 | ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++")) |
| 293 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 294 | if target.Os == android.Darwin { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 295 | ctx.Strict(makePrefix+"AR", "${config.MacArPath}") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 296 | } else { |
Stephen Hines | f1addeb | 2018-01-09 23:29:04 -0800 | [diff] [blame] | 297 | ctx.Strict(makePrefix+"AR", "${config.ClangBin}/llvm-ar") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 298 | ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf")) |
| 299 | ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm")) |
| 300 | } |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 301 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 302 | if target.Os == android.Windows { |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 303 | ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump")) |
| 304 | } |
| 305 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 306 | if target.Os.Class == android.Device { |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 307 | ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy")) |
| 308 | ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld")) |
| 309 | ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 310 | ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion()) |
| 311 | ctx.Strict(makePrefix+"NDK_GCC_VERSION", toolchain.GccVersion()) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 312 | ctx.Strict(makePrefix+"NDK_TRIPLE", toolchain.ClangTriple()) |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Dan Willemsen | 652b383 | 2017-09-22 13:55:22 -0700 | [diff] [blame] | 315 | if target.Os.Class == android.Host || target.Os.Class == android.HostCross { |
| 316 | ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " ")) |
| 317 | } |
| 318 | |
Dan Willemsen | 0bd5887 | 2016-05-26 15:23:07 -0700 | [diff] [blame] | 319 | ctx.Strict(makePrefix+"TOOLCHAIN_ROOT", toolchain.GccRoot()) |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 320 | ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, "")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 321 | ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix()) |
| 322 | ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 323 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 324 | |
| 325 | func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) { |
| 326 | flags, err := ctx.Eval(val) |
| 327 | if err != nil { |
| 328 | panic(err) |
| 329 | } |
| 330 | |
| 331 | extract := func(flags string, dirs []string, prefix string) (string, []string, bool) { |
| 332 | if strings.HasPrefix(flags, prefix) { |
| 333 | flags = strings.TrimPrefix(flags, prefix) |
| 334 | flags = strings.TrimLeft(flags, " ") |
| 335 | s := strings.SplitN(flags, " ", 2) |
| 336 | dirs = append(dirs, s[0]) |
| 337 | if len(s) > 1 { |
| 338 | return strings.TrimLeft(s[1], " "), dirs, true |
| 339 | } |
| 340 | return "", dirs, true |
| 341 | } else { |
| 342 | return flags, dirs, false |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | flags = strings.TrimLeft(flags, " ") |
| 347 | for flags != "" { |
| 348 | found := false |
| 349 | flags, includes, found = extract(flags, includes, "-I") |
| 350 | if !found { |
| 351 | flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ") |
| 352 | } |
| 353 | if !found { |
| 354 | panic(fmt.Errorf("Unexpected flag in %q", flags)) |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | return includes, systemIncludes |
| 359 | } |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 360 | |
| 361 | func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string { |
| 362 | rets := make([]string, len(checks)) |
| 363 | for i, check := range config.DefaultLocalTidyChecks { |
| 364 | rets[i] = check.PathPrefix + ":" + check.Checks |
| 365 | } |
| 366 | return strings.Join(rets, " ") |
| 367 | } |