2016-07-29 22:44:28 +02: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-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
linuxCflags = []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-01-31 02:27:36 +01:00
|
|
|
"-Wa,--noexecstack",
|
|
|
|
|
|
|
|
"-fPIC",
|
|
|
|
"-no-canonical-prefixes",
|
|
|
|
|
|
|
|
"-U_FORTIFY_SOURCE",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-D_FORTIFY_SOURCE=2",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-fstack-protector",
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
linuxLdflags = []string{
|
|
|
|
"-Wl,-z,noexecstack",
|
|
|
|
"-Wl,-z,relro",
|
|
|
|
"-Wl,-z,now",
|
2015-12-09 22:05:28 +01:00
|
|
|
"-Wl,--no-undefined-version",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extended cflags
|
|
|
|
linuxX86Cflags = []string{
|
|
|
|
"-msse3",
|
|
|
|
"-mfpmath=sse",
|
|
|
|
"-m32",
|
|
|
|
"-march=prescott",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-D_FILE_OFFSET_BITS=64",
|
|
|
|
"-D_LARGEFILE_SOURCE=1",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
linuxX8664Cflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
|
|
|
linuxX86Ldflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
linuxX8664Ldflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
linuxClangCflags = append(ClangFilterUnknownCflags(linuxCflags), []string{
|
|
|
|
"--gcc-toolchain=${LinuxGccRoot}",
|
|
|
|
"--sysroot ${LinuxGccRoot}/sysroot",
|
2016-01-13 01:22:40 +01:00
|
|
|
"-fstack-protector-strong",
|
2016-03-04 02:22:39 +01:00
|
|
|
}...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
linuxClangLdflags = append(ClangFilterUnknownCflags(linuxLdflags), []string{
|
|
|
|
"--gcc-toolchain=${LinuxGccRoot}",
|
|
|
|
"--sysroot ${LinuxGccRoot}/sysroot",
|
2016-03-04 02:22:39 +01:00
|
|
|
}...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
linuxX86ClangLdflags = append(ClangFilterUnknownCflags(linuxX86Ldflags), []string{
|
|
|
|
"-B${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}/32",
|
|
|
|
"-L${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}/32",
|
|
|
|
"-L${LinuxGccRoot}/${LinuxGccTriple}/lib32",
|
2016-03-04 02:22:39 +01:00
|
|
|
}...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
linuxX8664ClangLdflags = append(ClangFilterUnknownCflags(linuxX8664Ldflags), []string{
|
|
|
|
"-B${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}",
|
|
|
|
"-L${LinuxGccRoot}/lib/gcc/${LinuxGccTriple}/${LinuxGccVersion}",
|
|
|
|
"-L${LinuxGccRoot}/${LinuxGccTriple}/lib64",
|
2016-03-04 02:22:39 +01:00
|
|
|
}...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
linuxClangCppflags = []string{
|
2016-07-29 22:44:28 +02:00
|
|
|
"-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}",
|
|
|
|
"-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/backward",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
linuxX86ClangCppflags = []string{
|
2016-07-29 22:44:28 +02:00
|
|
|
"-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/${LinuxGccTriple}/32",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
linuxX8664ClangCppflags = []string{
|
2016-07-29 22:44:28 +02:00
|
|
|
"-isystem ${LinuxGccRoot}/${LinuxGccTriple}/include/c++/${LinuxGccVersion}/${LinuxGccTriple}",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-05-25 23:47:21 +02:00
|
|
|
|
|
|
|
linuxAvailableLibraries = addPrefix([]string{
|
|
|
|
"c",
|
|
|
|
"dl",
|
|
|
|
"gcc",
|
|
|
|
"gcc_s",
|
|
|
|
"m",
|
|
|
|
"ncurses",
|
|
|
|
"pthread",
|
|
|
|
"resolv",
|
|
|
|
"rt",
|
|
|
|
"util",
|
|
|
|
"z",
|
|
|
|
}, "-l")
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2015-12-07 21:30:44 +01:00
|
|
|
const (
|
|
|
|
linuxGccVersion = "4.8"
|
|
|
|
)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func init() {
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("LinuxGccVersion", linuxGccVersion)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.SourcePathVariable("LinuxGccRoot",
|
|
|
|
"prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-linux-glibc2.15-${LinuxGccVersion}")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("LinuxGccTriple", "x86_64-linux")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("LinuxCflags", strings.Join(linuxCflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxLdflags", strings.Join(linuxLdflags, " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("LinuxClangCflags", strings.Join(linuxClangCflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxClangLdflags", strings.Join(linuxClangLdflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxClangCppflags", strings.Join(linuxClangCppflags, " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// Extended cflags
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("LinuxX86Cflags", strings.Join(linuxX86Cflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxX8664Cflags", strings.Join(linuxX8664Cflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxX86Ldflags", strings.Join(linuxX86Ldflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxX8664Ldflags", strings.Join(linuxX8664Ldflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("LinuxX86ClangCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(linuxX86Cflags), " "))
|
|
|
|
pctx.StaticVariable("LinuxX8664ClangCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(linuxX8664Cflags), " "))
|
|
|
|
pctx.StaticVariable("LinuxX86ClangLdflags", strings.Join(linuxX86ClangLdflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxX8664ClangLdflags", strings.Join(linuxX8664ClangLdflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxX86ClangCppflags", strings.Join(linuxX86ClangCppflags, " "))
|
|
|
|
pctx.StaticVariable("LinuxX8664ClangCppflags", strings.Join(linuxX8664ClangCppflags, " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainLinux struct {
|
|
|
|
cFlags, ldFlags string
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainLinuxX86 struct {
|
|
|
|
toolchain32Bit
|
|
|
|
toolchainLinux
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainLinuxX8664 struct {
|
|
|
|
toolchain64Bit
|
|
|
|
toolchainLinux
|
|
|
|
}
|
|
|
|
|
2015-03-19 07:38:50 +01:00
|
|
|
func (t *toolchainLinuxX86) Name() string {
|
|
|
|
return "x86"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) Name() string {
|
|
|
|
return "x86_64"
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (t *toolchainLinux) GccRoot() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxGccRoot}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinux) GccTriple() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxGccTriple}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 07:38:50 +01:00
|
|
|
func (t *toolchainLinux) GccVersion() string {
|
2015-12-07 21:30:44 +01:00
|
|
|
return linuxGccVersion
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (t *toolchainLinuxX86) Cflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxCflags} ${config.LinuxX86Cflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) Cflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxCflags} ${config.LinuxX8664Cflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinux) Cppflags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX86) Ldflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxLdflags} ${config.LinuxX86Ldflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) Ldflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxLdflags} ${config.LinuxX8664Ldflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinux) IncludeFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX86) ClangTriple() string {
|
|
|
|
return "i686-linux-gnu"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX86) ClangCflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxClangCflags} ${config.LinuxX86ClangCflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX86) ClangCppflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxClangCppflags} ${config.LinuxX86ClangCppflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) ClangTriple() string {
|
|
|
|
return "x86_64-linux-gnu"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) ClangCflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxClangCflags} ${config.LinuxX8664ClangCflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) ClangCppflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxClangCppflags} ${config.LinuxX8664ClangCppflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX86) ClangLdflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxClangLdflags} ${config.LinuxX86ClangLdflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxX8664) ClangLdflags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.LinuxClangLdflags} ${config.LinuxX8664ClangLdflags}"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-05-25 23:47:21 +02:00
|
|
|
func (t *toolchainLinux) AvailableLibraries() []string {
|
|
|
|
return linuxAvailableLibraries
|
|
|
|
}
|
|
|
|
|
2016-11-17 10:02:25 +01:00
|
|
|
func (t *toolchainLinux) Bionic() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{}
|
|
|
|
var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func linuxX86ToolchainFactory(arch android.Arch) Toolchain {
|
2015-01-31 02:27:36 +01:00
|
|
|
return toolchainLinuxX86Singleton
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func linuxX8664ToolchainFactory(arch android.Arch) Toolchain {
|
2015-01-31 02:27:36 +01:00
|
|
|
return toolchainLinuxX8664Singleton
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-06-02 02:09:44 +02:00
|
|
|
registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory)
|
|
|
|
registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|