2015-03-18 21:28:46 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// 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 cc
|
|
|
|
|
|
|
|
// This file contains the module types for compiling C/C++ for Android, and converts the properties
|
|
|
|
// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
|
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/pathtools"
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
"android/soong/common"
|
2015-03-18 21:28:46 +01:00
|
|
|
"android/soong/genrule"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-04-08 02:11:30 +02:00
|
|
|
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", common.Config.PrebuiltOS)
|
|
|
|
SrcDir = pctx.VariableConfigMethod("SrcDir", common.Config.SrcDir)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
LibcRoot = pctx.StaticVariable("LibcRoot", "${SrcDir}/bionic/libc")
|
|
|
|
LibmRoot = pctx.StaticVariable("LibmRoot", "${SrcDir}/bionic/libm")
|
|
|
|
)
|
|
|
|
|
|
|
|
// Flags used by lots of devices. Putting them in package static variables will save bytes in
|
|
|
|
// build.ninja so they aren't repeated for every file
|
|
|
|
var (
|
|
|
|
commonGlobalCflags = []string{
|
|
|
|
"-DANDROID",
|
|
|
|
"-fmessage-length=0",
|
|
|
|
"-W",
|
|
|
|
"-Wall",
|
|
|
|
"-Wno-unused",
|
|
|
|
"-Winit-self",
|
|
|
|
"-Wpointer-arith",
|
|
|
|
|
|
|
|
// COMMON_RELEASE_CFLAGS
|
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceGlobalCflags = []string{
|
|
|
|
// TARGET_ERROR_FLAGS
|
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
|
|
|
}
|
|
|
|
|
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
|
|
|
"-std=gnu++11",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("commonClangGlobalCflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(commonGlobalCflags), " "))
|
|
|
|
pctx.StaticVariable("deviceClangGlobalCflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(deviceGlobalCflags), " "))
|
|
|
|
pctx.StaticVariable("hostClangGlobalCflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
|
2015-03-11 20:03:03 +01:00
|
|
|
pctx.StaticVariable("commonClangGlobalCppflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(commonGlobalCppflags), " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// Everything in this list is a crime against abstraction and dependency tracking.
|
|
|
|
// Do not add anything to this list.
|
|
|
|
pctx.StaticVariable("commonGlobalIncludes", strings.Join([]string{
|
|
|
|
"-isystem ${SrcDir}/system/core/include",
|
|
|
|
"-isystem ${SrcDir}/hardware/libhardware/include",
|
|
|
|
"-isystem ${SrcDir}/hardware/libhardware_legacy/include",
|
|
|
|
"-isystem ${SrcDir}/hardware/ril/include",
|
|
|
|
"-isystem ${SrcDir}/libnativehelper/include",
|
|
|
|
"-isystem ${SrcDir}/frameworks/native/include",
|
|
|
|
"-isystem ${SrcDir}/frameworks/native/opengl/include",
|
|
|
|
"-isystem ${SrcDir}/frameworks/av/include",
|
|
|
|
"-isystem ${SrcDir}/frameworks/base/include",
|
|
|
|
}, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("clangPath", "${SrcDir}/prebuilts/clang/${HostPrebuiltTag}/host/3.6/bin/")
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
// ccProperties describes properties used to compile all C or C++ modules
|
2015-01-31 02:27:36 +01:00
|
|
|
type ccProperties struct {
|
|
|
|
// srcs: list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
|
|
|
|
Srcs []string `android:"arch_variant,arch_subtract"`
|
|
|
|
|
|
|
|
// cflags: list of module-specific flags that will be used for C and C++ compiles.
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// cppflags: list of module-specific flags that will be used for C++ compiles
|
|
|
|
Cppflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// conlyflags: list of module-specific flags that will be used for C compiles
|
|
|
|
Conlyflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// asflags: list of module-specific flags that will be used for .S compiles
|
|
|
|
Asflags []string `android:"arch_variant"`
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
// yaccflags: list of module-specific flags that will be used for .y and .yy compiles
|
|
|
|
Yaccflags []string
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// ldflags: list of module-specific flags that will be used for all link steps
|
|
|
|
Ldflags []string `android:"arch_variant"`
|
|
|
|
|
2015-03-18 20:28:32 +01:00
|
|
|
// instruction_set: the instruction set architecture to use to compile the C/C++
|
|
|
|
// module.
|
|
|
|
Instruction_set string `android:"arch_variant"`
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// include_dirs: list of directories relative to the root of the source tree that will
|
|
|
|
// be added to the include path using -I.
|
|
|
|
// If possible, don't use this. If adding paths from the current directory use
|
|
|
|
// local_include_dirs, if adding paths from other modules use export_include_dirs in
|
|
|
|
// that module.
|
|
|
|
Include_dirs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// local_include_dirs: list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I
|
|
|
|
Local_include_dirs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// export_include_dirs: list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I for any module that links against this module
|
2015-03-19 07:38:50 +01:00
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// clang_cflags: list of module-specific flags that will be used for C and C++ compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// clang_asflags: list of module-specific flags that will be used for .S compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_asflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// system_shared_libs: list of system libraries that will be dynamically linked to
|
|
|
|
// shared library and executable modules. If unset, generally defaults to libc
|
|
|
|
// and libm. Set to [] to prevent linking against libc and libm.
|
|
|
|
System_shared_libs []string
|
|
|
|
|
|
|
|
// whole_static_libs: list of modules whose object files should be linked into this module
|
|
|
|
// in their entirety. For static library modules, all of the .o files from the intermediate
|
|
|
|
// directory of the dependency will be linked into this modules .a file. For a shared library,
|
|
|
|
// the dependency's .a file will be linked into this module using -Wl,--whole-archive.
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// static_libs: list of modules that should be statically linked into this module.
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// shared_libs: list of modules that should be dynamically linked into this module.
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// allow_undefined_symbols: allow the module to contain undefined symbols. By default,
|
|
|
|
// modules cannot contain undefined symbols that are not satisified by their immediate
|
|
|
|
// dependencies. Set this flag to true to remove --no-undefined from the linker flags.
|
|
|
|
// This flag should only be necessary for compiling low-level libraries like libc.
|
|
|
|
Allow_undefined_symbols bool
|
|
|
|
|
|
|
|
// nocrt: don't link in crt_begin and crt_end. This flag should only be necessary for
|
|
|
|
// compiling crt or libc.
|
|
|
|
Nocrt bool `android:"arch_variant"`
|
|
|
|
|
|
|
|
// no_default_compiler_flags: don't insert default compiler flags into asflags, cflags,
|
|
|
|
// cppflags, conlyflags, ldflags, or include_dirs
|
|
|
|
No_default_compiler_flags bool
|
|
|
|
|
|
|
|
// clang: compile module with clang instead of gcc
|
|
|
|
Clang bool `android:"arch_variant"`
|
|
|
|
|
|
|
|
// rtti: pass -frtti instead of -fno-rtti
|
|
|
|
Rtti bool
|
|
|
|
|
|
|
|
// host_ldlibs: -l arguments to pass to linker for host-provided shared libraries
|
|
|
|
Host_ldlibs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// stl: select the STL library to use. Possible values are "libc++", "libc++_static",
|
|
|
|
// "stlport", "stlport_static", "ndk", "libstdc++", or "none". Leave blank to select the
|
|
|
|
// default
|
|
|
|
Stl string
|
|
|
|
|
|
|
|
// Set for combined shared/static libraries to prevent compiling object files a second time
|
|
|
|
SkipCompileObjs bool `blueprint:"mutated"`
|
2015-03-18 20:07:10 +01:00
|
|
|
|
|
|
|
Debug struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Release struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2015-03-19 01:17:35 +01:00
|
|
|
|
|
|
|
// Minimum sdk version supported when compiling against the ndk
|
|
|
|
Sdk_version string
|
2015-04-22 02:37:37 +02:00
|
|
|
|
|
|
|
// relative_install_path: install to a subdirectory of the default install path for the module
|
|
|
|
Relative_install_path string
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type unusedProperties struct {
|
|
|
|
Asan bool
|
|
|
|
Native_coverage bool
|
|
|
|
Strip string
|
|
|
|
Tags []string
|
|
|
|
Required []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Building C/C++ code is handled by objects that satisfy this interface via composition
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCModuleType interface {
|
2015-01-31 02:27:36 +01:00
|
|
|
common.AndroidModule
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
// Modify the ccFlags
|
|
|
|
Flags(common.AndroidModuleContext, CCFlags) CCFlags
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
// Return list of dependency names for use in AndroidDynamicDependencies and in depsToPaths
|
|
|
|
DepNames(common.AndroidBaseContext, CCDeps) CCDeps
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// Compile objects into final module
|
2015-03-24 01:50:24 +01:00
|
|
|
compileModule(common.AndroidModuleContext, CCFlags, CCDeps, []string)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-18 22:01:18 +01:00
|
|
|
// Install the built module.
|
2015-03-24 01:50:24 +01:00
|
|
|
installModule(common.AndroidModuleContext, CCFlags)
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Return the output file (.o, .a or .so) for use by other modules
|
|
|
|
outputFile() string
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCDeps struct {
|
|
|
|
StaticLibs, SharedLibs, LateStaticLibs, WholeStaticLibs, ObjFiles, IncludeDirs []string
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
WholeStaticLibObjFiles []string
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
CrtBegin, CrtEnd string
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCFlags struct {
|
|
|
|
GlobalFlags []string
|
|
|
|
AsFlags []string
|
|
|
|
CFlags []string
|
|
|
|
ConlyFlags []string
|
|
|
|
CppFlags []string
|
2015-04-08 01:50:10 +02:00
|
|
|
YaccFlags []string
|
2015-03-24 01:50:24 +01:00
|
|
|
LdFlags []string
|
|
|
|
LdLibs []string
|
|
|
|
IncludeDirs []string
|
|
|
|
Nocrt bool
|
|
|
|
Toolchain Toolchain
|
|
|
|
Clang bool
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ccBase contains the properties and members used by all C/C++ module types, and implements
|
|
|
|
// the blueprint.Module interface. It expects to be embedded into an outer specialization struct,
|
|
|
|
// and uses a ccModuleType interface to that struct to create the build steps.
|
|
|
|
type ccBase struct {
|
|
|
|
common.AndroidModuleBase
|
2015-03-24 01:50:24 +01:00
|
|
|
module CCModuleType
|
2015-03-17 23:06:21 +01:00
|
|
|
|
|
|
|
properties ccProperties
|
|
|
|
unused unusedProperties
|
|
|
|
|
|
|
|
installPath string
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func newCCBase(base *ccBase, module CCModuleType, hod common.HostOrDeviceSupported,
|
2015-03-17 23:06:21 +01:00
|
|
|
multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
|
|
|
base.module = module
|
|
|
|
|
|
|
|
props = append(props, &base.properties, &base.unused)
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
return common.InitAndroidArchModule(module, hod, multilib, props...)
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (c *ccBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
toolchain := c.findToolchain(ctx)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
flags := c.collectFlags(ctx, toolchain)
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames := c.module.DepNames(ctx, CCDeps{})
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
deps := c.depsToPaths(ctx, depNames)
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, deps.IncludeDirs...)
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
objFiles := c.compileObjs(ctx, flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
generatedObjFiles := c.compileGeneratedObjs(ctx, flags)
|
2015-03-18 21:28:46 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
objFiles = append(objFiles, generatedObjFiles...)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
c.ccModuleType().compileModule(ctx, flags, deps, objFiles)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
|
|
|
|
c.ccModuleType().installModule(ctx, flags)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *ccBase) ccModuleType() CCModuleType {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.module
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ common.AndroidDynamicDepender = (*ccBase)(nil)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *ccBase) findToolchain(ctx common.AndroidModuleContext) Toolchain {
|
2015-01-31 02:27:36 +01:00
|
|
|
arch := ctx.Arch()
|
|
|
|
factory := toolchainFactories[arch.HostOrDevice][arch.ArchType]
|
|
|
|
if factory == nil {
|
|
|
|
panic(fmt.Sprintf("Toolchain not found for %s arch %q",
|
|
|
|
arch.HostOrDevice.String(), arch.String()))
|
|
|
|
}
|
|
|
|
return factory(arch.ArchVariant, arch.CpuVariant)
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *ccBase) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.properties.Whole_static_libs...)
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, c.properties.Static_libs...)
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, c.properties.Shared_libs...)
|
|
|
|
|
|
|
|
return depNames
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames := CCDeps{}
|
|
|
|
depNames = c.module.DepNames(ctx, depNames)
|
|
|
|
staticLibs := depNames.WholeStaticLibs
|
|
|
|
staticLibs = append(staticLibs, depNames.StaticLibs...)
|
|
|
|
staticLibs = append(staticLibs, depNames.LateStaticLibs...)
|
|
|
|
ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, staticLibs...)
|
|
|
|
|
|
|
|
ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depNames.SharedLibs...)
|
|
|
|
|
|
|
|
ret := append([]string(nil), depNames.ObjFiles...)
|
|
|
|
if depNames.CrtBegin != "" {
|
|
|
|
ret = append(ret, depNames.CrtBegin)
|
|
|
|
}
|
|
|
|
if depNames.CrtEnd != "" {
|
|
|
|
ret = append(ret, depNames.CrtEnd)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return ret
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a ccFlags struct that collects the compile flags from global values,
|
|
|
|
// per-target values, module type values, and per-module Blueprints properties
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *ccBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolchain) CCFlags {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags := CCFlags{
|
|
|
|
CFlags: c.properties.Cflags,
|
|
|
|
CppFlags: c.properties.Cppflags,
|
|
|
|
ConlyFlags: c.properties.Conlyflags,
|
|
|
|
LdFlags: c.properties.Ldflags,
|
|
|
|
AsFlags: c.properties.Asflags,
|
2015-04-08 01:50:10 +02:00
|
|
|
YaccFlags: c.properties.Yaccflags,
|
2015-03-24 01:50:24 +01:00
|
|
|
Nocrt: c.properties.Nocrt,
|
|
|
|
Toolchain: toolchain,
|
|
|
|
Clang: c.properties.Clang,
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-18 20:28:32 +01:00
|
|
|
instructionSet := c.properties.Instruction_set
|
|
|
|
instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-18 20:07:10 +01:00
|
|
|
// TODO: debug
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, c.properties.Release.Cflags...)
|
2015-03-18 20:07:10 +01:00
|
|
|
|
2015-03-27 00:14:04 +01:00
|
|
|
if ctx.Host() && !ctx.ContainsProperty("clang") {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.Clang = true
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CFlags = clangFilterUnknownCflags(flags.CFlags)
|
|
|
|
flags.CFlags = append(flags.CFlags, c.properties.Clang_cflags...)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, c.properties.Clang_asflags...)
|
|
|
|
flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags)
|
|
|
|
flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags)
|
|
|
|
flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "${clangExtraCflags}")
|
|
|
|
flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "${clangExtraTargetCflags}")
|
2015-03-17 00:21:20 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
target := "-target " + toolchain.ClangTriple()
|
|
|
|
gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, target, gccPrefix)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, target, gccPrefix)
|
|
|
|
flags.LdFlags = append(flags.LdFlags, target, gccPrefix)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Host() {
|
2015-01-31 02:27:36 +01:00
|
|
|
gccToolchain := "--gcc-toolchain=" + toolchain.GccRoot()
|
|
|
|
sysroot := "--sysroot=" + filepath.Join(toolchain.GccRoot(), "sysroot")
|
|
|
|
|
|
|
|
// TODO: also need more -B, -L flags to make host builds hermetic
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, gccToolchain, sysroot)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, gccToolchain, sysroot)
|
|
|
|
flags.LdFlags = append(flags.LdFlags, gccToolchain, sysroot)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 02:11:30 +02:00
|
|
|
flags.IncludeDirs = pathtools.PrefixPaths(c.properties.Include_dirs, ctx.AConfig().SrcDir())
|
2015-01-31 02:27:36 +01:00
|
|
|
localIncludeDirs := pathtools.PrefixPaths(c.properties.Local_include_dirs, common.ModuleSrcDir(ctx))
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, localIncludeDirs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
if !c.properties.No_default_compiler_flags {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, []string{
|
2015-01-31 02:27:36 +01:00
|
|
|
common.ModuleSrcDir(ctx),
|
|
|
|
common.ModuleOutDir(ctx),
|
|
|
|
common.ModuleGenDir(ctx),
|
|
|
|
}...)
|
|
|
|
|
2015-04-22 02:38:44 +02:00
|
|
|
if c.properties.Sdk_version == "" || ctx.Host() {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/libnativehelper/include/nativehelper")
|
2015-03-19 01:17:35 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() && !c.properties.Allow_undefined_symbols {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-22 02:38:44 +02:00
|
|
|
if ctx.Host() || c.properties.Sdk_version == "" {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
"${commonGlobalIncludes}",
|
|
|
|
toolchain.IncludeFlags())
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}")
|
2015-04-22 02:38:44 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-01-31 02:27:36 +01:00
|
|
|
toolchain.ClangCflags(),
|
|
|
|
"${commonClangGlobalCflags}",
|
2015-04-22 02:38:44 +02:00
|
|
|
fmt.Sprintf("${%sClangGlobalCflags}", ctx.Arch().HostOrDevice))
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
|
2015-04-22 02:38:44 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-01-31 02:27:36 +01:00
|
|
|
toolchain.Cflags(),
|
|
|
|
"${commonGlobalCflags}",
|
2015-04-22 02:38:44 +02:00
|
|
|
fmt.Sprintf("${%sGlobalCflags}", ctx.Arch().HostOrDevice))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Host() {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, c.properties.Host_ldlibs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-01-31 02:27:36 +01:00
|
|
|
if c.properties.Rtti {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "-frtti")
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags())
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags())
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags())
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
flags = c.ccModuleType().Flags(ctx, flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// Optimization to reduce size of build.ninja
|
|
|
|
// Replace the long list of flags for each file with a module-local variable
|
2015-03-24 01:50:24 +01:00
|
|
|
ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
|
|
|
|
ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
|
|
|
|
ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
|
|
|
|
flags.CFlags = []string{"$cflags"}
|
|
|
|
flags.CppFlags = []string{"$cppflags"}
|
|
|
|
flags.AsFlags = []string{"$asflags"}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *ccBase) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-01-31 02:27:36 +01:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compile a list of source files into objects a specified subdirectory
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *ccBase) customCompileObjs(ctx common.AndroidModuleContext, flags CCFlags,
|
2015-04-08 01:50:10 +02:00
|
|
|
subdir string, srcFiles []string) []string {
|
|
|
|
|
|
|
|
buildFlags := ccFlagsToBuilderFlags(flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-08 20:21:40 +02:00
|
|
|
srcFiles = common.ExpandSources(ctx, srcFiles)
|
2015-04-08 01:50:10 +02:00
|
|
|
srcFiles, deps := genSources(ctx, srcFiles, buildFlags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
return TransformSourceToObj(ctx, subdir, srcFiles, buildFlags, deps)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compile files listed in c.properties.Srcs into objects
|
2015-04-08 01:50:10 +02:00
|
|
|
func (c *ccBase) compileObjs(ctx common.AndroidModuleContext, flags CCFlags) []string {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
if c.properties.SkipCompileObjs {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
return c.customCompileObjs(ctx, flags, "", c.properties.Srcs)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
// Compile generated source files from dependencies
|
2015-04-08 01:50:10 +02:00
|
|
|
func (c *ccBase) compileGeneratedObjs(ctx common.AndroidModuleContext, flags CCFlags) []string {
|
2015-03-18 21:28:46 +01:00
|
|
|
var srcs []string
|
|
|
|
|
|
|
|
if c.properties.SkipCompileObjs {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
|
|
|
if gen, ok := module.(genrule.SourceFileGenerator); ok {
|
|
|
|
srcs = append(srcs, gen.GeneratedSourceFiles()...)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(srcs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
return TransformSourceToObj(ctx, "", srcs, ccFlagsToBuilderFlags(flags), nil)
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (c *ccBase) outputFile() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *ccBase) depsToPathsFromList(ctx common.AndroidModuleContext,
|
2015-01-31 02:27:36 +01:00
|
|
|
names []string) (modules []common.AndroidModule,
|
|
|
|
outputFiles []string, exportedIncludeDirs []string) {
|
|
|
|
|
|
|
|
for _, n := range names {
|
|
|
|
found := false
|
|
|
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
|
|
|
otherName := ctx.OtherModuleName(m)
|
|
|
|
if otherName != n {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if a, ok := m.(CCModuleType); ok {
|
2015-01-31 02:27:36 +01:00
|
|
|
if a.Disabled() {
|
|
|
|
// If a cc_library host+device module depends on a library that exists as both
|
|
|
|
// cc_library_shared and cc_library_host_shared, it will end up with two
|
|
|
|
// dependencies with the same name, one of which is marked disabled for each
|
|
|
|
// of host and device. Ignore the disabled one.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if a.HostOrDevice() != ctx.Arch().HostOrDevice {
|
|
|
|
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(),
|
|
|
|
otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if outputFile := a.outputFile(); outputFile != "" {
|
|
|
|
if found {
|
|
|
|
ctx.ModuleErrorf("multiple modules satisified dependency on %q", otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
outputFiles = append(outputFiles, outputFile)
|
|
|
|
modules = append(modules, a)
|
|
|
|
if i, ok := a.(ccExportedIncludeDirsProducer); ok {
|
|
|
|
exportedIncludeDirs = append(exportedIncludeDirs, i.exportedIncludeDirs()...)
|
|
|
|
}
|
|
|
|
found = true
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q missing output file", otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q not an android module", otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if !found {
|
|
|
|
ctx.ModuleErrorf("unsatisified dependency on %q", n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return modules, outputFiles, exportedIncludeDirs
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
// Convert depenedency names to paths. Takes a CCDeps containing names and returns a CCDeps
|
|
|
|
// containing paths
|
|
|
|
func (c *ccBase) depsToPaths(ctx common.AndroidModuleContext, depNames CCDeps) CCDeps {
|
|
|
|
var depPaths CCDeps
|
2015-01-31 02:27:36 +01:00
|
|
|
var newIncludeDirs []string
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
var wholeStaticLibModules []common.AndroidModule
|
|
|
|
|
|
|
|
wholeStaticLibModules, depPaths.WholeStaticLibs, newIncludeDirs =
|
|
|
|
c.depsToPathsFromList(ctx, depNames.WholeStaticLibs)
|
|
|
|
depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...)
|
|
|
|
|
|
|
|
for _, m := range wholeStaticLibModules {
|
|
|
|
if staticLib, ok := m.(ccLibraryInterface); ok && staticLib.static() {
|
|
|
|
depPaths.WholeStaticLibObjFiles =
|
|
|
|
append(depPaths.WholeStaticLibObjFiles, staticLib.allObjFiles()...)
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, depPaths.StaticLibs, newIncludeDirs = c.depsToPathsFromList(ctx, depNames.StaticLibs)
|
|
|
|
depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
_, depPaths.LateStaticLibs, newIncludeDirs = c.depsToPathsFromList(ctx, depNames.LateStaticLibs)
|
|
|
|
depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
_, depPaths.SharedLibs, newIncludeDirs = c.depsToPathsFromList(ctx, depNames.SharedLibs)
|
|
|
|
depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
|
|
|
if obj, ok := m.(*ccObject); ok {
|
|
|
|
otherName := ctx.OtherModuleName(m)
|
|
|
|
if otherName == depNames.CrtBegin {
|
|
|
|
if !c.properties.Nocrt {
|
|
|
|
depPaths.CrtBegin = obj.outputFile()
|
|
|
|
}
|
|
|
|
} else if otherName == depNames.CrtEnd {
|
|
|
|
if !c.properties.Nocrt {
|
|
|
|
depPaths.CrtEnd = obj.outputFile()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
depPaths.ObjFiles = append(depPaths.ObjFiles, obj.outputFile())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return depPaths
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
// ccLinked contains the properties and members used by libraries and executables
|
|
|
|
type ccLinked struct {
|
2015-01-31 02:27:36 +01:00
|
|
|
ccBase
|
2015-03-26 22:43:45 +01:00
|
|
|
|
|
|
|
dynamicProperties struct {
|
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func newCCDynamic(dynamic *ccLinked, module CCModuleType, hod common.HostOrDeviceSupported,
|
2015-03-17 23:06:21 +01:00
|
|
|
multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
props = append(props, &dynamic.dynamicProperties)
|
|
|
|
|
2015-03-17 23:06:21 +01:00
|
|
|
return newCCBase(&dynamic.ccBase, module, hod, multilib, props...)
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
|
2015-03-27 00:14:04 +01:00
|
|
|
if ctx.ContainsProperty("system_shared_libs") {
|
|
|
|
return c.properties.System_shared_libs
|
2015-03-28 02:23:34 +01:00
|
|
|
} else if ctx.Device() && c.properties.Sdk_version == "" {
|
|
|
|
return []string{"libc", "libm"}
|
2015-03-27 00:14:04 +01:00
|
|
|
} else {
|
2015-03-28 02:23:34 +01:00
|
|
|
return nil
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func (c *ccLinked) stl(ctx common.AndroidBaseContext) string {
|
2015-03-28 02:23:34 +01:00
|
|
|
if c.properties.Sdk_version != "" && ctx.Device() {
|
2015-03-26 22:43:45 +01:00
|
|
|
switch c.properties.Stl {
|
|
|
|
case "":
|
|
|
|
return "ndk_system"
|
|
|
|
case "c++_shared", "c++_static",
|
|
|
|
"stlport_shared", "stlport_static",
|
|
|
|
"gnustl_static":
|
|
|
|
return "ndk_lib" + c.properties.Stl
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", c.properties.Stl)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch c.properties.Stl {
|
|
|
|
case "libc++", "libc++_static",
|
|
|
|
"stlport", "stlport_static",
|
|
|
|
"libstdc++":
|
|
|
|
return c.properties.Stl
|
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
case "":
|
|
|
|
if c.shared() {
|
|
|
|
return "libc++" // TODO: mingw needs libstdc++
|
|
|
|
} else {
|
|
|
|
return "libc++_static"
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL", c.properties.Stl)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccLinked) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
|
|
|
stl := c.stl(ctx)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
switch stl {
|
|
|
|
case "libc++", "libc++_static":
|
|
|
|
flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
|
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/external/libcxx/include")
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
|
|
|
flags.LdLibs = append(flags.LdLibs, "-lc", "-lm", "-lpthread")
|
|
|
|
}
|
|
|
|
case "stlport", "stlport_static":
|
|
|
|
if ctx.Device() {
|
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs,
|
|
|
|
"${SrcDir}/external/stlport/stlport",
|
|
|
|
"${SrcDir}/bionic/libstdc++/include",
|
|
|
|
"${SrcDir}/bionic")
|
|
|
|
}
|
|
|
|
case "libstdc++":
|
|
|
|
// Using bionic's basic libstdc++. Not actually an STL. Only around until the
|
|
|
|
// tree is in good enough shape to not need it.
|
|
|
|
// Host builds will use GNU libstdc++.
|
|
|
|
if ctx.Device() {
|
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/bionic/libstdc++/include")
|
|
|
|
}
|
|
|
|
case "ndk_system":
|
2015-04-08 02:11:30 +02:00
|
|
|
ndkSrcRoot := ctx.AConfig().SrcDir() + "/prebuilts/ndk/current/sources/"
|
2015-03-26 22:43:45 +01:00
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs, ndkSrcRoot+"cxx-stl/system/include")
|
|
|
|
case "ndk_libc++_shared", "ndk_libc++_static":
|
|
|
|
// TODO(danalbert): This really shouldn't be here...
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-std=c++11")
|
|
|
|
case "ndk_libstlport_shared", "ndk_libstlport_static", "ndk_libgnustl_static":
|
|
|
|
// Nothing
|
|
|
|
case "":
|
|
|
|
// None or error.
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
|
|
|
flags.LdLibs = append(flags.LdLibs, "-lc", "-lm")
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl in ccLinked.Flags: %q", stl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccLinked) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames = c.ccBase.DepNames(ctx, depNames)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
stl := c.stl(ctx)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return depNames
|
|
|
|
}
|
|
|
|
|
|
|
|
switch stl {
|
|
|
|
case "libc++":
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, stl)
|
|
|
|
case "libstdc++":
|
|
|
|
if ctx.Device() {
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, stl)
|
|
|
|
}
|
|
|
|
case "libc++_static":
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, stl)
|
|
|
|
case "stlport":
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, "libstdc++", "libstlport")
|
|
|
|
case "stlport_static":
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libstdc++", "libstlport_static")
|
|
|
|
case "":
|
|
|
|
// None or error.
|
|
|
|
case "ndk_system":
|
|
|
|
// TODO: Make a system STL prebuilt for the NDK.
|
|
|
|
// The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have
|
|
|
|
// its own includes. The includes are handled in ccBase.Flags().
|
2015-03-28 02:23:34 +01:00
|
|
|
depNames.SharedLibs = append([]string{"libstdc++"}, depNames.SharedLibs...)
|
2015-03-26 22:43:45 +01:00
|
|
|
case "ndk_libc++_shared", "ndk_libstlport_shared":
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, stl)
|
|
|
|
case "ndk_libc++_static", "ndk_libstlport_static", "ndk_libgnustl_static":
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, stl)
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl in ccLinked.DepNames: %q", stl))
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-26 22:43:45 +01:00
|
|
|
if ctx.ModuleName() != "libcompiler_rt-extras" {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libcompiler_rt-extras")
|
|
|
|
}
|
2015-03-17 00:15:49 +01:00
|
|
|
// libgcc and libatomic have to be last on the command line
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcov", "libatomic", "libgcc")
|
2015-03-26 22:43:45 +01:00
|
|
|
|
|
|
|
if c.shared() {
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, c.systemSharedLibs(ctx)...)
|
|
|
|
}
|
2015-03-28 02:23:34 +01:00
|
|
|
|
|
|
|
if c.properties.Sdk_version != "" {
|
|
|
|
version := c.properties.Sdk_version
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs,
|
|
|
|
"ndk_libc."+version,
|
|
|
|
"ndk_libm."+version,
|
|
|
|
)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return depNames
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
// ccLinkedInterface interface is used on ccLinked to deal with static or shared variants
|
|
|
|
type ccLinkedInterface interface {
|
|
|
|
// Returns true if the build options for the module have selected a static or shared build
|
|
|
|
buildStatic() bool
|
|
|
|
buildShared() bool
|
|
|
|
|
|
|
|
// Sets whether a specific variant is static or shared
|
|
|
|
setStatic()
|
|
|
|
setShared()
|
|
|
|
|
|
|
|
// Returns whether a specific variant is static or shared
|
|
|
|
static() bool
|
|
|
|
shared() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ ccLinkedInterface = (*CCLibrary)(nil)
|
|
|
|
var _ ccLinkedInterface = (*CCBinary)(nil)
|
|
|
|
|
|
|
|
func (c *ccLinked) static() bool {
|
|
|
|
return c.dynamicProperties.VariantIsStatic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccLinked) shared() bool {
|
|
|
|
return c.dynamicProperties.VariantIsShared
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccLinked) setStatic() {
|
|
|
|
c.dynamicProperties.VariantIsStatic = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccLinked) setShared() {
|
|
|
|
c.dynamicProperties.VariantIsShared = true
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
type ccExportedIncludeDirsProducer interface {
|
|
|
|
exportedIncludeDirs() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Combined static+shared libraries
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCLibrary struct {
|
2015-03-26 22:43:45 +01:00
|
|
|
ccLinked
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
reuseFrom ccLibraryInterface
|
|
|
|
reuseObjFiles []string
|
2015-01-31 02:27:36 +01:00
|
|
|
objFiles []string
|
|
|
|
exportIncludeDirs []string
|
|
|
|
out string
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
LibraryProperties struct {
|
2015-01-31 02:27:36 +01:00
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
2015-03-26 22:43:45 +01:00
|
|
|
Static struct {
|
2015-01-31 02:27:36 +01:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func (c *CCLibrary) buildStatic() bool {
|
|
|
|
return c.LibraryProperties.BuildStatic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCLibrary) buildShared() bool {
|
|
|
|
return c.LibraryProperties.BuildShared
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type ccLibraryInterface interface {
|
2015-03-26 22:43:45 +01:00
|
|
|
ccLinkedInterface
|
2015-03-24 01:50:24 +01:00
|
|
|
ccLibrary() *CCLibrary
|
2015-03-26 22:43:45 +01:00
|
|
|
setReuseFrom(ccLibraryInterface)
|
|
|
|
getReuseFrom() ccLibraryInterface
|
|
|
|
getReuseObjFiles() []string
|
2015-03-24 01:50:24 +01:00
|
|
|
allObjFiles() []string
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
var _ ccLibraryInterface = (*CCLibrary)(nil)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) ccLibrary() *CCLibrary {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCCLibrary(library *CCLibrary, module CCModuleType,
|
|
|
|
hod common.HostOrDeviceSupported) (blueprint.Module, []interface{}) {
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
return newCCDynamic(&library.ccLinked, module, hod, common.MultilibBoth,
|
2015-03-24 01:50:24 +01:00
|
|
|
&library.LibraryProperties)
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCLibraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCLibrary{}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
module.LibraryProperties.BuildShared = true
|
|
|
|
module.LibraryProperties.BuildStatic = true
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return NewCCLibrary(module, module, common.HostAndDeviceSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *CCLibrary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-03-26 22:43:45 +01:00
|
|
|
depNames = c.ccLinked.DepNames(ctx, depNames)
|
2015-03-24 22:15:58 +01:00
|
|
|
if c.shared() {
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames.CrtBegin = "crtbegin_so"
|
|
|
|
depNames.CrtEnd = "crtend_so"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return depNames
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) outputFile() string {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.out
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func (c *CCLibrary) getReuseObjFiles() []string {
|
|
|
|
return c.reuseObjFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCLibrary) setReuseFrom(reuseFrom ccLibraryInterface) {
|
|
|
|
c.reuseFrom = reuseFrom
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCLibrary) getReuseFrom() ccLibraryInterface {
|
|
|
|
return c.reuseFrom
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) allObjFiles() []string {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.objFiles
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) exportedIncludeDirs() []string {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.exportIncludeDirs
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *CCLibrary) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-03-26 22:43:45 +01:00
|
|
|
flags = c.ccLinked.Flags(ctx, flags)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-fPIC")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
if c.shared() {
|
2015-01-31 02:27:36 +01:00
|
|
|
libName := ctx.ModuleName()
|
|
|
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
|
|
|
sharedFlag := "-Wl,-shared"
|
2015-03-24 19:13:38 +01:00
|
|
|
if c.properties.Clang || ctx.Host() {
|
2015-01-31 02:27:36 +01:00
|
|
|
sharedFlag = "-shared"
|
|
|
|
}
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-nostdlib")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
sharedFlag,
|
|
|
|
"-Wl,-soname,"+libName+sharedLibraryExtension,
|
|
|
|
)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
|
|
|
return flags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) compileStaticLibrary(ctx common.AndroidModuleContext,
|
|
|
|
flags CCFlags, deps CCDeps, objFiles []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
staticFlags := flags
|
2015-03-24 01:50:24 +01:00
|
|
|
staticFlags.CFlags = append(staticFlags.CFlags, c.LibraryProperties.Static.Cflags...)
|
2015-04-08 01:50:10 +02:00
|
|
|
objFilesStatic := c.customCompileObjs(ctx, staticFlags, common.DeviceStaticLibrary,
|
2015-03-24 01:50:24 +01:00
|
|
|
c.LibraryProperties.Static.Srcs)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
objFiles = append(objFiles, objFilesStatic...)
|
2015-03-24 22:15:58 +01:00
|
|
|
objFiles = append(objFiles, deps.WholeStaticLibObjFiles...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+staticLibraryExtension)
|
|
|
|
|
|
|
|
TransformObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
|
|
|
|
|
|
|
|
c.objFiles = objFiles
|
|
|
|
c.out = outputFile
|
|
|
|
c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs,
|
|
|
|
common.ModuleSrcDir(ctx))
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) compileSharedLibrary(ctx common.AndroidModuleContext,
|
|
|
|
flags CCFlags, deps CCDeps, objFiles []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
sharedFlags := flags
|
2015-03-24 01:50:24 +01:00
|
|
|
sharedFlags.CFlags = append(sharedFlags.CFlags, c.LibraryProperties.Shared.Cflags...)
|
2015-04-08 01:50:10 +02:00
|
|
|
objFilesShared := c.customCompileObjs(ctx, sharedFlags, common.DeviceSharedLibrary,
|
2015-03-24 01:50:24 +01:00
|
|
|
c.LibraryProperties.Shared.Srcs)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
objFiles = append(objFiles, objFilesShared...)
|
|
|
|
|
|
|
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+sharedLibraryExtension)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
|
2015-03-26 22:43:45 +01:00
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, deps.CrtBegin, deps.CrtEnd, false,
|
2015-03-17 00:15:49 +01:00
|
|
|
ccFlagsToBuilderFlags(flags), outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
c.out = outputFile
|
|
|
|
c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs,
|
|
|
|
common.ModuleSrcDir(ctx))
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) compileModule(ctx common.AndroidModuleContext,
|
|
|
|
flags CCFlags, deps CCDeps, objFiles []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// Reuse the object files from the matching static library if it exists
|
2015-03-26 22:43:45 +01:00
|
|
|
if c.getReuseFrom().ccLibrary() == c {
|
|
|
|
c.reuseObjFiles = objFiles
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-26 22:43:45 +01:00
|
|
|
objFiles = append([]string(nil), c.getReuseFrom().getReuseObjFiles()...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
if c.static() {
|
2015-01-31 02:27:36 +01:00
|
|
|
c.compileStaticLibrary(ctx, flags, deps, objFiles)
|
|
|
|
} else {
|
|
|
|
c.compileSharedLibrary(ctx, flags, deps, objFiles)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) installStaticLibrary(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-03-18 22:01:18 +01:00
|
|
|
// Static libraries do not get installed.
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) installSharedLibrary(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-03-18 22:01:18 +01:00
|
|
|
installDir := "lib"
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Toolchain.Is64Bit() {
|
2015-03-18 22:01:18 +01:00
|
|
|
installDir = "lib64"
|
|
|
|
}
|
|
|
|
|
2015-04-22 02:37:37 +02:00
|
|
|
ctx.InstallFile(filepath.Join(installDir, c.properties.Relative_install_path), c.out)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-03-26 22:43:45 +01:00
|
|
|
if c.static() {
|
2015-03-18 22:01:18 +01:00
|
|
|
c.installStaticLibrary(ctx, flags)
|
|
|
|
} else {
|
|
|
|
c.installSharedLibrary(ctx, flags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Objects (for crt*.o)
|
|
|
|
//
|
|
|
|
|
|
|
|
type ccObject struct {
|
|
|
|
ccBase
|
|
|
|
out string
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCObjectFactory() (blueprint.Module, []interface{}) {
|
2015-01-31 02:27:36 +01:00
|
|
|
module := &ccObject{}
|
|
|
|
|
2015-03-17 23:06:21 +01:00
|
|
|
return newCCBase(&module.ccBase, module, common.DeviceSupported, common.MultilibBoth)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*ccObject) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
|
|
|
|
// object files can't have any dynamic dependencies
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (*ccObject) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
// object files can't have any dynamic dependencies
|
|
|
|
return CCDeps{}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ccObject) compileModule(ctx common.AndroidModuleContext,
|
2015-03-24 01:50:24 +01:00
|
|
|
flags CCFlags, deps CCDeps, objFiles []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
var outputFile string
|
|
|
|
if len(objFiles) == 1 {
|
|
|
|
outputFile = objFiles[0]
|
|
|
|
} else {
|
|
|
|
outputFile = filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+".o")
|
|
|
|
TransformObjsToObj(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.out = outputFile
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *ccObject) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-03-18 22:01:18 +01:00
|
|
|
// Object files do not get installed.
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (c *ccObject) outputFile() string {
|
|
|
|
return c.out
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Executables
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCBinary struct {
|
2015-03-26 22:43:45 +01:00
|
|
|
ccLinked
|
2015-03-18 22:01:18 +01:00
|
|
|
out string
|
2015-03-24 01:50:24 +01:00
|
|
|
BinaryProperties struct {
|
|
|
|
// static_executable: compile executable with -static
|
|
|
|
Static_executable bool
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
// stem: set the name of the output
|
|
|
|
Stem string `android:"arch_variant"`
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-26 23:12:10 +01:00
|
|
|
// suffix: append to the name of the output
|
|
|
|
Suffix string `android:"arch_variant"`
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
// prefix_symbols: if set, add an extra objcopy --prefix-symbols= step
|
|
|
|
Prefix_symbols string
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func (c *CCBinary) buildStatic() bool {
|
|
|
|
return c.BinaryProperties.Static_executable
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCBinary) buildShared() bool {
|
|
|
|
return !c.BinaryProperties.Static_executable
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCBinary) getStem(ctx common.AndroidModuleContext) string {
|
2015-03-26 23:12:10 +01:00
|
|
|
stem := ctx.ModuleName()
|
2015-03-24 01:50:24 +01:00
|
|
|
if c.BinaryProperties.Stem != "" {
|
2015-03-26 23:12:10 +01:00
|
|
|
stem = c.BinaryProperties.Stem
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-26 23:12:10 +01:00
|
|
|
|
|
|
|
return stem + c.BinaryProperties.Suffix
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *CCBinary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-03-26 22:43:45 +01:00
|
|
|
depNames = c.ccLinked.DepNames(ctx, depNames)
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-24 01:50:24 +01:00
|
|
|
if c.BinaryProperties.Static_executable {
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames.CrtBegin = "crtbegin_static"
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames.CrtBegin = "crtbegin_dynamic"
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-24 22:15:58 +01:00
|
|
|
depNames.CrtEnd = "crtend_android"
|
2015-03-26 22:43:45 +01:00
|
|
|
|
|
|
|
if c.BinaryProperties.Static_executable {
|
|
|
|
// static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with
|
|
|
|
// --start-group/--end-group along with libgcc. If they are in deps.StaticLibs,
|
|
|
|
// move them to the beginning of deps.LateStaticLibs
|
|
|
|
var groupLibs []string
|
|
|
|
depNames.StaticLibs, groupLibs = filterList(depNames.StaticLibs,
|
|
|
|
[]string{"libc", "libc_nomalloc", "libcompiler_rt"})
|
|
|
|
depNames.LateStaticLibs = append(groupLibs, depNames.LateStaticLibs...)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-24 22:15:58 +01:00
|
|
|
return depNames
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func NewCCBinary(binary *CCBinary, module CCModuleType,
|
2015-03-27 00:09:47 +01:00
|
|
|
hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
|
|
|
props = append(props, &binary.BinaryProperties)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-27 00:09:47 +01:00
|
|
|
return newCCDynamic(&binary.ccLinked, module, hod, common.MultilibFirst, props...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCBinaryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCBinary{}
|
|
|
|
|
|
|
|
return NewCCBinary(module, module, common.HostAndDeviceSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *CCBinary) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-03-26 22:43:45 +01:00
|
|
|
flags = c.ccLinked.Flags(ctx, flags)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-fpie")
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-26 22:43:45 +01:00
|
|
|
if c.BinaryProperties.Static_executable {
|
|
|
|
// Clang driver needs -static to create static executable.
|
|
|
|
// However, bionic/linker uses -shared to overwrite.
|
|
|
|
// Linker for x86 targets does not allow coexistance of -static and -shared,
|
|
|
|
// so we add -static only if -shared is not used.
|
|
|
|
if !inList("-shared", flags.LdFlags) {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-static")
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Bstatic",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
linker := "/system/bin/linker"
|
|
|
|
if flags.Toolchain.Is64Bit() {
|
|
|
|
linker = "/system/bin/linker64"
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Bdynamic",
|
|
|
|
fmt.Sprintf("-Wl,-dynamic-linker,%s", linker),
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,-z,nocopyreloc",
|
|
|
|
)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return flags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCBinary) compileModule(ctx common.AndroidModuleContext,
|
|
|
|
flags CCFlags, deps CCDeps, objFiles []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if !c.BinaryProperties.Static_executable && inList("libc", c.properties.Static_libs) {
|
2015-01-31 02:27:36 +01:00
|
|
|
ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" +
|
|
|
|
"from static libs or set static_executable: true")
|
|
|
|
}
|
|
|
|
|
|
|
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), c.getStem(ctx))
|
2015-03-18 22:01:18 +01:00
|
|
|
c.out = outputFile
|
2015-03-26 22:44:11 +01:00
|
|
|
if c.BinaryProperties.Prefix_symbols != "" {
|
|
|
|
afterPrefixSymbols := outputFile
|
|
|
|
outputFile = outputFile + ".intermediate"
|
|
|
|
TransformBinaryPrefixSymbols(ctx, c.BinaryProperties.Prefix_symbols, outputFile,
|
|
|
|
ccFlagsToBuilderFlags(flags), afterPrefixSymbols)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
|
2015-03-26 22:43:45 +01:00
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, deps.CrtBegin, deps.CrtEnd, true,
|
2015-03-17 00:15:49 +01:00
|
|
|
ccFlagsToBuilderFlags(flags), outputFile)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCBinary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-04-22 02:37:37 +02:00
|
|
|
ctx.InstallFile(filepath.Join("bin", c.properties.Relative_install_path), c.out)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ccTest struct {
|
2015-03-24 01:50:24 +01:00
|
|
|
CCBinary
|
2015-03-19 22:05:33 +01:00
|
|
|
|
|
|
|
testProperties struct {
|
|
|
|
// test_per_src: Create a separate test for each source file. Useful when there is
|
|
|
|
// global state that can not be torn down and reset between each test suite.
|
|
|
|
Test_per_src bool
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *ccTest) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
|
|
|
flags = c.CCBinary.Flags(ctx, flags)
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING")
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Host() {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-O0", "-g")
|
|
|
|
flags.LdLibs = append(flags.LdLibs, "-lpthread")
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(danalbert): Make gtest export its dependencies.
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.IncludeDirs = append(flags.IncludeDirs,
|
2015-04-08 02:11:30 +02:00
|
|
|
filepath.Join(ctx.AConfig().SrcDir(), "external/gtest/include"))
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return flags
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (c *ccTest) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
depNames = c.CCBinary.DepNames(ctx, depNames)
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libgtest", "libgtest_main")
|
|
|
|
return depNames
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *ccTest) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-19 18:02:21 +01:00
|
|
|
ctx.InstallFile("../data/nativetest/"+ctx.ModuleName(), c.out)
|
2015-03-18 22:01:18 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
c.CCBinary.installModule(ctx, flags)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCTestFactory() (blueprint.Module, []interface{}) {
|
2015-03-18 22:01:18 +01:00
|
|
|
module := &ccTest{}
|
2015-03-27 00:09:47 +01:00
|
|
|
return NewCCBinary(&module.CCBinary, module, common.HostAndDeviceSupported,
|
|
|
|
&module.testProperties)
|
2015-03-19 22:05:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) {
|
|
|
|
if test, ok := mctx.Module().(*ccTest); ok {
|
|
|
|
if test.testProperties.Test_per_src {
|
|
|
|
testNames := make([]string, len(test.properties.Srcs))
|
|
|
|
for i, src := range test.properties.Srcs {
|
|
|
|
testNames[i] = strings.TrimSuffix(src, filepath.Ext(src))
|
|
|
|
}
|
|
|
|
tests := mctx.CreateLocalVariations(testNames...)
|
|
|
|
for i, src := range test.properties.Srcs {
|
|
|
|
tests[i].(*ccTest).properties.Srcs = []string{src}
|
2015-03-24 01:50:24 +01:00
|
|
|
tests[i].(*ccTest).BinaryProperties.Stem = testNames[i]
|
2015-03-19 22:05:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Static library
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCLibraryStaticFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCLibrary{}
|
|
|
|
module.LibraryProperties.BuildStatic = true
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return NewCCLibrary(module, module, common.HostAndDeviceSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Shared libraries
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCLibrarySharedFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCLibrary{}
|
|
|
|
module.LibraryProperties.BuildShared = true
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return NewCCLibrary(module, module, common.HostAndDeviceSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host static library
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCLibraryHostStaticFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCLibrary{}
|
|
|
|
module.LibraryProperties.BuildStatic = true
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return NewCCLibrary(module, module, common.HostSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host Shared libraries
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCLibraryHostSharedFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCLibrary{}
|
|
|
|
module.LibraryProperties.BuildShared = true
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return NewCCLibrary(module, module, common.HostSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host Binaries
|
|
|
|
//
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCBinaryHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCBinary{}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return NewCCBinary(module, module, common.HostSupported)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 00:09:47 +01:00
|
|
|
//
|
|
|
|
// Host Tests
|
|
|
|
//
|
|
|
|
|
|
|
|
func CCTestHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &ccTest{}
|
|
|
|
return NewCCBinary(&module.CCBinary, module, common.HostSupported,
|
|
|
|
&module.testProperties)
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Device libraries shipped with gcc
|
|
|
|
//
|
|
|
|
|
|
|
|
type toolchainLibrary struct {
|
2015-03-24 01:50:24 +01:00
|
|
|
CCLibrary
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*toolchainLibrary) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string {
|
|
|
|
// toolchain libraries can't have any dependencies
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
func (*toolchainLibrary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-01-31 02:27:36 +01:00
|
|
|
// toolchain libraries can't have any dependencies
|
2015-03-24 22:15:58 +01:00
|
|
|
return CCDeps{}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func ToolchainLibraryFactory() (blueprint.Module, []interface{}) {
|
2015-01-31 02:27:36 +01:00
|
|
|
module := &toolchainLibrary{}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
module.LibraryProperties.BuildStatic = true
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return newCCBase(&module.ccBase, module, common.DeviceSupported, common.MultilibBoth,
|
|
|
|
&module.LibraryProperties)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *toolchainLibrary) compileModule(ctx common.AndroidModuleContext,
|
2015-03-24 01:50:24 +01:00
|
|
|
flags CCFlags, deps CCDeps, objFiles []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
libName := ctx.ModuleName() + staticLibraryExtension
|
|
|
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), libName)
|
|
|
|
|
|
|
|
CopyGccLib(ctx, libName, ccFlagsToBuilderFlags(flags), outputFile)
|
|
|
|
|
|
|
|
c.out = outputFile
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *toolchainLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-03-18 22:01:18 +01:00
|
|
|
// Toolchain libraries do not get installed.
|
|
|
|
}
|
|
|
|
|
2015-03-19 07:38:50 +01:00
|
|
|
// NDK prebuilt libraries.
|
|
|
|
//
|
|
|
|
// These differ from regular prebuilts in that they aren't stripped and usually aren't installed
|
|
|
|
// either (with the exception of the shared STLs, which are installed to the app's directory rather
|
|
|
|
// than to the system image).
|
|
|
|
|
|
|
|
func getNdkLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, version string) string {
|
|
|
|
return fmt.Sprintf("%s/prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib",
|
2015-04-08 02:11:30 +02:00
|
|
|
ctx.AConfig().SrcDir(), version, toolchain.Name())
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ndkPrebuiltLibrary struct {
|
|
|
|
CCLibrary
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*ndkPrebuiltLibrary) AndroidDynamicDependencies(
|
|
|
|
ctx common.AndroidDynamicDependerModuleContext) []string {
|
|
|
|
|
|
|
|
// NDK libraries can't have any dependencies
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*ndkPrebuiltLibrary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
// NDK libraries can't have any dependencies
|
|
|
|
return CCDeps{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NdkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &ndkPrebuiltLibrary{}
|
|
|
|
module.LibraryProperties.BuildShared = true
|
|
|
|
return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltLibrary) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
|
|
|
|
deps CCDeps, objFiles []string) {
|
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
|
|
|
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs,
|
|
|
|
common.ModuleSrcDir(ctx))
|
|
|
|
|
|
|
|
// NDK prebuilt libraries are named like: ndk_LIBNAME.SDK_VERSION.
|
|
|
|
// We want to translate to just LIBNAME.
|
|
|
|
libName := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0]
|
|
|
|
libDir := getNdkLibDir(ctx, flags.Toolchain, c.properties.Sdk_version)
|
2015-03-26 22:43:45 +01:00
|
|
|
c.out = filepath.Join(libDir, libName+sharedLibraryExtension)
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
|
|
|
// Toolchain libraries do not get installed.
|
|
|
|
}
|
|
|
|
|
|
|
|
// The NDK STLs are slightly different from the prebuilt system libraries:
|
|
|
|
// * Are not specific to each platform version.
|
|
|
|
// * The libraries are not in a predictable location for each STL.
|
|
|
|
|
|
|
|
type ndkPrebuiltStl struct {
|
|
|
|
ndkPrebuiltLibrary
|
|
|
|
}
|
|
|
|
|
|
|
|
type ndkPrebuiltStaticStl struct {
|
|
|
|
ndkPrebuiltStl
|
|
|
|
}
|
|
|
|
|
|
|
|
type ndkPrebuiltSharedStl struct {
|
|
|
|
ndkPrebuiltStl
|
|
|
|
}
|
|
|
|
|
|
|
|
func NdkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &ndkPrebuiltSharedStl{}
|
|
|
|
module.LibraryProperties.BuildShared = true
|
|
|
|
return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NdkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &ndkPrebuiltStaticStl{}
|
|
|
|
module.LibraryProperties.BuildStatic = true
|
|
|
|
return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl string) string {
|
|
|
|
gccVersion := toolchain.GccVersion()
|
|
|
|
var libDir string
|
|
|
|
switch stl {
|
|
|
|
case "libstlport":
|
|
|
|
libDir = "cxx-stl/stlport/libs"
|
|
|
|
case "libc++":
|
|
|
|
libDir = "cxx-stl/llvm-libc++/libs"
|
|
|
|
case "libgnustl":
|
|
|
|
libDir = fmt.Sprintf("cxx-stl/gnu-libstdc++/%s/libs", gccVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
if libDir != "" {
|
2015-04-08 02:11:30 +02:00
|
|
|
ndkSrcRoot := ctx.AConfig().SrcDir() + "/prebuilts/ndk/current/sources"
|
2015-03-19 07:38:50 +01:00
|
|
|
return fmt.Sprintf("%s/%s/%s", ndkSrcRoot, libDir, ctx.Arch().Abi)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleErrorf("Unknown NDK STL: %s", stl)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltStl) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
|
|
|
|
deps CCDeps, objFiles []string) {
|
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
|
|
|
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs,
|
|
|
|
common.ModuleSrcDir(ctx))
|
|
|
|
|
|
|
|
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
|
|
|
libExt := sharedLibraryExtension
|
|
|
|
if c.LibraryProperties.BuildStatic {
|
|
|
|
libExt = staticLibraryExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
stlName := strings.TrimSuffix(libName, "_shared")
|
|
|
|
stlName = strings.TrimSuffix(stlName, "_static")
|
|
|
|
libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
|
|
|
|
c.out = libDir + "/" + libName + libExt
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func LinkageMutator(mctx blueprint.EarlyMutatorContext) {
|
2015-03-26 22:43:45 +01:00
|
|
|
if c, ok := mctx.Module().(ccLinkedInterface); ok {
|
2015-01-31 02:27:36 +01:00
|
|
|
var modules []blueprint.Module
|
2015-03-26 22:43:45 +01:00
|
|
|
if c.buildStatic() && c.buildShared() {
|
2015-01-31 02:27:36 +01:00
|
|
|
modules = mctx.CreateLocalVariations("static", "shared")
|
2015-03-26 22:43:45 +01:00
|
|
|
modules[0].(ccLinkedInterface).setStatic()
|
|
|
|
modules[1].(ccLinkedInterface).setShared()
|
|
|
|
} else if c.buildStatic() {
|
2015-01-31 02:27:36 +01:00
|
|
|
modules = mctx.CreateLocalVariations("static")
|
2015-03-26 22:43:45 +01:00
|
|
|
modules[0].(ccLinkedInterface).setStatic()
|
|
|
|
} else if c.buildShared() {
|
2015-01-31 02:27:36 +01:00
|
|
|
modules = mctx.CreateLocalVariations("shared")
|
2015-03-26 22:43:45 +01:00
|
|
|
modules[0].(ccLinkedInterface).setShared()
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
panic(fmt.Errorf("ccLibrary %q not static or shared", mctx.ModuleName()))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
|
|
|
|
if _, ok := c.(ccLibraryInterface); ok {
|
|
|
|
reuseFrom := modules[0].(ccLibraryInterface)
|
|
|
|
for _, m := range modules {
|
|
|
|
m.(ccLibraryInterface).setReuseFrom(reuseFrom)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|