2016-07-30 04:44:28 +08:00
|
|
|
// 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
|
2015-05-01 07:36:18 +08:00
|
|
|
|
|
|
|
import (
|
2015-12-15 12:02:44 +08:00
|
|
|
"os/exec"
|
2017-03-14 03:40:30 +08:00
|
|
|
"path/filepath"
|
2015-05-01 07:36:18 +08:00
|
|
|
"strings"
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2015-05-01 07:36:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
darwinCflags = []string{
|
2015-11-25 09:53:15 +08:00
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
"-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}",
|
2016-10-27 10:20:58 +08:00
|
|
|
"-mmacosx-version-min=${macMinVersion}",
|
|
|
|
"-DMACOSX_DEPLOYMENT_TARGET=${macMinVersion}",
|
2018-08-29 08:12:56 +08:00
|
|
|
|
|
|
|
"-m64",
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinLdflags = []string{
|
|
|
|
"-isysroot ${macSdkRoot}",
|
|
|
|
"-Wl,-syslibroot,${macSdkRoot}",
|
2016-10-27 10:20:58 +08:00
|
|
|
"-mmacosx-version-min=${macMinVersion}",
|
2015-05-01 07:36:18 +08:00
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
darwinClangCflags = append(ClangFilterUnknownCflags(darwinCflags), []string{
|
2015-05-01 07:36:18 +08:00
|
|
|
"-integrated-as",
|
2016-01-13 08:22:40 +08:00
|
|
|
"-fstack-protector-strong",
|
2016-03-04 09:22:39 +08:00
|
|
|
}...)
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
darwinClangLdflags = ClangFilterUnknownCflags(darwinLdflags)
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2018-04-18 05:16:05 +08:00
|
|
|
darwinClangLldflags = ClangFilterUnknownLldflags(darwinClangLdflags)
|
|
|
|
|
2015-12-15 12:02:44 +08:00
|
|
|
darwinSupportedSdkVersions = []string{
|
2016-03-10 02:41:21 +08:00
|
|
|
"10.10",
|
|
|
|
"10.11",
|
2016-10-27 10:20:58 +08:00
|
|
|
"10.12",
|
2017-09-24 16:51:02 +08:00
|
|
|
"10.13",
|
2018-08-29 07:48:45 +08:00
|
|
|
"10.14",
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
2016-05-26 05:47:21 +08:00
|
|
|
|
2016-09-30 05:22:54 +08:00
|
|
|
darwinAvailableLibraries = append(
|
|
|
|
addPrefix([]string{
|
|
|
|
"c",
|
|
|
|
"dl",
|
|
|
|
"m",
|
|
|
|
"ncurses",
|
|
|
|
"objc",
|
|
|
|
"pthread",
|
|
|
|
}, "-l"),
|
2016-11-22 09:31:08 +08:00
|
|
|
"-framework AppKit",
|
2016-09-30 05:22:54 +08:00
|
|
|
"-framework CoreFoundation",
|
2016-11-22 09:31:08 +08:00
|
|
|
"-framework Foundation",
|
2016-09-30 05:22:54 +08:00
|
|
|
"-framework IOKit",
|
2016-11-22 09:31:08 +08:00
|
|
|
"-framework Security",
|
2016-09-30 05:22:54 +08:00
|
|
|
)
|
2015-05-01 07:36:18 +08:00
|
|
|
)
|
|
|
|
|
2015-12-08 04:30:44 +08:00
|
|
|
const (
|
|
|
|
darwinGccVersion = "4.2.1"
|
|
|
|
)
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
func init() {
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("macSdkPath", func(ctx android.PackageVarContext) string {
|
|
|
|
xcodeselect := ctx.Config().HostSystemTool("xcode-select")
|
2017-05-09 05:15:59 +08:00
|
|
|
bytes, err := exec.Command(xcodeselect, "--print-path").Output()
|
2018-03-13 04:24:09 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.Errorf("xcode-select failed with: %q", err.Error())
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(bytes))
|
2015-12-15 12:02:44 +08:00
|
|
|
})
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string {
|
|
|
|
return xcrunSdk(ctx, "--show-sdk-path")
|
2015-12-15 12:02:44 +08:00
|
|
|
})
|
2016-10-27 10:20:58 +08:00
|
|
|
pctx.StaticVariable("macMinVersion", "10.8")
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string {
|
|
|
|
return xcrun(ctx, "--find", "ar")
|
2015-12-15 12:02:44 +08:00
|
|
|
})
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string {
|
|
|
|
return xcrun(ctx, "--find", "strip")
|
2016-05-04 06:10:29 +08:00
|
|
|
})
|
|
|
|
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string {
|
|
|
|
return filepath.Dir(xcrun(ctx, "--find", "ld"))
|
2017-03-14 03:40:30 +08:00
|
|
|
})
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("DarwinGccVersion", darwinGccVersion)
|
|
|
|
pctx.SourcePathVariable("DarwinGccRoot",
|
|
|
|
"prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${DarwinGccVersion}")
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("DarwinGccTriple", "i686-apple-darwin11")
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("DarwinClangCflags", strings.Join(darwinClangCflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinClangLdflags", strings.Join(darwinClangLdflags, " "))
|
2018-04-18 05:16:05 +08:00
|
|
|
pctx.StaticVariable("DarwinClangLldflags", strings.Join(darwinClangLldflags, " "))
|
2016-03-10 02:30:22 +08:00
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64")
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2018-03-13 04:24:09 +08:00
|
|
|
func xcrun(ctx android.PackageVarContext, args ...string) string {
|
|
|
|
xcrun := ctx.Config().HostSystemTool("xcrun")
|
2017-05-09 05:15:59 +08:00
|
|
|
bytes, err := exec.Command(xcrun, args...).Output()
|
2018-03-13 04:24:09 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.Errorf("xcrun failed with: %q", err.Error())
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(bytes))
|
2017-05-09 05:15:59 +08:00
|
|
|
}
|
|
|
|
|
2018-03-13 04:24:09 +08:00
|
|
|
func xcrunSdk(ctx android.PackageVarContext, arg string) string {
|
|
|
|
xcrun := ctx.Config().HostSystemTool("xcrun")
|
|
|
|
if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" {
|
2016-03-10 02:41:21 +08:00
|
|
|
if !inList(selected, darwinSupportedSdkVersions) {
|
2018-03-13 04:24:09 +08:00
|
|
|
ctx.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
|
|
|
|
return ""
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 05:15:59 +08:00
|
|
|
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+selected, arg).Output()
|
2018-03-13 04:24:09 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.Errorf("MAC_SDK_VERSION %s is not installed", selected)
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
2018-03-13 04:24:09 +08:00
|
|
|
return strings.TrimSpace(string(bytes))
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, sdk := range darwinSupportedSdkVersions {
|
2017-05-09 05:15:59 +08:00
|
|
|
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+sdk, arg).Output()
|
2015-12-15 12:02:44 +08:00
|
|
|
if err == nil {
|
2018-03-13 04:24:09 +08:00
|
|
|
return strings.TrimSpace(string(bytes))
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
|
|
|
}
|
2018-03-13 04:24:09 +08:00
|
|
|
ctx.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
|
|
|
|
return ""
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
type toolchainDarwin struct {
|
|
|
|
cFlags, ldFlags string
|
|
|
|
toolchain64Bit
|
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func (t *toolchainDarwin) Name() string {
|
2015-05-01 07:36:18 +08:00
|
|
|
return "x86_64"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) GccRoot() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinGccRoot}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) GccTriple() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinGccTriple}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) GccVersion() string {
|
2015-12-08 04:30:44 +08:00
|
|
|
return darwinGccVersion
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) IncludeFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func (t *toolchainDarwin) ClangTriple() string {
|
2016-03-30 15:01:12 +08:00
|
|
|
return "x86_64-apple-darwin"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func (t *toolchainDarwin) ClangCflags() string {
|
|
|
|
return "${config.DarwinClangCflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2016-03-10 02:30:22 +08:00
|
|
|
func (t *toolchainDarwin) ClangCppflags() string {
|
|
|
|
return ""
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func (t *toolchainDarwin) ClangLdflags() string {
|
|
|
|
return "${config.DarwinClangLdflags}"
|
2018-04-04 02:33:34 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func (t *toolchainDarwin) ClangLldflags() string {
|
|
|
|
return "${config.DarwinClangLldflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func (t *toolchainDarwin) YasmFlags() string {
|
|
|
|
return "${config.DarwinYasmFlags}"
|
2017-10-05 08:31:43 +08:00
|
|
|
}
|
|
|
|
|
2015-11-25 09:53:15 +08:00
|
|
|
func (t *toolchainDarwin) ShlibSuffix() string {
|
|
|
|
return ".dylib"
|
|
|
|
}
|
|
|
|
|
2016-05-26 05:47:21 +08:00
|
|
|
func (t *toolchainDarwin) AvailableLibraries() []string {
|
|
|
|
return darwinAvailableLibraries
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:02:25 +08:00
|
|
|
func (t *toolchainDarwin) Bionic() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-03-14 03:40:30 +08:00
|
|
|
func (t *toolchainDarwin) ToolPath() string {
|
|
|
|
return "${config.MacToolPath}"
|
|
|
|
}
|
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
var toolchainDarwinSingleton Toolchain = &toolchainDarwin{}
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2018-08-29 08:12:56 +08:00
|
|
|
func darwinToolchainFactory(arch android.Arch) Toolchain {
|
|
|
|
return toolchainDarwinSingleton
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-08-29 08:12:56 +08:00
|
|
|
registerToolchainFactory(android.Darwin, android.X86_64, darwinToolchainFactory)
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|