2015-05-01 01:36:18 +02:00
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
2015-12-15 05:02:44 +01:00
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
2015-05-01 01:36:18 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
darwinCflags = []string{
|
|
|
|
"-fno-exceptions", // from build/core/combo/select.mk
|
|
|
|
"-Wno-multichar", // from build/core/combo/select.mk
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
2015-05-01 01:36:18 +02: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 05:02:44 +01:00
|
|
|
"-mmacosx-version-min=${macSdkVersion}",
|
|
|
|
"-DMACOSX_DEPLOYMENT_TARGET=${macSdkVersion}",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinCppflags = []string{
|
2015-12-15 05:02:44 +01:00
|
|
|
"-isystem ${macToolchainRoot}/usr/include/c++/v1",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinLdflags = []string{
|
|
|
|
"-isysroot ${macSdkRoot}",
|
|
|
|
"-Wl,-syslibroot,${macSdkRoot}",
|
2015-12-15 05:02:44 +01:00
|
|
|
"-mmacosx-version-min=${macSdkVersion}",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extended cflags
|
|
|
|
darwinX86Cflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX8664Cflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX86Ldflags = []string{
|
|
|
|
"-m32",
|
|
|
|
"-Wl,-rpath,@loader_path/../lib",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-Wl,-rpath,@loader_path/lib",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinX8664Ldflags = []string{
|
|
|
|
"-m64",
|
|
|
|
"-Wl,-rpath,@loader_path/../lib64",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-Wl,-rpath,@loader_path/lib64",
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinClangCflags = append([]string{
|
|
|
|
"-integrated-as",
|
|
|
|
}, clangFilterUnknownCflags(darwinCflags)...)
|
|
|
|
|
|
|
|
darwinClangLdflags = clangFilterUnknownCflags(darwinLdflags)
|
|
|
|
|
|
|
|
darwinX86ClangLdflags = clangFilterUnknownCflags(darwinX86Ldflags)
|
|
|
|
|
|
|
|
darwinX8664ClangLdflags = clangFilterUnknownCflags(darwinX8664Ldflags)
|
|
|
|
|
|
|
|
darwinClangCppflags = clangFilterUnknownCflags(darwinCppflags)
|
2015-12-15 05:02:44 +01:00
|
|
|
|
|
|
|
darwinSupportedSdkVersions = []string{
|
|
|
|
"macosx10.8",
|
|
|
|
"macosx10.9",
|
|
|
|
"macosx10.10",
|
|
|
|
"macosx10.11",
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
|
2015-12-07 21:30:44 +01:00
|
|
|
const (
|
|
|
|
darwinGccVersion = "4.2.1"
|
|
|
|
)
|
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
func init() {
|
2015-12-15 05:02:44 +01: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.StaticVariable("macToolchainRoot", "${macSdkPath}/Toolchains/XcodeDefault.xctoolchain")
|
|
|
|
pctx.VariableFunc("macSdkRoot", func(config interface{}) (string, error) {
|
|
|
|
return xcrunSdk(config.(common.Config), "--show-sdk-path")
|
|
|
|
})
|
|
|
|
pctx.VariableFunc("macSdkVersion", func(config interface{}) (string, error) {
|
|
|
|
return xcrunSdk(config.(common.Config), "--show-sdk-version")
|
|
|
|
})
|
|
|
|
pctx.VariableFunc("macArPath", func(config interface{}) (string, error) {
|
|
|
|
bytes, err := exec.Command("xcrun", "--find", "ar").Output()
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
})
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2015-12-07 21:30:44 +01:00
|
|
|
pctx.StaticVariable("darwinGccVersion", darwinGccVersion)
|
2015-09-24 00:26:20 +02:00
|
|
|
pctx.SourcePathVariable("darwinGccRoot",
|
|
|
|
"prebuilts/gcc/${HostPrebuiltTag}/host/i686-apple-darwin-${darwinGccVersion}")
|
2015-05-01 01:36:18 +02:00
|
|
|
|
|
|
|
pctx.StaticVariable("darwinGccTriple", "i686-apple-darwin11")
|
|
|
|
|
|
|
|
pctx.StaticVariable("darwinCflags", strings.Join(darwinCflags, " "))
|
|
|
|
pctx.StaticVariable("darwinLdflags", strings.Join(darwinLdflags, " "))
|
|
|
|
pctx.StaticVariable("darwinCppflags", strings.Join(darwinCppflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("darwinClangCflags", strings.Join(darwinClangCflags, " "))
|
|
|
|
pctx.StaticVariable("darwinClangLdflags", strings.Join(darwinClangLdflags, " "))
|
|
|
|
pctx.StaticVariable("darwinClangCppflags", strings.Join(darwinClangCppflags, " "))
|
|
|
|
|
|
|
|
// Extended cflags
|
|
|
|
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(clangFilterUnknownCflags(darwinX86Cflags), " "))
|
|
|
|
pctx.StaticVariable("darwinX8664ClangCflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(darwinX8664Cflags), " "))
|
|
|
|
pctx.StaticVariable("darwinX86ClangLdflags", strings.Join(darwinX86ClangLdflags, " "))
|
|
|
|
pctx.StaticVariable("darwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " "))
|
|
|
|
}
|
|
|
|
|
2015-12-15 05:02:44 +01:00
|
|
|
func xcrunSdk(config common.Config, arg string) (string, error) {
|
|
|
|
if selected := config.Getenv("MAC_SDK_VERSION"); selected != "" {
|
|
|
|
if !inList("macosx"+selected, darwinSupportedSdkVersions) {
|
|
|
|
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 {
|
|
|
|
bytes, err := exec.Command("xcrun", "--sdk", sdk, arg).Output()
|
|
|
|
if err == nil {
|
|
|
|
return strings.TrimSpace(string(bytes)), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
|
|
|
|
}
|
|
|
|
|
2015-05-01 01:36:18 +02: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 {
|
|
|
|
return "${darwinGccRoot}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) GccTriple() string {
|
|
|
|
return "${darwinGccTriple}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) GccVersion() string {
|
2015-12-07 21:30:44 +01:00
|
|
|
return darwinGccVersion
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) Cflags() string {
|
|
|
|
return "${darwinCflags} ${darwinX86Cflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) Cflags() string {
|
|
|
|
return "${darwinCflags} ${darwinX8664Cflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) Cppflags() string {
|
|
|
|
return "${darwinCppflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) Ldflags() string {
|
|
|
|
return "${darwinLdflags} ${darwinX86Ldflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) Ldflags() string {
|
|
|
|
return "${darwinLdflags} ${darwinX8664Ldflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) IncludeFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangTriple() string {
|
|
|
|
return "i686-darwin-gnu"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangCflags() string {
|
|
|
|
return "${darwinClangCflags} ${darwinX86ClangCflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangCppflags() string {
|
|
|
|
return "${darwinClangCppflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangTriple() string {
|
|
|
|
return "x86_64-darwin-gnu"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangCflags() string {
|
|
|
|
return "${darwinClangCflags} ${darwinX8664ClangCflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangCppflags() string {
|
|
|
|
return "${darwinClangCppflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangLdflags() string {
|
|
|
|
return "${darwinClangLdflags} ${darwinX86ClangLdflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangLdflags() string {
|
|
|
|
return "${darwinClangLdflags} ${darwinX8664ClangLdflags}"
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (t *toolchainDarwin) ShlibSuffix() string {
|
|
|
|
return ".dylib"
|
|
|
|
}
|
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
|
|
|
|
var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}
|
|
|
|
|
2015-11-21 00:35:00 +01:00
|
|
|
func darwinX86ToolchainFactory(arch common.Arch) Toolchain {
|
2015-05-01 01:36:18 +02:00
|
|
|
return toolchainDarwinX86Singleton
|
|
|
|
}
|
|
|
|
|
2015-11-21 00:35:00 +01:00
|
|
|
func darwinX8664ToolchainFactory(arch common.Arch) Toolchain {
|
2015-05-01 01:36:18 +02:00
|
|
|
return toolchainDarwinX8664Singleton
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2015-11-25 02:53:15 +01:00
|
|
|
registerHostToolchainFactory(common.Darwin, common.X86, darwinX86ToolchainFactory)
|
|
|
|
registerHostToolchainFactory(common.Darwin, common.X86_64, darwinX8664ToolchainFactory)
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|