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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-09 19:30:22 +01:00
|
|
|
darwinSystemCppCppflags = []string{
|
|
|
|
"-isystem ${macToolchainRoot}/usr/include/c++/v1",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinSystemCppLdflags = []string{
|
|
|
|
"-stdlib=libc++",
|
|
|
|
}
|
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
// Extended cflags
|
|
|
|
darwinX86Cflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX8664Cflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX86Ldflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinX8664Ldflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
2016-03-04 02:22:39 +01:00
|
|
|
darwinClangCflags = append(clangFilterUnknownCflags(darwinCflags), []string{
|
2015-05-01 01:36:18 +02:00
|
|
|
"-integrated-as",
|
2016-01-13 01:22:40 +01:00
|
|
|
"-fstack-protector-strong",
|
2016-03-04 02:22:39 +01:00
|
|
|
}...)
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2016-03-30 09:01:12 +02:00
|
|
|
darwinX86ClangCflags = append(clangFilterUnknownCflags(darwinX86Cflags), []string{
|
|
|
|
"-msse3",
|
|
|
|
}...)
|
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
darwinClangLdflags = clangFilterUnknownCflags(darwinLdflags)
|
|
|
|
|
|
|
|
darwinX86ClangLdflags = clangFilterUnknownCflags(darwinX86Ldflags)
|
|
|
|
|
|
|
|
darwinX8664ClangLdflags = clangFilterUnknownCflags(darwinX8664Ldflags)
|
|
|
|
|
2015-12-15 05:02:44 +01:00
|
|
|
darwinSupportedSdkVersions = []string{
|
2016-03-09 19:41:21 +01:00
|
|
|
"10.8",
|
|
|
|
"10.9",
|
|
|
|
"10.10",
|
|
|
|
"10.11",
|
2015-12-15 05:02:44 +01:00
|
|
|
}
|
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")
|
|
|
|
})
|
2016-03-09 19:41:21 +01:00
|
|
|
pctx.StaticVariable("macSdkVersion", darwinSupportedSdkVersions[0])
|
2015-12-15 05:02:44 +01:00
|
|
|
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("darwinClangCflags", strings.Join(darwinClangCflags, " "))
|
|
|
|
pctx.StaticVariable("darwinClangLdflags", strings.Join(darwinClangLdflags, " "))
|
2016-03-09 19:30:22 +01:00
|
|
|
|
|
|
|
pctx.StaticVariable("darwinSystemCppCppflags", strings.Join(darwinSystemCppCppflags, " "))
|
|
|
|
pctx.StaticVariable("darwinSystemCppLdflags", strings.Join(darwinSystemCppLdflags, " "))
|
2015-05-01 01:36:18 +02:00
|
|
|
|
|
|
|
// 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, " "))
|
|
|
|
|
2016-03-30 09:01:12 +02:00
|
|
|
pctx.StaticVariable("darwinX86ClangCflags", strings.Join(darwinX86ClangCflags, " "))
|
2015-05-01 01:36:18 +02:00
|
|
|
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 != "" {
|
2016-03-09 19:41:21 +01:00
|
|
|
if !inList(selected, darwinSupportedSdkVersions) {
|
2015-12-15 05:02:44 +01: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-09 19:41:21 +01:00
|
|
|
bytes, err := exec.Command("xcrun", "--sdk", "macosx"+sdk, arg).Output()
|
2015-12-15 05:02:44 +01: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 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 {
|
2016-03-09 19:30:22 +01:00
|
|
|
return ""
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2016-03-30 09:01:12 +02:00
|
|
|
return "i686-apple-darwin"
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX86) ClangCflags() string {
|
|
|
|
return "${darwinClangCflags} ${darwinX86ClangCflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangTriple() string {
|
2016-03-30 09:01:12 +02:00
|
|
|
return "x86_64-apple-darwin"
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwinX8664) ClangCflags() string {
|
|
|
|
return "${darwinClangCflags} ${darwinX8664ClangCflags}"
|
|
|
|
}
|
|
|
|
|
2016-03-09 19:30:22 +01:00
|
|
|
func (t *toolchainDarwin) ClangCppflags() string {
|
|
|
|
return ""
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2016-03-09 19:30:22 +01:00
|
|
|
func (t *toolchainDarwin) SystemCppCppflags() string {
|
|
|
|
return "${darwinSystemCppCppflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainDarwin) SystemCppLdflags() string {
|
|
|
|
return "${darwinSystemCppLdflags}"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|