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
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
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{
|
|
|
|
"-fno-exceptions", // from build/core/combo/select.mk
|
|
|
|
"-Wno-multichar", // from build/core/combo/select.mk
|
|
|
|
|
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",
|
|
|
|
|
|
|
|
// HOST_RELEASE_CFLAGS
|
|
|
|
"-O2", // from build/core/combo/select.mk
|
|
|
|
"-g", // from build/core/combo/select.mk
|
|
|
|
"-fno-strict-aliasing", // from build/core/combo/select.mk
|
|
|
|
"-isysroot ${macSdkRoot}",
|
2015-12-15 12:02:44 +08:00
|
|
|
"-mmacosx-version-min=${macSdkVersion}",
|
|
|
|
"-DMACOSX_DEPLOYMENT_TARGET=${macSdkVersion}",
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinLdflags = []string{
|
|
|
|
"-isysroot ${macSdkRoot}",
|
|
|
|
"-Wl,-syslibroot,${macSdkRoot}",
|
2015-12-15 12:02:44 +08:00
|
|
|
"-mmacosx-version-min=${macSdkVersion}",
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extended cflags
|
|
|
|
darwinX86Cflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX8664Cflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX86Ldflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX8664Ldflags = []string{
|
|
|
|
"-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
|
|
|
darwinX86ClangCflags = append(ClangFilterUnknownCflags(darwinX86Cflags), []string{
|
2016-03-30 15:01:12 +08:00
|
|
|
"-msse3",
|
|
|
|
}...)
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
darwinClangLdflags = ClangFilterUnknownCflags(darwinLdflags)
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
darwinX86ClangLdflags = ClangFilterUnknownCflags(darwinX86Ldflags)
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
darwinX8664ClangLdflags = ClangFilterUnknownCflags(darwinX8664Ldflags)
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2015-12-15 12:02:44 +08:00
|
|
|
darwinSupportedSdkVersions = []string{
|
2016-03-10 02:41:21 +08:00
|
|
|
"10.8",
|
|
|
|
"10.9",
|
|
|
|
"10.10",
|
|
|
|
"10.11",
|
2015-12-15 12:02:44 +08:00
|
|
|
}
|
2016-05-26 05:47:21 +08:00
|
|
|
|
2016-09-02 02:51:27 +08:00
|
|
|
darwinAvailableLibraries = append(addPrefix([]string{
|
2016-05-26 05:47:21 +08:00
|
|
|
"c",
|
2016-07-14 13:17:39 +08:00
|
|
|
"dl",
|
2016-05-26 05:47:21 +08:00
|
|
|
"m",
|
2016-07-21 03:47:47 +08:00
|
|
|
"ncurses",
|
2016-05-26 05:47:21 +08:00
|
|
|
"pthread",
|
2016-06-07 07:26:48 +08:00
|
|
|
"z",
|
2016-09-02 02:51:27 +08:00
|
|
|
}, "-l"), "-framework CoreFoundation")
|
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() {
|
2015-12-15 12:02:44 +08:00
|
|
|
pctx.VariableFunc("macSdkPath", func(config interface{}) (string, error) {
|
|
|
|
bytes, err := exec.Command("xcode-select", "--print-path").Output()
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
})
|
|
|
|
pctx.VariableFunc("macSdkRoot", func(config interface{}) (string, error) {
|
2016-05-19 06:37:25 +08:00
|
|
|
return xcrunSdk(config.(android.Config), "--show-sdk-path")
|
2015-12-15 12:02:44 +08:00
|
|
|
})
|
2016-03-10 02:41:21 +08:00
|
|
|
pctx.StaticVariable("macSdkVersion", darwinSupportedSdkVersions[0])
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.VariableFunc("MacArPath", func(config interface{}) (string, error) {
|
2015-12-15 12:02:44 +08:00
|
|
|
bytes, err := exec.Command("xcrun", "--find", "ar").Output()
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
})
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.VariableFunc("MacStripPath", func(config interface{}) (string, error) {
|
2016-05-04 06:10:29 +08:00
|
|
|
bytes, err := exec.Command("xcrun", "--find", "strip").Output()
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
})
|
|
|
|
|
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("DarwinCflags", strings.Join(darwinCflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinLdflags", strings.Join(darwinLdflags, " "))
|
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, " "))
|
2016-03-10 02:30:22 +08:00
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
// Extended cflags
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("DarwinX86Cflags", strings.Join(darwinX86Cflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinX8664Cflags", strings.Join(darwinX8664Cflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinX86Ldflags", strings.Join(darwinX86Ldflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinX8664Ldflags", strings.Join(darwinX8664Ldflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("DarwinX86ClangCflags", strings.Join(darwinX86ClangCflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinX8664ClangCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(darwinX8664Cflags), " "))
|
|
|
|
pctx.StaticVariable("DarwinX86ClangLdflags", strings.Join(darwinX86ClangLdflags, " "))
|
|
|
|
pctx.StaticVariable("DarwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " "))
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func xcrunSdk(config android.Config, arg string) (string, error) {
|
2015-12-15 12:02:44 +08:00
|
|
|
if selected := config.Getenv("MAC_SDK_VERSION"); selected != "" {
|
2016-03-10 02:41:21 +08:00
|
|
|
if !inList(selected, darwinSupportedSdkVersions) {
|
2015-12-15 12:02:44 +08:00
|
|
|
return "", fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes, err := exec.Command("xcrun", "--sdk", "macosx"+selected, arg).Output()
|
|
|
|
if err == nil {
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("MAC_SDK_VERSION %s is not installed", selected)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sdk := range darwinSupportedSdkVersions {
|
2016-03-10 02:41:21 +08:00
|
|
|
bytes, err := exec.Command("xcrun", "--sdk", "macosx"+sdk, arg).Output()
|
2015-12-15 12:02:44 +08:00
|
|
|
if err == nil {
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
type toolchainDarwin struct {
|
|
|
|
cFlags, ldFlags string
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainDarwinX86 struct {
|
|
|
|
toolchain32Bit
|
|
|
|
toolchainDarwin
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainDarwinX8664 struct {
|
|
|
|
toolchain64Bit
|
|
|
|
toolchainDarwin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) Name() string {
|
|
|
|
return "x86"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) Name() string {
|
|
|
|
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) Cflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinCflags} ${config.DarwinX86Cflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) Cflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinCflags} ${config.DarwinX8664Cflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) Cppflags() string {
|
2016-03-10 02:30:22 +08:00
|
|
|
return ""
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) Ldflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinLdflags} ${config.DarwinX86Ldflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) Ldflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinLdflags} ${config.DarwinX8664Ldflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) IncludeFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangTriple() string {
|
2016-03-30 15:01:12 +08:00
|
|
|
return "i686-apple-darwin"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangCflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinClangCflags} ${config.DarwinX86ClangCflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangTriple() string {
|
2016-03-30 15:01:12 +08:00
|
|
|
return "x86_64-apple-darwin"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangCflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinClangCflags} ${config.DarwinX8664ClangCflags}"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangLdflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinClangLdflags} ${config.DarwinX86ClangLdflags}"
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangLdflags() string {
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${config.DarwinClangLdflags} ${config.DarwinX8664ClangLdflags}"
|
2015-05-01 07:36:18 +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
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
|
|
|
|
var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func darwinX86ToolchainFactory(arch android.Arch) Toolchain {
|
2015-05-01 07:36:18 +08:00
|
|
|
return toolchainDarwinX86Singleton
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func darwinX8664ToolchainFactory(arch android.Arch) Toolchain {
|
2015-05-01 07:36:18 +08:00
|
|
|
return toolchainDarwinX8664Singleton
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-06-02 08:09:44 +08:00
|
|
|
registerToolchainFactory(android.Darwin, android.X86, darwinX86ToolchainFactory)
|
|
|
|
registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory)
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|