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" |
| 21 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 22 | "android/soong/android" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 23 | "android/soong/cc/config" |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | func init() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 27 | android.RegisterMakeVarsProvider(pctx, makeVarsProvider) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 28 | } |
| 29 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 30 | func makeVarsProvider(ctx android.MakeVarsContext) { |
Dan Willemsen | 1009119 | 2016-12-14 15:50:54 -0800 | [diff] [blame] | 31 | ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 32 | ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}") |
| 33 | ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}") |
| 34 | ctx.Strict("LLVM_PREBUILTS_PATH", "${config.ClangBin}") |
| 35 | ctx.Strict("CLANG", "${config.ClangBin}/clang") |
| 36 | ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++") |
| 37 | ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as") |
| 38 | ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link") |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 39 | ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy") |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 40 | ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " ")) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 41 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 42 | ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}") |
| 43 | ctx.Strict("RS_LLVM_PREBUILTS_BASE", "${config.RSClangBase}") |
| 44 | ctx.Strict("RS_LLVM_PREBUILTS_PATH", "${config.RSLLVMPrebuiltsPath}") |
| 45 | ctx.Strict("RS_CLANG", "${config.RSLLVMPrebuiltsPath}/clang") |
| 46 | ctx.Strict("RS_LLVM_AS", "${config.RSLLVMPrebuiltsPath}/llvm-as") |
| 47 | ctx.Strict("RS_LLVM_LINK", "${config.RSLLVMPrebuiltsPath}/llvm-link") |
| 48 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 49 | ctx.Strict("GLOBAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}") |
| 50 | ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.ClangExtraNoOverrideCflags}") |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 51 | ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "") |
| 52 | ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") |
Dan Willemsen | 97704ed | 2016-07-07 21:40:39 -0700 | [diff] [blame] | 53 | ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " ")) |
Dan Willemsen | 5efc706 | 2016-05-27 15:23:38 -0700 | [diff] [blame] | 54 | |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 55 | if ctx.Config().ProductVariables.DeviceVndkVersion != nil { |
| 56 | ctx.Strict("BOARD_VNDK_VERSION", *ctx.Config().ProductVariables.DeviceVndkVersion) |
| 57 | } else { |
| 58 | ctx.Strict("BOARD_VNDK_VERSION", "") |
| 59 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 60 | |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 61 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", asanCflags) |
| 62 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", asanLdflags) |
| 63 | ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", asanLibs) |
| 64 | |
Vishwath Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 65 | ctx.Strict("CFI_EXTRA_CFLAGS", cfiCflags) |
| 66 | ctx.Strict("CFI_EXTRA_LDFLAGS", cfiLdflags) |
| 67 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 68 | ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion) |
| 69 | ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion) |
| 70 | ctx.Strict("DEFAULT_GCC_CPP_STD_VERSION", config.GccCppStdVersion) |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 71 | ctx.Strict("EXPERIMENTAL_C_STD_VERSION", config.ExperimentalCStdVersion) |
| 72 | ctx.Strict("EXPERIMENTAL_CPP_STD_VERSION", config.ExperimentalCppStdVersion) |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 73 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 74 | ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}") |
| 75 | ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks)) |
| 76 | ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}") |
| 77 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 78 | ctx.Strict("AIDL_CPP", "${aidlCmd}") |
| 79 | |
Colin Cross | 307d145 | 2017-04-30 17:45:07 -0700 | [diff] [blame] | 80 | includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}") |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 81 | if err != nil { |
| 82 | panic(err) |
| 83 | } |
| 84 | includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) |
| 85 | ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " ")) |
| 86 | ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " ")) |
| 87 | |
Dan Willemsen | 65905f8 | 2016-09-14 20:29:05 -0700 | [diff] [blame] | 88 | sort.Strings(ndkMigratedLibs) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 89 | ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " ")) |
| 90 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 91 | hostTargets := ctx.Config().Targets[android.Host] |
| 92 | makeVarsToolchain(ctx, "", hostTargets[0]) |
| 93 | if len(hostTargets) > 1 { |
| 94 | makeVarsToolchain(ctx, "2ND_", hostTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 97 | crossTargets := ctx.Config().Targets[android.HostCross] |
| 98 | if len(crossTargets) > 0 { |
| 99 | makeVarsToolchain(ctx, "", crossTargets[0]) |
| 100 | if len(crossTargets) > 1 { |
| 101 | makeVarsToolchain(ctx, "2ND_", crossTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 105 | deviceTargets := ctx.Config().Targets[android.Device] |
| 106 | makeVarsToolchain(ctx, "", deviceTargets[0]) |
| 107 | if len(deviceTargets) > 1 { |
| 108 | makeVarsToolchain(ctx, "2ND_", deviceTargets[1]) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 112 | func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 113 | target android.Target) { |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 114 | var typePrefix string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 115 | switch target.Os.Class { |
| 116 | case android.Host: |
| 117 | typePrefix = "HOST_" |
| 118 | case android.HostCross: |
| 119 | typePrefix = "HOST_CROSS_" |
| 120 | case android.Device: |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 121 | typePrefix = "TARGET_" |
| 122 | } |
| 123 | makePrefix := secondPrefix + typePrefix |
| 124 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 125 | toolchain := config.FindToolchain(target.Os, target.Arch) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 126 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 127 | var productExtraCflags string |
| 128 | var productExtraLdflags string |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 129 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 130 | hod := "Host" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 131 | if target.Os.Class == android.Device { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 132 | hod = "Device" |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | if target.Os.Class == android.Device && Bool(ctx.Config().ProductVariables.Brillo) { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 136 | productExtraCflags += "-D__BRILLO__" |
| 137 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 138 | if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 139 | productExtraLdflags += "-static" |
Dan Willemsen | 06f4533 | 2016-05-16 19:32:33 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 142 | ctx.Strict(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{ |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 143 | toolchain.Cflags(), |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 144 | "${config.CommonGlobalCflags}", |
| 145 | fmt.Sprintf("${config.%sGlobalCflags}", hod), |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 146 | toolchain.ToolchainCflags(), |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 147 | productExtraCflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 148 | }, " ")) |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 149 | ctx.Strict(makePrefix+"GLOBAL_CONLYFLAGS", strings.Join([]string{ |
| 150 | "${config.CommonGlobalConlyflags}", |
| 151 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 152 | ctx.Strict(makePrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 153 | "${config.CommonGlobalCppflags}", |
Dan Willemsen | 216a459 | 2016-05-16 23:56:53 -0700 | [diff] [blame] | 154 | toolchain.Cppflags(), |
| 155 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 156 | ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 157 | toolchain.Ldflags(), |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 158 | toolchain.ToolchainLdflags(), |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 159 | productExtraLdflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 160 | }, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 161 | |
| 162 | includeFlags, err := ctx.Eval(toolchain.IncludeFlags()) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 163 | if err != nil { |
| 164 | panic(err) |
| 165 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 166 | includes, systemIncludes := splitSystemIncludes(ctx, includeFlags) |
| 167 | ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " ")) |
| 168 | ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 169 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 170 | if target.Arch.ArchType == android.Arm { |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 171 | flags, err := toolchain.InstructionSetFlags("arm") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 172 | if err != nil { |
| 173 | panic(err) |
| 174 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 175 | ctx.Strict(makePrefix+"arm_CFLAGS", flags) |
| 176 | |
| 177 | flags, err = toolchain.InstructionSetFlags("thumb") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 178 | if err != nil { |
| 179 | panic(err) |
| 180 | } |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 181 | ctx.Strict(makePrefix+"thumb_CFLAGS", flags) |
| 182 | } |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 183 | |
| 184 | if toolchain.ClangSupported() { |
| 185 | clangPrefix := secondPrefix + "CLANG_" + typePrefix |
Dan Willemsen | 3772da1 | 2016-05-16 18:01:46 -0700 | [diff] [blame] | 186 | clangExtras := "-target " + toolchain.ClangTriple() |
Dan Willemsen | 300151b | 2017-03-13 12:40:30 -0700 | [diff] [blame] | 187 | clangExtras += " -B" + config.ToolPath(toolchain) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 188 | |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 189 | ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{ |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 190 | toolchain.ClangCflags(), |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 191 | "${config.CommonClangGlobalCflags}", |
| 192 | fmt.Sprintf("${config.%sClangGlobalCflags}", hod), |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 193 | toolchain.ToolchainClangCflags(), |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 194 | clangExtras, |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 195 | productExtraCflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 196 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 197 | ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 198 | "${config.CommonClangGlobalCppflags}", |
Dan Willemsen | 216a459 | 2016-05-16 23:56:53 -0700 | [diff] [blame] | 199 | toolchain.ClangCppflags(), |
| 200 | }, " ")) |
Dan Willemsen | 9598e10 | 2016-05-19 16:59:04 -0700 | [diff] [blame] | 201 | ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ |
Dan Willemsen | d26a713 | 2016-05-18 23:00:57 -0700 | [diff] [blame] | 202 | toolchain.ClangLdflags(), |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 203 | toolchain.ToolchainClangLdflags(), |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 204 | productExtraLdflags, |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 205 | clangExtras, |
| 206 | }, " ")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 207 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 208 | if target.Os.Class == android.Device { |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 209 | ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so")) |
| 210 | 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] | 211 | ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // This is used by external/gentoo/... |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 215 | ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE", |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 216 | toolchain.ClangTriple()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc")) |
| 220 | ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++")) |
| 221 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 222 | if target.Os == android.Darwin { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 223 | ctx.Strict(makePrefix+"AR", "${config.MacArPath}") |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 224 | } else { |
| 225 | ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar")) |
| 226 | ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf")) |
| 227 | ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm")) |
| 228 | } |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 229 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 230 | if target.Os == android.Windows { |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 231 | ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump")) |
| 232 | } |
| 233 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 234 | if target.Os.Class == android.Device { |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 235 | ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy")) |
| 236 | ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld")) |
| 237 | ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 238 | ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion()) |
| 239 | ctx.Strict(makePrefix+"NDK_GCC_VERSION", toolchain.GccVersion()) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 240 | ctx.Strict(makePrefix+"NDK_TRIPLE", toolchain.ClangTriple()) |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Dan Willemsen | 0bd5887 | 2016-05-26 15:23:07 -0700 | [diff] [blame] | 243 | ctx.Strict(makePrefix+"TOOLCHAIN_ROOT", toolchain.GccRoot()) |
Dan Willemsen | 73d21f2 | 2016-05-16 14:22:56 -0700 | [diff] [blame] | 244 | ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, "")) |
Dan Willemsen | 558e517 | 2016-05-19 16:58:46 -0700 | [diff] [blame] | 245 | ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix()) |
| 246 | ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix()) |
Dan Willemsen | 4b7d5de | 2016-01-12 23:20:28 -0800 | [diff] [blame] | 247 | } |
Colin Cross | 10c78c6 | 2016-07-20 12:14:19 -0700 | [diff] [blame] | 248 | |
| 249 | func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) { |
| 250 | flags, err := ctx.Eval(val) |
| 251 | if err != nil { |
| 252 | panic(err) |
| 253 | } |
| 254 | |
| 255 | extract := func(flags string, dirs []string, prefix string) (string, []string, bool) { |
| 256 | if strings.HasPrefix(flags, prefix) { |
| 257 | flags = strings.TrimPrefix(flags, prefix) |
| 258 | flags = strings.TrimLeft(flags, " ") |
| 259 | s := strings.SplitN(flags, " ", 2) |
| 260 | dirs = append(dirs, s[0]) |
| 261 | if len(s) > 1 { |
| 262 | return strings.TrimLeft(s[1], " "), dirs, true |
| 263 | } |
| 264 | return "", dirs, true |
| 265 | } else { |
| 266 | return flags, dirs, false |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | flags = strings.TrimLeft(flags, " ") |
| 271 | for flags != "" { |
| 272 | found := false |
| 273 | flags, includes, found = extract(flags, includes, "-I") |
| 274 | if !found { |
| 275 | flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ") |
| 276 | } |
| 277 | if !found { |
| 278 | panic(fmt.Errorf("Unexpected flag in %q", flags)) |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return includes, systemIncludes |
| 283 | } |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 284 | |
| 285 | func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string { |
| 286 | rets := make([]string, len(checks)) |
| 287 | for i, check := range config.DefaultLocalTidyChecks { |
| 288 | rets[i] = check.PathPrefix + ":" + check.Checks |
| 289 | } |
| 290 | return strings.Join(rets, " ") |
| 291 | } |