123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- // Copyright 2016 Google Inc. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package config
- import (
- "fmt"
- "os/exec"
- "path/filepath"
- "strings"
- "sync"
- "android/soong/android"
- )
- var (
- darwinCflags = []string{
- "-fPIC",
- "-funwind-tables",
- // Workaround differences in inttypes.h between host and target.
- //See bug 12708004.
- "-D__STDC_FORMAT_MACROS",
- "-D__STDC_CONSTANT_MACROS",
- "-isysroot ${macSdkRoot}",
- "-mmacosx-version-min=${macMinVersion}",
- "-DMACOSX_DEPLOYMENT_TARGET=${macMinVersion}",
- "-m64",
- "-integrated-as",
- "-fstack-protector-strong",
- }
- darwinLdflags = []string{
- "-isysroot ${macSdkRoot}",
- "-Wl,-syslibroot,${macSdkRoot}",
- "-mmacosx-version-min=${macMinVersion}",
- "-m64",
- "-mlinker-version=305",
- }
- darwinSupportedSdkVersions = []string{
- "10.13",
- "10.14",
- "10.15",
- "11.0",
- "11.1",
- "11.3",
- }
- darwinAvailableLibraries = append(
- addPrefix([]string{
- "c",
- "dl",
- "m",
- "ncurses",
- "objc",
- "pthread",
- }, "-l"),
- "-framework AppKit",
- "-framework CoreFoundation",
- "-framework Foundation",
- "-framework IOKit",
- "-framework Security",
- "-framework SystemConfiguration",
- )
- )
- const (
- darwinGccVersion = "4.2.1"
- )
- func init() {
- pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string {
- return getMacTools(ctx).sdkRoot
- })
- pctx.StaticVariable("macMinVersion", "10.13")
- pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string {
- return getMacTools(ctx).arPath
- })
- pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string {
- return getMacTools(ctx).stripPath
- })
- pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string {
- return getMacTools(ctx).toolPath
- })
- pctx.StaticVariable("DarwinGccVersion", darwinGccVersion)
- pctx.SourcePathVariable("DarwinGccRoot",
- "prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${DarwinGccVersion}")
- pctx.StaticVariable("DarwinGccTriple", "i686-apple-darwin11")
- pctx.StaticVariable("DarwinCflags", strings.Join(darwinCflags, " "))
- pctx.StaticVariable("DarwinLdflags", strings.Join(darwinLdflags, " "))
- pctx.StaticVariable("DarwinLldflags", strings.Join(darwinLdflags, " "))
- pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64")
- }
- func MacStripPath(ctx android.PathContext) string {
- return getMacTools(ctx).stripPath
- }
- type macPlatformTools struct {
- once sync.Once
- err error
- sdkRoot string
- arPath string
- stripPath string
- toolPath string
- }
- var macTools = &macPlatformTools{}
- func getMacTools(ctx android.PathContext) *macPlatformTools {
- macTools.once.Do(func() {
- xcrunTool := "/usr/bin/xcrun"
- xcrun := func(args ...string) string {
- if macTools.err != nil {
- return ""
- }
- bytes, err := exec.Command(xcrunTool, args...).Output()
- if err != nil {
- macTools.err = fmt.Errorf("xcrun %q failed with: %q", args, err)
- return ""
- }
- return strings.TrimSpace(string(bytes))
- }
- xcrunSdk := func(arg string) string {
- if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" {
- if !inList(selected, darwinSupportedSdkVersions) {
- macTools.err = fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
- return ""
- }
- return xcrun("--sdk", "macosx"+selected, arg)
- }
- for _, sdk := range darwinSupportedSdkVersions {
- bytes, err := exec.Command(xcrunTool, "--sdk", "macosx"+sdk, arg).Output()
- if err == nil {
- return strings.TrimSpace(string(bytes))
- }
- }
- macTools.err = fmt.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
- return ""
- }
- macTools.sdkRoot = xcrunSdk("--show-sdk-path")
- macTools.arPath = xcrun("--find", "ar")
- macTools.stripPath = xcrun("--find", "strip")
- macTools.toolPath = filepath.Dir(xcrun("--find", "ld"))
- })
- if macTools.err != nil {
- android.ReportPathErrorf(ctx, "%q", macTools.err)
- }
- return macTools
- }
- type toolchainDarwin struct {
- cFlags, ldFlags string
- toolchain64Bit
- }
- func (t *toolchainDarwin) Name() string {
- return "x86_64"
- }
- func (t *toolchainDarwin) GccRoot() string {
- return "${config.DarwinGccRoot}"
- }
- func (t *toolchainDarwin) GccTriple() string {
- return "${config.DarwinGccTriple}"
- }
- func (t *toolchainDarwin) GccVersion() string {
- return darwinGccVersion
- }
- func (t *toolchainDarwin) IncludeFlags() string {
- return ""
- }
- func (t *toolchainDarwin) ClangTriple() string {
- return "x86_64-apple-darwin"
- }
- func (t *toolchainDarwin) Cflags() string {
- return "${config.DarwinCflags}"
- }
- func (t *toolchainDarwin) Cppflags() string {
- return ""
- }
- func (t *toolchainDarwin) Ldflags() string {
- return "${config.DarwinLdflags}"
- }
- func (t *toolchainDarwin) Lldflags() string {
- return "${config.DarwinLldflags}"
- }
- func (t *toolchainDarwin) YasmFlags() string {
- return "${config.DarwinYasmFlags}"
- }
- func (t *toolchainDarwin) ShlibSuffix() string {
- return ".dylib"
- }
- func (t *toolchainDarwin) AvailableLibraries() []string {
- return darwinAvailableLibraries
- }
- func (t *toolchainDarwin) ToolPath() string {
- return "${config.MacToolPath}"
- }
- var toolchainDarwinSingleton Toolchain = &toolchainDarwin{}
- func darwinToolchainFactory(arch android.Arch) Toolchain {
- return toolchainDarwinSingleton
- }
- func init() {
- registerToolchainFactory(android.Darwin, android.X86_64, darwinToolchainFactory)
- }
|