github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/config/x86_darwin_host.go (about) 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 config 16 17 import ( 18 "os/exec" 19 "path/filepath" 20 "strings" 21 22 "android/soong/android" 23 ) 24 25 var ( 26 darwinCflags = []string{ 27 "-fdiagnostics-color", 28 29 "-fPIC", 30 "-funwind-tables", 31 32 // Workaround differences in inttypes.h between host and target. 33 //See bug 12708004. 34 "-D__STDC_FORMAT_MACROS", 35 "-D__STDC_CONSTANT_MACROS", 36 37 "-isysroot ${macSdkRoot}", 38 "-mmacosx-version-min=${macMinVersion}", 39 "-DMACOSX_DEPLOYMENT_TARGET=${macMinVersion}", 40 } 41 42 darwinLdflags = []string{ 43 "-isysroot ${macSdkRoot}", 44 "-Wl,-syslibroot,${macSdkRoot}", 45 "-mmacosx-version-min=${macMinVersion}", 46 } 47 48 // Extended cflags 49 darwinX86Cflags = []string{ 50 "-m32", 51 } 52 53 darwinX8664Cflags = []string{ 54 "-m64", 55 } 56 57 darwinX86Ldflags = []string{ 58 "-m32", 59 } 60 61 darwinX8664Ldflags = []string{ 62 "-m64", 63 } 64 65 darwinClangCflags = append(ClangFilterUnknownCflags(darwinCflags), []string{ 66 "-integrated-as", 67 "-fstack-protector-strong", 68 }...) 69 70 darwinX86ClangCflags = append(ClangFilterUnknownCflags(darwinX86Cflags), []string{ 71 "-msse3", 72 }...) 73 74 darwinClangLdflags = ClangFilterUnknownCflags(darwinLdflags) 75 76 darwinX86ClangLdflags = ClangFilterUnknownCflags(darwinX86Ldflags) 77 78 darwinX8664ClangLdflags = ClangFilterUnknownCflags(darwinX8664Ldflags) 79 80 darwinSupportedSdkVersions = []string{ 81 "10.10", 82 "10.11", 83 "10.12", 84 "10.13", 85 } 86 87 darwinAvailableLibraries = append( 88 addPrefix([]string{ 89 "c", 90 "dl", 91 "m", 92 "ncurses", 93 "objc", 94 "pthread", 95 }, "-l"), 96 "-framework AppKit", 97 "-framework CoreFoundation", 98 "-framework Foundation", 99 "-framework IOKit", 100 "-framework Security", 101 ) 102 ) 103 104 const ( 105 darwinGccVersion = "4.2.1" 106 ) 107 108 func init() { 109 pctx.VariableFunc("macSdkPath", func(ctx android.PackageVarContext) string { 110 xcodeselect := ctx.Config().HostSystemTool("xcode-select") 111 bytes, err := exec.Command(xcodeselect, "--print-path").Output() 112 if err != nil { 113 ctx.Errorf("xcode-select failed with: %q", err.Error()) 114 } 115 return strings.TrimSpace(string(bytes)) 116 }) 117 pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string { 118 return xcrunSdk(ctx, "--show-sdk-path") 119 }) 120 pctx.StaticVariable("macMinVersion", "10.8") 121 pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string { 122 return xcrun(ctx, "--find", "ar") 123 }) 124 125 pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string { 126 return xcrun(ctx, "--find", "strip") 127 }) 128 129 pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string { 130 return filepath.Dir(xcrun(ctx, "--find", "ld")) 131 }) 132 133 pctx.StaticVariable("DarwinGccVersion", darwinGccVersion) 134 pctx.SourcePathVariable("DarwinGccRoot", 135 "prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${DarwinGccVersion}") 136 137 pctx.StaticVariable("DarwinGccTriple", "i686-apple-darwin11") 138 139 pctx.StaticVariable("DarwinCflags", strings.Join(darwinCflags, " ")) 140 pctx.StaticVariable("DarwinLdflags", strings.Join(darwinLdflags, " ")) 141 142 pctx.StaticVariable("DarwinClangCflags", strings.Join(darwinClangCflags, " ")) 143 pctx.StaticVariable("DarwinClangLdflags", strings.Join(darwinClangLdflags, " ")) 144 145 // Extended cflags 146 pctx.StaticVariable("DarwinX86Cflags", strings.Join(darwinX86Cflags, " ")) 147 pctx.StaticVariable("DarwinX8664Cflags", strings.Join(darwinX8664Cflags, " ")) 148 pctx.StaticVariable("DarwinX86Ldflags", strings.Join(darwinX86Ldflags, " ")) 149 pctx.StaticVariable("DarwinX8664Ldflags", strings.Join(darwinX8664Ldflags, " ")) 150 151 pctx.StaticVariable("DarwinX86ClangCflags", strings.Join(darwinX86ClangCflags, " ")) 152 pctx.StaticVariable("DarwinX8664ClangCflags", 153 strings.Join(ClangFilterUnknownCflags(darwinX8664Cflags), " ")) 154 pctx.StaticVariable("DarwinX86ClangLdflags", strings.Join(darwinX86ClangLdflags, " ")) 155 pctx.StaticVariable("DarwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " ")) 156 pctx.StaticVariable("DarwinX86YasmFlags", "-f macho -m x86") 157 pctx.StaticVariable("DarwinX8664YasmFlags", "-f macho -m amd64") 158 } 159 160 func xcrun(ctx android.PackageVarContext, args ...string) string { 161 xcrun := ctx.Config().HostSystemTool("xcrun") 162 bytes, err := exec.Command(xcrun, args...).Output() 163 if err != nil { 164 ctx.Errorf("xcrun failed with: %q", err.Error()) 165 } 166 return strings.TrimSpace(string(bytes)) 167 } 168 169 func xcrunSdk(ctx android.PackageVarContext, arg string) string { 170 xcrun := ctx.Config().HostSystemTool("xcrun") 171 if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" { 172 if !inList(selected, darwinSupportedSdkVersions) { 173 ctx.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions) 174 return "" 175 } 176 177 bytes, err := exec.Command(xcrun, "--sdk", "macosx"+selected, arg).Output() 178 if err != nil { 179 ctx.Errorf("MAC_SDK_VERSION %s is not installed", selected) 180 } 181 return strings.TrimSpace(string(bytes)) 182 } 183 184 for _, sdk := range darwinSupportedSdkVersions { 185 bytes, err := exec.Command(xcrun, "--sdk", "macosx"+sdk, arg).Output() 186 if err == nil { 187 return strings.TrimSpace(string(bytes)) 188 } 189 } 190 ctx.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions) 191 return "" 192 } 193 194 type toolchainDarwin struct { 195 cFlags, ldFlags string 196 } 197 198 type toolchainDarwinX86 struct { 199 toolchain32Bit 200 toolchainDarwin 201 } 202 203 type toolchainDarwinX8664 struct { 204 toolchain64Bit 205 toolchainDarwin 206 } 207 208 func (t *toolchainDarwinX86) Name() string { 209 return "x86" 210 } 211 212 func (t *toolchainDarwinX8664) Name() string { 213 return "x86_64" 214 } 215 216 func (t *toolchainDarwin) GccRoot() string { 217 return "${config.DarwinGccRoot}" 218 } 219 220 func (t *toolchainDarwin) GccTriple() string { 221 return "${config.DarwinGccTriple}" 222 } 223 224 func (t *toolchainDarwin) GccVersion() string { 225 return darwinGccVersion 226 } 227 228 func (t *toolchainDarwin) Cflags() string { 229 return "${config.DarwinCflags} ${config.DarwinX86Cflags}" 230 } 231 232 func (t *toolchainDarwinX8664) Cflags() string { 233 return "${config.DarwinCflags} ${config.DarwinX8664Cflags}" 234 } 235 236 func (t *toolchainDarwin) Cppflags() string { 237 return "" 238 } 239 240 func (t *toolchainDarwinX86) Ldflags() string { 241 return "${config.DarwinLdflags} ${config.DarwinX86Ldflags}" 242 } 243 244 func (t *toolchainDarwinX8664) Ldflags() string { 245 return "${config.DarwinLdflags} ${config.DarwinX8664Ldflags}" 246 } 247 248 func (t *toolchainDarwin) IncludeFlags() string { 249 return "" 250 } 251 252 func (t *toolchainDarwinX86) ClangTriple() string { 253 return "i686-apple-darwin" 254 } 255 256 func (t *toolchainDarwinX86) ClangCflags() string { 257 return "${config.DarwinClangCflags} ${config.DarwinX86ClangCflags}" 258 } 259 260 func (t *toolchainDarwinX8664) ClangTriple() string { 261 return "x86_64-apple-darwin" 262 } 263 264 func (t *toolchainDarwinX8664) ClangCflags() string { 265 return "${config.DarwinClangCflags} ${config.DarwinX8664ClangCflags}" 266 } 267 268 func (t *toolchainDarwin) ClangCppflags() string { 269 return "" 270 } 271 272 func (t *toolchainDarwinX86) ClangLdflags() string { 273 return "${config.DarwinClangLdflags} ${config.DarwinX86ClangLdflags}" 274 } 275 276 func (t *toolchainDarwinX8664) ClangLdflags() string { 277 return "${config.DarwinClangLdflags} ${config.DarwinX8664ClangLdflags}" 278 } 279 280 func (t *toolchainDarwinX86) YasmFlags() string { 281 return "${config.DarwinX86YasmFlags}" 282 } 283 284 func (t *toolchainDarwinX8664) YasmFlags() string { 285 return "${config.DarwinX8664YasmFlags}" 286 } 287 288 func (t *toolchainDarwin) ShlibSuffix() string { 289 return ".dylib" 290 } 291 292 func (t *toolchainDarwin) AvailableLibraries() []string { 293 return darwinAvailableLibraries 294 } 295 296 func (t *toolchainDarwin) Bionic() bool { 297 return false 298 } 299 300 func (t *toolchainDarwin) ToolPath() string { 301 return "${config.MacToolPath}" 302 } 303 304 var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{} 305 var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{} 306 307 func darwinX86ToolchainFactory(arch android.Arch) Toolchain { 308 return toolchainDarwinX86Singleton 309 } 310 311 func darwinX8664ToolchainFactory(arch android.Arch) Toolchain { 312 return toolchainDarwinX8664Singleton 313 } 314 315 func init() { 316 registerToolchainFactory(android.Darwin, android.X86, darwinX86ToolchainFactory) 317 registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory) 318 }