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"
|
2015-10-29 01:23:31 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
"android/soong"
|
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
|
|
|
)
|
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
|
|
|
soong.RegisterModuleType("cc_library_static", CCLibraryStaticFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_shared", CCLibrarySharedFactory)
|
|
|
|
soong.RegisterModuleType("cc_library", CCLibraryFactory)
|
|
|
|
soong.RegisterModuleType("cc_object", CCObjectFactory)
|
|
|
|
soong.RegisterModuleType("cc_binary", CCBinaryFactory)
|
|
|
|
soong.RegisterModuleType("cc_test", CCTestFactory)
|
|
|
|
soong.RegisterModuleType("cc_benchmark", CCBenchmarkFactory)
|
2015-11-03 01:43:11 +01:00
|
|
|
soong.RegisterModuleType("cc_defaults", CCDefaultsFactory)
|
2015-06-17 23:20:06 +02:00
|
|
|
|
|
|
|
soong.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
|
|
|
|
soong.RegisterModuleType("ndk_prebuilt_library", NdkPrebuiltLibraryFactory)
|
|
|
|
soong.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
|
|
|
|
soong.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
|
|
|
|
soong.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
|
|
|
|
|
|
|
|
soong.RegisterModuleType("cc_library_host_static", CCLibraryHostStaticFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_host_shared", CCLibraryHostSharedFactory)
|
|
|
|
soong.RegisterModuleType("cc_binary_host", CCBinaryHostFactory)
|
|
|
|
soong.RegisterModuleType("cc_test_host", CCTestHostFactory)
|
|
|
|
soong.RegisterModuleType("cc_benchmark_host", CCBenchmarkHostFactory)
|
|
|
|
|
|
|
|
// LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
|
|
|
|
// the Go initialization order because this package depends on common, so common's init
|
|
|
|
// functions will run first.
|
2015-10-29 23:25:03 +01:00
|
|
|
common.RegisterBottomUpMutator("link", linkageMutator)
|
|
|
|
common.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
|
|
|
|
common.RegisterBottomUpMutator("deps", depsMutator)
|
2015-06-17 23:20:06 +02:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
var (
|
2015-04-08 02:11:30 +02:00
|
|
|
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", common.Config.PrebuiltOS)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
LibcRoot = pctx.SourcePathVariable("LibcRoot", "bionic/libc")
|
|
|
|
LibmRoot = pctx.SourcePathVariable("LibmRoot", "bionic/libm")
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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",
|
2015-10-21 00:21:33 +02:00
|
|
|
"-fdebug-prefix-map=/proc/self/cwd=",
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// COMMON_RELEASE_CFLAGS
|
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceGlobalCflags = []string{
|
2015-11-25 02:53:15 +01:00
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// TARGET_ERROR_FLAGS
|
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
|
|
|
}
|
|
|
|
|
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
2015-09-12 02:41:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
illegalFlags = []string{
|
|
|
|
"-w",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2015-12-19 00:11:17 +01:00
|
|
|
pctx.PrefixedPathsForOptionalSourceVariable("commonGlobalIncludes", "-isystem ",
|
2015-09-24 00:26:20 +02:00
|
|
|
[]string{
|
|
|
|
"system/core/include",
|
|
|
|
"hardware/libhardware/include",
|
|
|
|
"hardware/libhardware_legacy/include",
|
|
|
|
"hardware/ril/include",
|
|
|
|
"libnativehelper/include",
|
|
|
|
"frameworks/native/include",
|
|
|
|
"frameworks/native/opengl/include",
|
|
|
|
"frameworks/av/include",
|
|
|
|
"frameworks/base/include",
|
|
|
|
})
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
pctx.SourcePathVariable("clangPath", "prebuilts/clang/host/${HostPrebuiltTag}/3.8/bin")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
type CCModuleContext common.AndroidBaseContext
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// 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-04-25 02:31:52 +02:00
|
|
|
// Modify property values after parsing Blueprints file but before starting dependency
|
|
|
|
// resolution or build rule generation
|
2015-10-29 23:25:03 +01:00
|
|
|
ModifyProperties(CCModuleContext)
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
// Modify the ccFlags
|
2015-04-25 02:39:18 +02:00
|
|
|
flags(common.AndroidModuleContext, CCFlags) CCFlags
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
// Return list of dependency names for use in depsMutator
|
2015-04-25 02:39:18 +02:00
|
|
|
depNames(common.AndroidBaseContext, CCDeps) CCDeps
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
// Add dynamic dependencies
|
|
|
|
depsMutator(common.AndroidBottomUpMutatorContext)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Compile objects into final module
|
2015-09-24 00:26:20 +02:00
|
|
|
compileModule(common.AndroidModuleContext, CCFlags, CCPathDeps, common.Paths)
|
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
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile() common.OptionalPath
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCDeps struct {
|
2015-09-24 00:26:20 +02:00
|
|
|
StaticLibs, SharedLibs, LateStaticLibs, WholeStaticLibs []string
|
|
|
|
|
|
|
|
ObjFiles common.Paths
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
Cflags, ReexportedCflags []string
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
CrtBegin, CrtEnd string
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
type CCPathDeps struct {
|
|
|
|
StaticLibs, SharedLibs, LateStaticLibs, WholeStaticLibs common.Paths
|
|
|
|
|
|
|
|
ObjFiles common.Paths
|
|
|
|
WholeStaticLibObjFiles common.Paths
|
|
|
|
|
|
|
|
Cflags, ReexportedCflags []string
|
|
|
|
|
|
|
|
CrtBegin, CrtEnd common.OptionalPath
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCFlags struct {
|
2015-04-22 22:07:53 +02:00
|
|
|
GlobalFlags []string // Flags that apply to C, C++, and assembly source files
|
|
|
|
AsFlags []string // Flags that apply to assembly source files
|
|
|
|
CFlags []string // Flags that apply to C and C++ source files
|
|
|
|
ConlyFlags []string // Flags that apply to C source files
|
|
|
|
CppFlags []string // Flags that apply to C++ source files
|
|
|
|
YaccFlags []string // Flags that apply to Yacc source files
|
|
|
|
LdFlags []string // Flags that apply to linker command lines
|
|
|
|
|
|
|
|
Nocrt bool
|
|
|
|
Toolchain Toolchain
|
|
|
|
Clang bool
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// Properties used to compile all C or C++ modules
|
|
|
|
type CCBaseProperties struct {
|
|
|
|
// list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
|
2015-07-01 03:15:24 +02:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of source files that should not be used to build the C/C++ module.
|
|
|
|
// This is most useful in the arch/multilib variants to remove non-common files
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C and C++ compiles.
|
|
|
|
Cflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C++ compiles
|
|
|
|
Cppflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C compiles
|
|
|
|
Conlyflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for .S compiles
|
|
|
|
Asflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for .y and .yy compiles
|
|
|
|
Yaccflags []string
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for all link steps
|
|
|
|
Ldflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// the instruction set architecture to use to compile the C/C++
|
|
|
|
// module.
|
|
|
|
Instruction_set string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-09-14 21:30:50 +02:00
|
|
|
// list of files relative to the root of the source tree that will be included
|
|
|
|
// using -include.
|
|
|
|
// If possible, don't use this.
|
|
|
|
Include_files []string `android:"arch_variant"`
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-09-14 21:30:50 +02:00
|
|
|
// list of files relative to the Blueprints file that will be included
|
|
|
|
// using -include.
|
|
|
|
// If possible, don't use this.
|
|
|
|
Local_include_files []string `android:"arch_variant"`
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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
|
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C and C++ compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_cflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for .S compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_asflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of modules that should be statically linked into this module.
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of modules that should be dynamically linked into this module.
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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.
|
2015-10-29 01:23:31 +01:00
|
|
|
Allow_undefined_symbols *bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// don't link in crt_begin and crt_end. This flag should only be necessary for
|
|
|
|
// compiling crt or libc.
|
2015-10-29 01:23:31 +01:00
|
|
|
Nocrt *bool `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-09-17 00:19:33 +02:00
|
|
|
// don't link in libgcc.a
|
2015-10-29 01:23:31 +01:00
|
|
|
No_libgcc *bool
|
2015-09-17 00:19:33 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// don't insert default compiler flags into asflags, cflags,
|
|
|
|
// cppflags, conlyflags, ldflags, or include_dirs
|
2015-10-29 01:23:31 +01:00
|
|
|
No_default_compiler_flags *bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// compile module with clang instead of gcc
|
2015-10-29 01:23:31 +01:00
|
|
|
Clang *bool `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// pass -frtti instead of -fno-rtti
|
2015-10-29 01:23:31 +01:00
|
|
|
Rtti *bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// -l arguments to pass to linker for host-provided shared libraries
|
|
|
|
Host_ldlibs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// 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
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// Set for combined shared/static libraries to prevent compiling object files a second time
|
|
|
|
SkipCompileObjs bool `blueprint:"mutated"`
|
|
|
|
|
|
|
|
Debug, Release struct {
|
|
|
|
// list of module-specific flags that will be used for C and C++ compiles in debug or
|
|
|
|
// release builds
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// Minimum sdk version supported when compiling against the ndk
|
|
|
|
Sdk_version string
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// install to a subdirectory of the default install path for the module
|
|
|
|
Relative_install_path string
|
|
|
|
}
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-11-03 01:43:11 +01:00
|
|
|
type CCUnusedProperties struct {
|
|
|
|
Native_coverage *bool
|
|
|
|
Required []string
|
|
|
|
Sanitize []string `android:"arch_variant"`
|
|
|
|
Sanitize_recover []string
|
|
|
|
Strip string
|
|
|
|
Tags []string
|
|
|
|
}
|
|
|
|
|
2015-05-11 22:39:40 +02: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-11-03 01:43:11 +01:00
|
|
|
common.DefaultableModule
|
2015-05-11 22:39:40 +02:00
|
|
|
module CCModuleType
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
Properties CCBaseProperties
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-11-03 01:43:11 +01:00
|
|
|
unused CCUnusedProperties
|
2015-03-17 23:06:21 +01:00
|
|
|
|
|
|
|
installPath string
|
2015-04-28 22:30:13 +02:00
|
|
|
|
|
|
|
savedDepNames CCDeps
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02: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
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
props = append(props, &base.Properties, &base.unused)
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-11-03 01:43:11 +01:00
|
|
|
_, props = common.InitAndroidArchModule(module, hod, multilib, props...)
|
|
|
|
|
|
|
|
return common.InitDefaultableModule(module, base, props...)
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
func (c *CCBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
2015-01-31 02:27:36 +01:00
|
|
|
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-04-28 22:30:13 +02:00
|
|
|
deps := c.depsToPaths(ctx, c.savedDepNames)
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.CFlags = append(flags.CFlags, deps.Cflags...)
|
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-04-25 02:31:52 +02:00
|
|
|
func (c *CCBase) ccModuleType() CCModuleType {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.module
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
func (c *CCBase) findToolchain(ctx common.AndroidModuleContext) Toolchain {
|
2015-01-31 02:27:36 +01:00
|
|
|
arch := ctx.Arch()
|
2015-05-07 23:11:29 +02:00
|
|
|
hod := ctx.HostOrDevice()
|
2015-11-25 02:53:15 +01:00
|
|
|
ht := ctx.HostType()
|
|
|
|
factory := toolchainFactories[hod][ht][arch.ArchType]
|
2015-01-31 02:27:36 +01:00
|
|
|
if factory == nil {
|
2015-11-25 02:53:15 +01:00
|
|
|
ctx.ModuleErrorf("Toolchain not found for %s %s arch %q", hod.String(), ht.String(), arch.String())
|
2015-11-20 22:07:51 +01:00
|
|
|
return nil
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-11-21 00:35:00 +01:00
|
|
|
return factory(arch)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func (c *CCBase) ModifyProperties(ctx CCModuleContext) {
|
2015-04-25 02:31:52 +02:00
|
|
|
}
|
|
|
|
|
2015-04-28 02:49:17 +02:00
|
|
|
func (c *CCBase) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-04-25 02:31:52 +02:00
|
|
|
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...)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
|
|
|
return depNames
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func (c *CCBase) depsMutator(ctx common.AndroidBottomUpMutatorContext) {
|
2015-04-28 22:30:13 +02:00
|
|
|
c.savedDepNames = c.module.depNames(ctx, CCDeps{})
|
|
|
|
c.savedDepNames.WholeStaticLibs = lastUniqueElements(c.savedDepNames.WholeStaticLibs)
|
|
|
|
c.savedDepNames.StaticLibs = lastUniqueElements(c.savedDepNames.StaticLibs)
|
|
|
|
c.savedDepNames.SharedLibs = lastUniqueElements(c.savedDepNames.SharedLibs)
|
|
|
|
|
|
|
|
staticLibs := c.savedDepNames.WholeStaticLibs
|
|
|
|
staticLibs = append(staticLibs, c.savedDepNames.StaticLibs...)
|
|
|
|
staticLibs = append(staticLibs, c.savedDepNames.LateStaticLibs...)
|
2015-03-24 22:15:58 +01:00
|
|
|
ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, staticLibs...)
|
|
|
|
|
2015-04-28 22:30:13 +02:00
|
|
|
ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, c.savedDepNames.SharedLibs...)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
ctx.AddDependency(ctx.Module(), c.savedDepNames.ObjFiles.Strings()...)
|
2015-04-28 22:30:13 +02:00
|
|
|
if c.savedDepNames.CrtBegin != "" {
|
2015-10-29 23:25:03 +01:00
|
|
|
ctx.AddDependency(ctx.Module(), c.savedDepNames.CrtBegin)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2015-04-28 22:30:13 +02:00
|
|
|
if c.savedDepNames.CrtEnd != "" {
|
2015-10-29 23:25:03 +01:00
|
|
|
ctx.AddDependency(ctx.Module(), c.savedDepNames.CrtEnd)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func depsMutator(ctx common.AndroidBottomUpMutatorContext) {
|
|
|
|
if c, ok := ctx.Module().(CCModuleType); ok {
|
|
|
|
c.ModifyProperties(ctx)
|
|
|
|
c.depsMutator(ctx)
|
|
|
|
}
|
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-04-25 02:31:52 +02:00
|
|
|
func (c *CCBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolchain) CCFlags {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags := CCFlags{
|
2015-04-25 02:31:52 +02:00
|
|
|
CFlags: c.Properties.Cflags,
|
|
|
|
CppFlags: c.Properties.Cppflags,
|
|
|
|
ConlyFlags: c.Properties.Conlyflags,
|
|
|
|
LdFlags: c.Properties.Ldflags,
|
|
|
|
AsFlags: c.Properties.Asflags,
|
|
|
|
YaccFlags: c.Properties.Yaccflags,
|
2015-10-29 01:23:31 +01:00
|
|
|
Nocrt: Bool(c.Properties.Nocrt),
|
2015-03-24 01:50:24 +01:00
|
|
|
Toolchain: toolchain,
|
2015-10-29 01:23:31 +01:00
|
|
|
Clang: Bool(c.Properties.Clang),
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-04-22 22:07:53 +02:00
|
|
|
|
|
|
|
// Include dir cflags
|
2015-09-24 00:26:20 +02:00
|
|
|
rootIncludeDirs := common.PathsForSource(ctx, c.Properties.Include_dirs)
|
|
|
|
localIncludeDirs := common.PathsForModuleSrc(ctx, c.Properties.Local_include_dirs)
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-09-24 00:26:32 +02:00
|
|
|
includeDirsToFlags(localIncludeDirs),
|
|
|
|
includeDirsToFlags(rootIncludeDirs))
|
2015-04-22 22:07:53 +02:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
rootIncludeFiles := common.PathsForSource(ctx, c.Properties.Include_files)
|
|
|
|
localIncludeFiles := common.PathsForModuleSrc(ctx, c.Properties.Local_include_files)
|
2015-09-14 21:30:50 +02:00
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
includeFilesToFlags(rootIncludeFiles),
|
|
|
|
includeFilesToFlags(localIncludeFiles))
|
|
|
|
|
2015-10-29 01:23:31 +01:00
|
|
|
if !Bool(c.Properties.No_default_compiler_flags) {
|
2015-04-25 02:31:52 +02:00
|
|
|
if c.Properties.Sdk_version == "" || ctx.Host() {
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
"${commonGlobalIncludes}",
|
|
|
|
toolchain.IncludeFlags(),
|
2015-09-24 00:26:20 +02:00
|
|
|
"-I"+common.PathForSource(ctx, "libnativehelper/include/nativehelper").String())
|
2015-04-22 22:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, []string{
|
2015-09-24 00:26:20 +02:00
|
|
|
"-I" + common.PathForModuleSrc(ctx).String(),
|
|
|
|
"-I" + common.PathForModuleOut(ctx).String(),
|
|
|
|
"-I" + common.PathForModuleGen(ctx).String(),
|
2015-04-22 22:07:53 +02:00
|
|
|
}...)
|
|
|
|
}
|
|
|
|
|
2015-10-29 01:23:31 +01:00
|
|
|
if c.Properties.Clang == nil {
|
2015-10-20 23:29:35 +02:00
|
|
|
if ctx.Host() {
|
|
|
|
flags.Clang = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
|
|
|
|
flags.Clang = true
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
if !toolchain.ClangSupported() {
|
|
|
|
flags.Clang = false
|
|
|
|
}
|
|
|
|
|
2015-11-03 23:27:00 +01:00
|
|
|
instructionSet := c.Properties.Instruction_set
|
|
|
|
instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet)
|
|
|
|
if flags.Clang {
|
|
|
|
instructionSetFlags, err = toolchain.ClangInstructionSetFlags(instructionSet)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: debug
|
|
|
|
flags.CFlags = append(flags.CFlags, c.Properties.Release.Cflags...)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CFlags = clangFilterUnknownCflags(flags.CFlags)
|
2015-04-25 02:31:52 +02:00
|
|
|
flags.CFlags = append(flags.CFlags, c.Properties.Clang_cflags...)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, c.Properties.Clang_asflags...)
|
2015-03-24 01:50:24 +01:00
|
|
|
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-10-29 01:23:31 +01:00
|
|
|
if !Bool(c.Properties.No_default_compiler_flags) {
|
|
|
|
if ctx.Device() && !Bool(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
|
|
|
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-05-07 23:11:29 +02:00
|
|
|
fmt.Sprintf("${%sClangGlobalCflags}", ctx.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-05-07 23:11:29 +02:00
|
|
|
fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice()))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-12-16 01:07:43 +01:00
|
|
|
if Bool(ctx.AConfig().ProductVariables.Brillo) {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__")
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-10-29 01:23:31 +01:00
|
|
|
if Bool(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-04-22 22:07:53 +02:00
|
|
|
|
|
|
|
if ctx.Host() {
|
2015-04-25 02:31:52 +02:00
|
|
|
flags.LdFlags = append(flags.LdFlags, c.Properties.Host_ldlibs...)
|
2015-04-22 22:07:53 +02:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-24 01:11:30 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainClangCflags())
|
|
|
|
} else {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainCflags())
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainLdflags())
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:39:18 +02:00
|
|
|
flags = c.ccModuleType().flags(ctx, flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-12 02:41:10 +02:00
|
|
|
if c.Properties.Sdk_version == "" {
|
|
|
|
if ctx.Host() && !flags.Clang {
|
|
|
|
// The host GCC doesn't support C++14 (and is deprecated, so likely
|
|
|
|
// never will). Build these modules with C++11.
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-std=gnu++11")
|
|
|
|
} else {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-std=gnu++14")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.CFlags, _ = filterList(flags.CFlags, illegalFlags)
|
|
|
|
flags.CppFlags, _ = filterList(flags.CppFlags, illegalFlags)
|
|
|
|
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, illegalFlags)
|
|
|
|
|
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-04-25 02:39:18 +02: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-04-25 02:31:52 +02:00
|
|
|
func (c *CCBase) customCompileObjs(ctx common.AndroidModuleContext, flags CCFlags,
|
2015-09-24 00:26:20 +02:00
|
|
|
subdir string, srcFiles, excludes []string) common.Paths {
|
2015-04-08 01:50:10 +02:00
|
|
|
|
|
|
|
buildFlags := ccFlagsToBuilderFlags(flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
inputFiles := ctx.ExpandSources(srcFiles, excludes)
|
|
|
|
srcPaths, deps := genSources(ctx, inputFiles, buildFlags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
return TransformSourceToObj(ctx, subdir, srcPaths, buildFlags, deps)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
// Compile files listed in c.Properties.Srcs into objects
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCBase) compileObjs(ctx common.AndroidModuleContext, flags CCFlags) common.Paths {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
if c.Properties.SkipCompileObjs {
|
2015-01-31 02:27:36 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-01 03:15:24 +02:00
|
|
|
return c.customCompileObjs(ctx, flags, "", c.Properties.Srcs, c.Properties.Exclude_srcs)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
// Compile generated source files from dependencies
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCBase) compileGeneratedObjs(ctx common.AndroidModuleContext, flags CCFlags) common.Paths {
|
|
|
|
var srcs common.Paths
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
if c.Properties.SkipCompileObjs {
|
2015-03-18 21:28:46 +01:00
|
|
|
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-09-24 00:26:20 +02:00
|
|
|
func (c *CCBase) outputFile() common.OptionalPath {
|
|
|
|
return common.OptionalPath{}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
func (c *CCBase) depsToPathsFromList(ctx common.AndroidModuleContext,
|
2015-01-31 02:27:36 +01:00
|
|
|
names []string) (modules []common.AndroidModule,
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFiles common.Paths, exportedFlags []string) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
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-12-01 01:06:01 +01:00
|
|
|
if !a.Enabled() {
|
2015-01-31 02:27:36 +01:00
|
|
|
// 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
|
|
|
|
}
|
2015-05-07 23:11:29 +02:00
|
|
|
if a.HostOrDevice() != ctx.HostOrDevice() {
|
2015-01-31 02:27:36 +01:00
|
|
|
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(),
|
|
|
|
otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
if outputFile := a.outputFile(); outputFile.Valid() {
|
2015-01-31 02:27:36 +01:00
|
|
|
if found {
|
|
|
|
ctx.ModuleErrorf("multiple modules satisified dependency on %q", otherName)
|
|
|
|
return
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFiles = append(outputFiles, outputFile.Path())
|
2015-01-31 02:27:36 +01:00
|
|
|
modules = append(modules, a)
|
2015-04-22 22:07:53 +02:00
|
|
|
if i, ok := a.(ccExportedFlagsProducer); ok {
|
|
|
|
exportedFlags = append(exportedFlags, i.exportedFlags()...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
found = true
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q missing output file", otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q not an android module", otherName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
2015-12-18 01:39:19 +01:00
|
|
|
if !found && !inList(n, ctx.GetMissingDependencies()) {
|
2015-01-31 02:27:36 +01:00
|
|
|
ctx.ModuleErrorf("unsatisified dependency on %q", n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
return modules, outputFiles, exportedFlags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
// Convert dependency names to paths. Takes a CCDeps containing names and returns a CCPathDeps
|
2015-03-24 22:15:58 +01:00
|
|
|
// containing paths
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCBase) depsToPaths(ctx common.AndroidModuleContext, depNames CCDeps) CCPathDeps {
|
|
|
|
var depPaths CCPathDeps
|
2015-04-22 22:07:53 +02:00
|
|
|
var newCflags []string
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
var wholeStaticLibModules []common.AndroidModule
|
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
wholeStaticLibModules, depPaths.WholeStaticLibs, newCflags =
|
2015-03-24 22:15:58 +01:00
|
|
|
c.depsToPathsFromList(ctx, depNames.WholeStaticLibs)
|
2015-04-22 22:07:53 +02:00
|
|
|
depPaths.Cflags = append(depPaths.Cflags, newCflags...)
|
2015-11-17 03:00:41 +01:00
|
|
|
depPaths.ReexportedCflags = append(depPaths.ReexportedCflags, newCflags...)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
_, depPaths.StaticLibs, newCflags = c.depsToPathsFromList(ctx, depNames.StaticLibs)
|
|
|
|
depPaths.Cflags = append(depPaths.Cflags, newCflags...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
_, depPaths.LateStaticLibs, newCflags = c.depsToPathsFromList(ctx, depNames.LateStaticLibs)
|
|
|
|
depPaths.Cflags = append(depPaths.Cflags, newCflags...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
_, depPaths.SharedLibs, newCflags = c.depsToPathsFromList(ctx, depNames.SharedLibs)
|
|
|
|
depPaths.Cflags = append(depPaths.Cflags, newCflags...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
2015-04-29 03:17:56 +02:00
|
|
|
if obj, ok := m.(ccObjectProvider); ok {
|
2015-03-24 22:15:58 +01:00
|
|
|
otherName := ctx.OtherModuleName(m)
|
|
|
|
if otherName == depNames.CrtBegin {
|
2015-10-29 01:23:31 +01:00
|
|
|
if !Bool(c.Properties.Nocrt) {
|
2015-04-29 03:17:56 +02:00
|
|
|
depPaths.CrtBegin = obj.object().outputFile()
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
|
|
|
} else if otherName == depNames.CrtEnd {
|
2015-10-29 01:23:31 +01:00
|
|
|
if !Bool(c.Properties.Nocrt) {
|
2015-04-29 03:17:56 +02:00
|
|
|
depPaths.CrtEnd = obj.object().outputFile()
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-09-24 00:26:20 +02:00
|
|
|
output := obj.object().outputFile()
|
|
|
|
if output.Valid() {
|
|
|
|
depPaths.ObjFiles = append(depPaths.ObjFiles, output.Path())
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %s did not provide an output file", otherName)
|
|
|
|
}
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return depPaths
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
type ccLinkedProperties struct {
|
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
|
|
|
VariantIsStaticBinary bool `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
// CCLinked contains the properties and members used by libraries and executables
|
|
|
|
type CCLinked struct {
|
|
|
|
CCBase
|
2015-05-11 22:39:40 +02:00
|
|
|
dynamicProperties ccLinkedProperties
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02: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-04-25 02:31:52 +02:00
|
|
|
return newCCBase(&dynamic.CCBase, module, hod, multilib, props...)
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
func (c *CCLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string {
|
2015-10-29 01:23:31 +01:00
|
|
|
if c.Properties.System_shared_libs != nil {
|
2015-04-25 02:31:52 +02:00
|
|
|
return c.Properties.System_shared_libs
|
|
|
|
} else if ctx.Device() && c.Properties.Sdk_version == "" {
|
2015-03-28 02:23:34 +01:00
|
|
|
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-04-25 02:31:52 +02:00
|
|
|
func (c *CCLinked) stl(ctx common.AndroidBaseContext) string {
|
|
|
|
if c.Properties.Sdk_version != "" && ctx.Device() {
|
|
|
|
switch c.Properties.Stl {
|
2015-03-26 22:43:45 +01:00
|
|
|
case "":
|
|
|
|
return "ndk_system"
|
|
|
|
case "c++_shared", "c++_static",
|
|
|
|
"stlport_shared", "stlport_static",
|
|
|
|
"gnustl_static":
|
2015-04-25 02:31:52 +02:00
|
|
|
return "ndk_lib" + c.Properties.Stl
|
2015-03-26 22:43:45 +01:00
|
|
|
default:
|
2015-04-25 02:31:52 +02:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", c.Properties.Stl)
|
2015-03-26 22:43:45 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
if ctx.HostType() == common.Windows {
|
|
|
|
switch c.Properties.Stl {
|
|
|
|
case "libc++", "libc++_static", "libstdc++", "":
|
|
|
|
// libc++ is not supported on mingw
|
|
|
|
return "libstdc++"
|
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL", c.Properties.Stl)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch c.Properties.Stl {
|
|
|
|
case "libc++", "libc++_static",
|
|
|
|
"libstdc++":
|
|
|
|
return c.Properties.Stl
|
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
case "":
|
|
|
|
if c.static() {
|
|
|
|
return "libc++_static"
|
|
|
|
} else {
|
|
|
|
return "libc++"
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL", c.Properties.Stl)
|
|
|
|
return ""
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
var hostDynamicGccLibs, hostStaticGccLibs map[common.HostType][]string
|
2015-05-01 01:36:18 +02:00
|
|
|
|
|
|
|
func init() {
|
2015-11-25 02:53:15 +01:00
|
|
|
hostDynamicGccLibs = map[common.HostType][]string{
|
|
|
|
common.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"},
|
|
|
|
common.Darwin: []string{"-lc", "-lSystem"},
|
|
|
|
common.Windows: []string{"-lmsvcr110", "-lmingw32", "-lgcc", "-lmoldname",
|
|
|
|
"-lmingwex", "-lmsvcrt", "-ladvapi32", "-lshell32", "-luser32",
|
|
|
|
"-lkernel32", "-lmingw32", "-lgcc", "-lmoldname", "-lmingwex",
|
|
|
|
"-lmsvcrt"},
|
|
|
|
}
|
|
|
|
hostStaticGccLibs = map[common.HostType][]string{
|
|
|
|
common.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"},
|
|
|
|
common.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"},
|
|
|
|
common.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"},
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-27 20:13:34 +02:00
|
|
|
|
2015-04-28 02:49:17 +02:00
|
|
|
func (c *CCLinked) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-03-26 22:43:45 +01:00
|
|
|
stl := c.stl(ctx)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
switch stl {
|
|
|
|
case "libc++", "libc++_static":
|
|
|
|
flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
2015-04-27 20:13:34 +02:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
|
2015-04-28 22:20:37 +02:00
|
|
|
if c.staticBinary() {
|
2015-11-25 02:53:15 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.HostType()]...)
|
2015-04-28 22:20:37 +02:00
|
|
|
} else {
|
2015-11-25 02:53:15 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.HostType()]...)
|
2015-04-27 20:13:34 +02:00
|
|
|
}
|
2015-09-12 02:41:10 +02:00
|
|
|
} else {
|
|
|
|
if ctx.Arch().ArchType == common.Arm {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,libunwind_llvm.a")
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
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() {
|
2015-09-24 00:26:20 +02:00
|
|
|
flags.CFlags = append(flags.CFlags, "-I"+common.PathForSource(ctx, "bionic/libstdc++/include").String())
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
case "ndk_system":
|
2015-09-24 00:26:20 +02:00
|
|
|
ndkSrcRoot := common.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include")
|
|
|
|
flags.CFlags = append(flags.CFlags, "-isystem "+ndkSrcRoot.String())
|
2015-03-26 22:43:45 +01:00
|
|
|
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")
|
2015-04-28 22:20:37 +02:00
|
|
|
if c.staticBinary() {
|
2015-11-25 02:53:15 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.HostType()]...)
|
2015-04-28 22:20:37 +02:00
|
|
|
} else {
|
2015-11-25 02:53:15 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.HostType()]...)
|
2015-04-27 20:13:34 +02:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
default:
|
2015-04-25 02:31:52 +02:00
|
|
|
panic(fmt.Errorf("Unknown stl in CCLinked.Flags: %q", stl))
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2015-04-28 02:49:17 +02:00
|
|
|
func (c *CCLinked) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
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 "libstdc++":
|
|
|
|
if ctx.Device() {
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, stl)
|
|
|
|
}
|
2015-04-28 22:30:13 +02:00
|
|
|
case "libc++", "libc++_static":
|
|
|
|
if stl == "libc++" {
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, stl)
|
|
|
|
} else {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, stl)
|
|
|
|
}
|
|
|
|
if ctx.Device() {
|
|
|
|
if ctx.Arch().ArchType == common.Arm {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libunwind_llvm")
|
|
|
|
}
|
|
|
|
if c.staticBinary() {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libdl")
|
|
|
|
} else {
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, "libdl")
|
|
|
|
}
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
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
|
2015-04-25 02:31:52 +02:00
|
|
|
// 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:
|
2015-04-28 02:49:17 +02:00
|
|
|
panic(fmt.Errorf("Unknown stl in CCLinked.depNames: %q", stl))
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:30:13 +02:00
|
|
|
if ctx.ModuleName() != "libcompiler_rt-extras" {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libcompiler_rt-extras")
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-03-17 00:15:49 +01:00
|
|
|
// libgcc and libatomic have to be last on the command line
|
2015-09-17 00:19:33 +02:00
|
|
|
depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcov", "libatomic")
|
2015-10-29 01:23:31 +01:00
|
|
|
if !Bool(c.Properties.No_libgcc) {
|
2015-09-17 00:19:33 +02:00
|
|
|
depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcc")
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2015-04-28 22:20:37 +02:00
|
|
|
if !c.static() {
|
2015-03-26 22:43:45 +01:00
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, c.systemSharedLibs(ctx)...)
|
|
|
|
}
|
2015-03-28 02:23:34 +01:00
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
if c.Properties.Sdk_version != "" {
|
|
|
|
version := c.Properties.Sdk_version
|
2015-03-28 02:23:34 +01:00
|
|
|
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
|
2015-04-28 22:20:37 +02:00
|
|
|
setStatic(bool)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2015-04-28 22:20:37 +02:00
|
|
|
// Returns whether a specific variant is a static library or binary
|
2015-03-26 22:43:45 +01:00
|
|
|
static() bool
|
2015-04-28 22:20:37 +02:00
|
|
|
|
|
|
|
// Returns whether a module is a static binary
|
|
|
|
staticBinary() bool
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ ccLinkedInterface = (*CCLibrary)(nil)
|
|
|
|
var _ ccLinkedInterface = (*CCBinary)(nil)
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
func (c *CCLinked) static() bool {
|
2015-03-26 22:43:45 +01:00
|
|
|
return c.dynamicProperties.VariantIsStatic
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:20:37 +02:00
|
|
|
func (c *CCLinked) staticBinary() bool {
|
|
|
|
return c.dynamicProperties.VariantIsStaticBinary
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:20:37 +02:00
|
|
|
func (c *CCLinked) setStatic(static bool) {
|
|
|
|
c.dynamicProperties.VariantIsStatic = static
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
type ccExportedFlagsProducer interface {
|
|
|
|
exportedFlags() []string
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Combined static+shared libraries
|
|
|
|
//
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
type CCLibraryProperties struct {
|
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
|
|
|
Static struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
2015-07-01 03:15:24 +02:00
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2015-05-11 22:39:40 +02:00
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
2015-07-01 03:15:24 +02:00
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2015-05-11 22:39:40 +02:00
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2015-07-07 02:48:31 +02:00
|
|
|
|
|
|
|
// local file name to pass to the linker as --version_script
|
2015-09-24 00:26:20 +02:00
|
|
|
Version_script *string `android:"arch_variant"`
|
2015-12-04 23:59:08 +01:00
|
|
|
// local file name to pass to the linker as -unexported_symbols_list
|
2015-09-24 00:26:20 +02:00
|
|
|
Unexported_symbols_list *string `android:"arch_variant"`
|
2015-12-04 23:59:08 +01:00
|
|
|
// local file name to pass to the linker as -force_symbols_not_weak_list
|
2015-09-24 00:26:20 +02:00
|
|
|
Force_symbols_not_weak_list *string `android:"arch_variant"`
|
2015-12-04 23:59:08 +01:00
|
|
|
// local file name to pass to the linker as -force_symbols_weak_list
|
2015-09-24 00:26:20 +02:00
|
|
|
Force_symbols_weak_list *string `android:"arch_variant"`
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCLibrary struct {
|
2015-04-25 02:31:52 +02:00
|
|
|
CCLinked
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
reuseFrom ccLibraryInterface
|
2015-09-24 00:26:20 +02:00
|
|
|
reuseObjFiles common.Paths
|
|
|
|
objFiles common.Paths
|
2015-04-22 22:07:53 +02:00
|
|
|
exportFlags []string
|
2015-09-24 00:26:20 +02:00
|
|
|
out common.Path
|
2015-07-09 03:13:11 +02:00
|
|
|
systemLibs []string
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
LibraryProperties CCLibraryProperties
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
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
|
2015-09-24 00:26:20 +02:00
|
|
|
getReuseObjFiles() common.Paths
|
|
|
|
allObjFiles() common.Paths
|
2015-03-24 01:50:24 +01:00
|
|
|
}
|
|
|
|
|
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-04-25 02:31:52 +02: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-04-25 02:39:18 +02:00
|
|
|
func (c *CCLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-04-28 02:49:17 +02:00
|
|
|
depNames = c.CCLinked.depNames(ctx, depNames)
|
2015-04-28 22:23:52 +02:00
|
|
|
if c.static() {
|
|
|
|
depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.LibraryProperties.Static.Whole_static_libs...)
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, c.LibraryProperties.Static.Static_libs...)
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, c.LibraryProperties.Static.Shared_libs...)
|
|
|
|
} else {
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-04-29 03:17:56 +02:00
|
|
|
if c.Properties.Sdk_version == "" {
|
|
|
|
depNames.CrtBegin = "crtbegin_so"
|
|
|
|
depNames.CrtEnd = "crtend_so"
|
|
|
|
} else {
|
|
|
|
depNames.CrtBegin = "ndk_crtbegin_so." + c.Properties.Sdk_version
|
|
|
|
depNames.CrtEnd = "ndk_crtend_so." + c.Properties.Sdk_version
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-04-28 22:23:52 +02:00
|
|
|
depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.LibraryProperties.Shared.Whole_static_libs...)
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, c.LibraryProperties.Shared.Static_libs...)
|
|
|
|
depNames.SharedLibs = append(depNames.SharedLibs, c.LibraryProperties.Shared.Shared_libs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2015-07-09 03:13:11 +02:00
|
|
|
c.systemLibs = c.systemSharedLibs(ctx)
|
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return depNames
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCLibrary) outputFile() common.OptionalPath {
|
|
|
|
return common.OptionalPathForPath(c.out)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCLibrary) getReuseObjFiles() common.Paths {
|
2015-03-26 22:43:45 +01:00
|
|
|
return c.reuseObjFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCLibrary) setReuseFrom(reuseFrom ccLibraryInterface) {
|
|
|
|
c.reuseFrom = reuseFrom
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCLibrary) getReuseFrom() ccLibraryInterface {
|
|
|
|
return c.reuseFrom
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCLibrary) allObjFiles() common.Paths {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.objFiles
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:07:53 +02:00
|
|
|
func (c *CCLibrary) exportedFlags() []string {
|
|
|
|
return c.exportFlags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:39:18 +02:00
|
|
|
func (c *CCLibrary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-04-28 02:49:17 +02:00
|
|
|
flags = c.CCLinked.flags(ctx, flags)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
|
|
|
// all code is position independent, and then those warnings get promoted to
|
|
|
|
// errors.
|
|
|
|
if ctx.HostType() != common.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-fPIC")
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-04-29 02:39:43 +02:00
|
|
|
if c.static() {
|
|
|
|
flags.CFlags = append(flags.CFlags, c.LibraryProperties.Static.Cflags...)
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, c.LibraryProperties.Shared.Cflags...)
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:20:37 +02:00
|
|
|
if !c.static() {
|
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-10-20 23:29:35 +02:00
|
|
|
if flags.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
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-dynamiclib",
|
|
|
|
"-single_module",
|
|
|
|
//"-read_only_relocs suppress",
|
2015-11-25 02:53:15 +01:00
|
|
|
"-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(),
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
sharedFlag,
|
2015-11-25 02:53:15 +01:00
|
|
|
"-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix(),
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
}
|
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,
|
2015-09-24 00:26:20 +02:00
|
|
|
flags CCFlags, deps CCPathDeps, objFiles common.Paths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
staticFlags := flags
|
2015-04-08 01:50:10 +02:00
|
|
|
objFilesStatic := c.customCompileObjs(ctx, staticFlags, common.DeviceStaticLibrary,
|
2015-07-01 03:15:24 +02:00
|
|
|
c.LibraryProperties.Static.Srcs, c.LibraryProperties.Static.Exclude_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
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
|
|
|
TransformDarwinObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
|
|
|
|
} else {
|
|
|
|
TransformObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
c.objFiles = objFiles
|
|
|
|
c.out = outputFile
|
2015-05-12 20:36:53 +02:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, c.Properties.Export_include_dirs)
|
2015-04-22 22:07:53 +02:00
|
|
|
c.exportFlags = []string{includeDirsToFlags(includeDirs)}
|
2015-11-17 03:00:41 +01:00
|
|
|
c.exportFlags = append(c.exportFlags, deps.ReexportedCflags...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) compileSharedLibrary(ctx common.AndroidModuleContext,
|
2015-09-24 00:26:20 +02:00
|
|
|
flags CCFlags, deps CCPathDeps, objFiles common.Paths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
sharedFlags := flags
|
2015-04-08 01:50:10 +02:00
|
|
|
objFilesShared := c.customCompileObjs(ctx, sharedFlags, common.DeviceSharedLibrary,
|
2015-07-01 03:15:24 +02:00
|
|
|
c.LibraryProperties.Shared.Srcs, c.LibraryProperties.Shared.Exclude_srcs)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
objFiles = append(objFiles, objFilesShared...)
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, ctx.ModuleName()+flags.Toolchain.ShlibSuffix())
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var linkerDeps common.Paths
|
2015-07-07 02:48:31 +02:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
versionScript := common.OptionalPathForModuleSrc(ctx, c.LibraryProperties.Version_script)
|
|
|
|
unexportedSymbols := common.OptionalPathForModuleSrc(ctx, c.LibraryProperties.Unexported_symbols_list)
|
|
|
|
forceNotWeakSymbols := common.OptionalPathForModuleSrc(ctx, c.LibraryProperties.Force_symbols_not_weak_list)
|
|
|
|
forceWeakSymbols := common.OptionalPathForModuleSrc(ctx, c.LibraryProperties.Force_symbols_weak_list)
|
2015-12-04 23:59:08 +01:00
|
|
|
if !ctx.Darwin() {
|
2015-09-24 00:26:20 +02:00
|
|
|
if versionScript.Valid() {
|
|
|
|
sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
|
|
|
linkerDeps = append(linkerDeps, versionScript.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if unexportedSymbols.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceNotWeakSymbols.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceWeakSymbols.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-24 00:26:20 +02:00
|
|
|
if versionScript.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if unexportedSymbols.Valid() {
|
|
|
|
sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceNotWeakSymbols.Valid() {
|
|
|
|
sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceWeakSymbols.Valid() {
|
|
|
|
sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-07-07 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
|
2015-07-07 02:48:31 +02:00
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, false,
|
2015-11-24 21:58:57 +01:00
|
|
|
ccFlagsToBuilderFlags(sharedFlags), outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
c.out = outputFile
|
2015-09-24 00:26:20 +02:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, c.Properties.Export_include_dirs)
|
2015-04-22 22:07:53 +02:00
|
|
|
c.exportFlags = []string{includeDirsToFlags(includeDirs)}
|
2015-11-17 03:00:41 +01:00
|
|
|
c.exportFlags = append(c.exportFlags, deps.ReexportedCflags...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func (c *CCLibrary) compileModule(ctx common.AndroidModuleContext,
|
2015-09-24 00:26:20 +02:00
|
|
|
flags CCFlags, deps CCPathDeps, objFiles common.Paths) {
|
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-04-28 22:23:52 +02:00
|
|
|
if c.getReuseFrom().ccLibrary().LibraryProperties.Static.Cflags == nil &&
|
|
|
|
c.LibraryProperties.Shared.Cflags == nil {
|
2015-09-24 00:26:20 +02:00
|
|
|
objFiles = append(common.Paths(nil), c.getReuseFrom().getReuseObjFiles()...)
|
2015-04-28 22:23:52 +02:00
|
|
|
}
|
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-12-21 23:55:28 +01:00
|
|
|
ctx.InstallFile(common.PathForModuleInstall(ctx, 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)
|
|
|
|
//
|
|
|
|
|
2015-04-29 03:17:56 +02:00
|
|
|
type ccObjectProvider interface {
|
|
|
|
object() *ccObject
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
type ccObject struct {
|
2015-04-25 02:31:52 +02:00
|
|
|
CCBase
|
2015-09-24 00:26:20 +02:00
|
|
|
out common.OptionalPath
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 03:17:56 +02:00
|
|
|
func (c *ccObject) object() *ccObject {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCObjectFactory() (blueprint.Module, []interface{}) {
|
2015-01-31 02:27:36 +01:00
|
|
|
module := &ccObject{}
|
|
|
|
|
2015-04-25 02:31:52 +02:00
|
|
|
return newCCBase(&module.CCBase, module, common.DeviceSupported, common.MultilibBoth)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:39:18 +02:00
|
|
|
func (*ccObject) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-03-24 22:15:58 +01:00
|
|
|
// 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-09-24 00:26:20 +02:00
|
|
|
flags CCFlags, deps CCPathDeps, objFiles common.Paths) {
|
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
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var outputFile common.Path
|
2015-01-31 02:27:36 +01:00
|
|
|
if len(objFiles) == 1 {
|
|
|
|
outputFile = objFiles[0]
|
|
|
|
} else {
|
2015-09-24 00:26:20 +02:00
|
|
|
output := common.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
|
|
|
|
TransformObjsToObj(ctx, objFiles, ccFlagsToBuilderFlags(flags), output)
|
|
|
|
outputFile = output
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
c.out = common.OptionalPathForPath(outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
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-09-24 00:26:20 +02:00
|
|
|
func (c *ccObject) outputFile() common.OptionalPath {
|
2015-01-31 02:27:36 +01:00
|
|
|
return c.out
|
|
|
|
}
|
|
|
|
|
2015-04-29 03:17:56 +02:00
|
|
|
var _ ccObjectProvider = (*ccObject)(nil)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Executables
|
|
|
|
//
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
type CCBinaryProperties struct {
|
|
|
|
// compile executable with -static
|
2015-10-29 01:23:31 +01:00
|
|
|
Static_executable *bool
|
2015-05-11 22:39:40 +02:00
|
|
|
|
|
|
|
// set the name of the output
|
|
|
|
Stem string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// append to the name of the output
|
|
|
|
Suffix string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// if set, add an extra objcopy --prefix-symbols= step
|
|
|
|
Prefix_symbols string
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type CCBinary struct {
|
2015-04-25 02:31:52 +02:00
|
|
|
CCLinked
|
2015-09-24 00:26:20 +02:00
|
|
|
out common.Path
|
|
|
|
installFile common.Path
|
2015-05-11 22:39:40 +02:00
|
|
|
BinaryProperties CCBinaryProperties
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
func (c *CCBinary) buildStatic() bool {
|
2015-10-29 01:23:31 +01:00
|
|
|
return Bool(c.BinaryProperties.Static_executable)
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCBinary) buildShared() bool {
|
2015-10-29 01:23:31 +01:00
|
|
|
return !Bool(c.BinaryProperties.Static_executable)
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
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-04-25 02:39:18 +02:00
|
|
|
func (c *CCBinary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-04-28 02:49:17 +02:00
|
|
|
depNames = c.CCLinked.depNames(ctx, depNames)
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-04-29 03:17:56 +02:00
|
|
|
if c.Properties.Sdk_version == "" {
|
2015-10-29 01:23:31 +01:00
|
|
|
if Bool(c.BinaryProperties.Static_executable) {
|
2015-04-29 03:17:56 +02:00
|
|
|
depNames.CrtBegin = "crtbegin_static"
|
|
|
|
} else {
|
|
|
|
depNames.CrtBegin = "crtbegin_dynamic"
|
|
|
|
}
|
|
|
|
depNames.CrtEnd = "crtend_android"
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-10-29 01:23:31 +01:00
|
|
|
if Bool(c.BinaryProperties.Static_executable) {
|
2015-04-29 03:17:56 +02:00
|
|
|
depNames.CrtBegin = "ndk_crtbegin_static." + c.Properties.Sdk_version
|
|
|
|
} else {
|
|
|
|
depNames.CrtBegin = "ndk_crtbegin_dynamic." + c.Properties.Sdk_version
|
|
|
|
}
|
|
|
|
depNames.CrtEnd = "ndk_crtend_android." + c.Properties.Sdk_version
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2015-10-29 01:23:31 +01:00
|
|
|
if Bool(c.BinaryProperties.Static_executable) {
|
2015-04-28 22:30:13 +02:00
|
|
|
if c.stl(ctx) == "libc++_static" {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libm", "libc", "libdl")
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
// 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-12-22 00:25:58 +01:00
|
|
|
hod common.HostOrDeviceSupported, multilib common.Multilib,
|
|
|
|
props ...interface{}) (blueprint.Module, []interface{}) {
|
2015-03-27 00:09:47 +01:00
|
|
|
|
|
|
|
props = append(props, &binary.BinaryProperties)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-12-22 00:25:58 +01:00
|
|
|
return newCCDynamic(&binary.CCLinked, module, hod, multilib, props...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCBinaryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCBinary{}
|
|
|
|
|
2015-12-22 00:25:58 +01:00
|
|
|
return NewCCBinary(module, module, common.HostAndDeviceSupported, common.MultilibFirst)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func (c *CCBinary) ModifyProperties(ctx CCModuleContext) {
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
2015-10-29 01:23:31 +01:00
|
|
|
c.BinaryProperties.Static_executable = proptools.BoolPtr(false)
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
2015-10-29 01:23:31 +01:00
|
|
|
if Bool(c.BinaryProperties.Static_executable) {
|
2015-04-28 22:20:37 +02:00
|
|
|
c.dynamicProperties.VariantIsStaticBinary = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:39:18 +02:00
|
|
|
func (c *CCBinary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-04-28 02:49:17 +02:00
|
|
|
flags = c.CCLinked.flags(ctx, flags)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
if ctx.Host() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-pie")
|
|
|
|
if ctx.HostType() == common.Windows {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
|
|
|
// all code is position independent, and then those warnings get promoted to
|
|
|
|
// errors.
|
|
|
|
if ctx.HostType() != common.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-fpie")
|
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2015-10-29 01:23:31 +01:00
|
|
|
if Bool(c.BinaryProperties.Static_executable) {
|
2015-03-26 22:43:45 +01:00
|
|
|
// 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,
|
2015-12-01 23:09:48 +01:00
|
|
|
"-pie",
|
2015-03-26 22:43:45 +01:00
|
|
|
"-nostdlib",
|
|
|
|
"-Bdynamic",
|
|
|
|
fmt.Sprintf("-Wl,-dynamic-linker,%s", linker),
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,-z,nocopyreloc",
|
|
|
|
)
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
} else if ctx.Darwin() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names")
|
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,
|
2015-09-24 00:26:20 +02:00
|
|
|
flags CCFlags, deps CCPathDeps, objFiles common.Paths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-10-29 01:23:31 +01:00
|
|
|
if !Bool(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")
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, c.getStem(ctx)+flags.Toolchain.ExecutableSuffix())
|
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
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile = common.PathForModuleOut(ctx, c.getStem(ctx)+".intermediate")
|
2015-03-26 22:44:11 +01:00
|
|
|
TransformBinaryPrefixSymbols(ctx, c.BinaryProperties.Prefix_symbols, outputFile,
|
|
|
|
ccFlagsToBuilderFlags(flags), afterPrefixSymbols)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var linkerDeps common.Paths
|
2015-07-07 02:48:31 +02:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
|
2015-07-07 02:48:31 +02:00
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, 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-12-21 23:55:28 +01:00
|
|
|
c.installFile = ctx.InstallFile(common.PathForModuleInstall(ctx, "bin", c.Properties.Relative_install_path), c.out)
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func (c *CCBinary) HostToolPath() common.OptionalPath {
|
2015-04-28 22:25:36 +02:00
|
|
|
if c.HostOrDevice().Host() {
|
2015-09-24 00:26:20 +02:00
|
|
|
return common.OptionalPathForPath(c.installFile)
|
2015-04-28 22:25:36 +02:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
return common.OptionalPath{}
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-09-17 01:00:08 +02:00
|
|
|
func (c *CCBinary) binary() *CCBinary {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
type testPerSrc interface {
|
|
|
|
binary() *CCBinary
|
|
|
|
testPerSrc() bool
|
|
|
|
}
|
|
|
|
|
2015-12-22 00:25:58 +01:00
|
|
|
var _ testPerSrc = (*CCTest)(nil)
|
2015-09-17 01:00:08 +02:00
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func testPerSrcMutator(mctx common.AndroidBottomUpMutatorContext) {
|
2015-09-17 01:00:08 +02:00
|
|
|
if test, ok := mctx.Module().(testPerSrc); ok {
|
|
|
|
if test.testPerSrc() {
|
|
|
|
testNames := make([]string, len(test.binary().Properties.Srcs))
|
|
|
|
for i, src := range test.binary().Properties.Srcs {
|
|
|
|
testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
|
|
|
|
}
|
|
|
|
tests := mctx.CreateLocalVariations(testNames...)
|
|
|
|
for i, src := range test.binary().Properties.Srcs {
|
|
|
|
tests[i].(testPerSrc).binary().Properties.Srcs = []string{src}
|
2015-12-22 00:25:58 +01:00
|
|
|
tests[i].(testPerSrc).binary().BinaryProperties.Stem = testNames[i]
|
2015-09-17 01:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 00:25:58 +01:00
|
|
|
type CCTestProperties struct {
|
|
|
|
// if set, build against the gtest library. Defaults to true.
|
|
|
|
Gtest bool
|
|
|
|
|
|
|
|
// Create a separate binary 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-04-25 02:48:09 +02:00
|
|
|
type CCTest struct {
|
2015-03-24 01:50:24 +01:00
|
|
|
CCBinary
|
2015-12-22 00:25:58 +01:00
|
|
|
|
|
|
|
TestProperties CCTestProperties
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:48:09 +02:00
|
|
|
func (c *CCTest) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
2015-04-25 02:39:18 +02:00
|
|
|
flags = c.CCBinary.flags(ctx, flags)
|
2015-12-22 00:25:58 +01:00
|
|
|
if !c.TestProperties.Gtest {
|
|
|
|
return 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")
|
2015-12-22 00:25:58 +01:00
|
|
|
|
|
|
|
if ctx.HostType() == common.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-lpthread")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID")
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(danalbert): Make gtest export its dependencies.
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.CFlags = append(flags.CFlags,
|
2015-09-24 00:26:20 +02:00
|
|
|
"-I"+common.PathForSource(ctx, "external/gtest/include").String())
|
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-04-25 02:48:09 +02:00
|
|
|
func (c *CCTest) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-12-22 00:25:58 +01:00
|
|
|
if c.TestProperties.Gtest {
|
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libgtest_main", "libgtest")
|
|
|
|
}
|
2015-04-28 22:26:49 +02:00
|
|
|
depNames = c.CCBinary.depNames(ctx, depNames)
|
2015-03-24 22:15:58 +01:00
|
|
|
return depNames
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-12-21 23:55:28 +01:00
|
|
|
func (c *CCTest) InstallInData() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:48:09 +02:00
|
|
|
func (c *CCTest) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-12-22 00:25:58 +01:00
|
|
|
installDir := "nativetest"
|
|
|
|
if flags.Toolchain.Is64Bit() {
|
|
|
|
installDir = "nativetest64"
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
2015-12-22 00:25:58 +01:00
|
|
|
ctx.InstallFile(common.PathForModuleInstall(ctx, installDir, ctx.ModuleName()), c.out)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCTest) testPerSrc() bool {
|
|
|
|
return Bool(c.TestProperties.Test_per_src)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:48:09 +02:00
|
|
|
func NewCCTest(test *CCTest, module CCModuleType,
|
|
|
|
hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
2015-12-22 00:25:58 +01:00
|
|
|
props = append(props, &test.TestProperties)
|
|
|
|
|
|
|
|
return NewCCBinary(&test.CCBinary, module, hod, common.MultilibBoth, props...)
|
2015-04-25 02:48:09 +02:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
func CCTestFactory() (blueprint.Module, []interface{}) {
|
2015-04-25 02:48:09 +02:00
|
|
|
module := &CCTest{}
|
2015-12-22 00:25:58 +01:00
|
|
|
module.TestProperties.Gtest = true
|
2015-04-25 02:48:09 +02:00
|
|
|
|
|
|
|
return NewCCTest(module, module, common.HostAndDeviceSupported)
|
2015-03-19 22:05:33 +01:00
|
|
|
}
|
|
|
|
|
2015-05-08 00:44:20 +02:00
|
|
|
type CCBenchmark struct {
|
|
|
|
CCBinary
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CCBenchmark) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
depNames = c.CCBinary.depNames(ctx, depNames)
|
2015-09-12 02:41:44 +02:00
|
|
|
depNames.StaticLibs = append(depNames.StaticLibs, "libbenchmark", "libbase")
|
2015-05-08 00:44:20 +02:00
|
|
|
return depNames
|
|
|
|
}
|
|
|
|
|
2015-12-21 23:55:28 +01:00
|
|
|
func (c *CCBenchmark) InstallInData() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-05-08 00:44:20 +02:00
|
|
|
func (c *CCBenchmark) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
|
|
|
if ctx.Device() {
|
2015-12-21 23:55:28 +01:00
|
|
|
installDir := "nativetest"
|
|
|
|
if flags.Toolchain.Is64Bit() {
|
|
|
|
installDir = "nativetest64"
|
|
|
|
}
|
|
|
|
ctx.InstallFile(common.PathForModuleInstall(ctx, installDir, ctx.ModuleName()), c.out)
|
2015-05-08 00:44:20 +02:00
|
|
|
} else {
|
|
|
|
c.CCBinary.installModule(ctx, flags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCCBenchmark(test *CCBenchmark, module CCModuleType,
|
|
|
|
hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
2015-12-22 00:25:58 +01:00
|
|
|
return NewCCBinary(&test.CCBinary, module, hod, common.MultilibFirst, props...)
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func CCBenchmarkFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCBenchmark{}
|
|
|
|
|
|
|
|
return NewCCBenchmark(module, module, common.HostAndDeviceSupported)
|
|
|
|
}
|
|
|
|
|
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-12-22 00:25:58 +01:00
|
|
|
return NewCCBinary(module, module, common.HostSupported, common.MultilibFirst)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 00:09:47 +01:00
|
|
|
//
|
|
|
|
// Host Tests
|
|
|
|
//
|
|
|
|
|
|
|
|
func CCTestHostFactory() (blueprint.Module, []interface{}) {
|
2015-04-25 02:48:09 +02:00
|
|
|
module := &CCTest{}
|
2015-12-22 00:25:58 +01:00
|
|
|
return NewCCTest(module, module, common.HostSupported)
|
2015-03-27 00:09:47 +01:00
|
|
|
}
|
|
|
|
|
2015-05-08 00:44:20 +02:00
|
|
|
//
|
|
|
|
// Host Benchmarks
|
|
|
|
//
|
|
|
|
|
|
|
|
func CCBenchmarkHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCBenchmark{}
|
2015-12-22 00:25:58 +01:00
|
|
|
return NewCCBinary(&module.CCBinary, module, common.HostSupported, common.MultilibFirst)
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
2015-11-03 01:43:11 +01:00
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
|
|
|
type CCDefaults struct {
|
|
|
|
common.AndroidModuleBase
|
|
|
|
common.DefaultsModule
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*CCDefaults) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func CCDefaultsFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &CCDefaults{}
|
|
|
|
|
|
|
|
propertyStructs := []interface{}{
|
|
|
|
&CCBaseProperties{},
|
|
|
|
&CCLibraryProperties{},
|
|
|
|
&CCBinaryProperties{},
|
2015-12-22 00:25:58 +01:00
|
|
|
&CCTestProperties{},
|
2015-11-03 01:43:11 +01:00
|
|
|
&CCUnusedProperties{},
|
|
|
|
}
|
|
|
|
|
2015-07-09 03:13:11 +02:00
|
|
|
_, propertyStructs = common.InitAndroidArchModule(module, common.HostAndDeviceDefault,
|
|
|
|
common.MultilibDefault, propertyStructs...)
|
2015-11-03 01:43:11 +01:00
|
|
|
|
|
|
|
return common.InitDefaultsModule(module, module, propertyStructs...)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-04-25 02:39:18 +02: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-04-25 02:31:52 +02:00
|
|
|
return newCCBase(&module.CCBase, module, common.DeviceSupported, common.MultilibBoth,
|
2015-03-24 22:15:58 +01:00
|
|
|
&module.LibraryProperties)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *toolchainLibrary) compileModule(ctx common.AndroidModuleContext,
|
2015-09-24 00:26:20 +02:00
|
|
|
flags CCFlags, deps CCPathDeps, objFiles common.Paths) {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
libName := ctx.ModuleName() + staticLibraryExtension
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, libName)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
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).
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func getNdkLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, version string) common.SourcePath {
|
|
|
|
return common.PathForSource(ctx, fmt.Sprintf("prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib",
|
|
|
|
version, toolchain.Name()))
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 03:17:56 +02:00
|
|
|
func ndkPrebuiltModuleToPath(ctx common.AndroidModuleContext, toolchain Toolchain,
|
2015-09-24 00:26:20 +02:00
|
|
|
ext string, version string) common.Path {
|
2015-04-29 03:17:56 +02:00
|
|
|
|
|
|
|
// NDK prebuilts are named like: ndk_NAME.EXT.SDK_VERSION.
|
|
|
|
// We want to translate to just NAME.EXT
|
|
|
|
name := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0]
|
|
|
|
dir := getNdkLibDir(ctx, toolchain, version)
|
2015-09-24 00:26:20 +02:00
|
|
|
return dir.Join(ctx, name+ext)
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ndkPrebuiltObject struct {
|
|
|
|
ccObject
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*ndkPrebuiltObject) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
|
|
|
// NDK objects can't have any dependencies
|
|
|
|
return CCDeps{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NdkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &ndkPrebuiltObject{}
|
|
|
|
return newCCBase(&module.CCBase, module, common.DeviceSupported, common.MultilibBoth)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltObject) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
|
2015-09-24 00:26:20 +02:00
|
|
|
deps CCPathDeps, objFiles common.Paths) {
|
2015-04-29 03:17:56 +02:00
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
|
|
|
|
ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name")
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
c.out = common.OptionalPathForPath(ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, c.Properties.Sdk_version))
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltObject) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
|
|
|
// Objects do not get installed.
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ ccObjectProvider = (*ndkPrebuiltObject)(nil)
|
|
|
|
|
2015-03-19 07:38:50 +01:00
|
|
|
type ndkPrebuiltLibrary struct {
|
|
|
|
CCLibrary
|
|
|
|
}
|
|
|
|
|
2015-04-25 02:39:18 +02:00
|
|
|
func (*ndkPrebuiltLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
2015-03-19 07:38:50 +01:00
|
|
|
// 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,
|
2015-09-24 00:26:20 +02:00
|
|
|
deps CCPathDeps, objFiles common.Paths) {
|
2015-03-19 07:38:50 +01:00
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, c.Properties.Export_include_dirs)
|
|
|
|
c.exportFlags = []string{common.JoinWithPrefix(includeDirs.Strings(), "-isystem ")}
|
2015-03-19 07:38:50 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
c.out = ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(),
|
2015-04-29 03:17:56 +02:00
|
|
|
c.Properties.Sdk_version)
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) {
|
2015-04-29 03:17:56 +02:00
|
|
|
// NDK prebuilt libraries do not get installed.
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl string) common.SourcePath {
|
2015-03-19 07:38:50 +01:00
|
|
|
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-09-24 00:26:20 +02:00
|
|
|
ndkSrcRoot := "prebuilts/ndk/current/sources"
|
|
|
|
return common.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0])
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleErrorf("Unknown NDK STL: %s", stl)
|
2015-09-24 00:26:20 +02:00
|
|
|
return common.PathForSource(ctx, "")
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltStl) compileModule(ctx common.AndroidModuleContext, flags CCFlags,
|
2015-09-24 00:26:20 +02:00
|
|
|
deps CCPathDeps, objFiles common.Paths) {
|
2015-03-19 07:38:50 +01:00
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, c.Properties.Export_include_dirs)
|
2015-04-22 22:07:53 +02:00
|
|
|
c.exportFlags = []string{includeDirsToFlags(includeDirs)}
|
2015-03-19 07:38:50 +01:00
|
|
|
|
|
|
|
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
2015-11-25 02:53:15 +01:00
|
|
|
libExt := flags.Toolchain.ShlibSuffix()
|
2015-03-19 07:38:50 +01:00
|
|
|
if c.LibraryProperties.BuildStatic {
|
|
|
|
libExt = staticLibraryExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
stlName := strings.TrimSuffix(libName, "_shared")
|
|
|
|
stlName = strings.TrimSuffix(stlName, "_static")
|
|
|
|
libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
|
2015-09-24 00:26:20 +02:00
|
|
|
c.out = libDir.Join(ctx, libName+libExt)
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func linkageMutator(mctx common.AndroidBottomUpMutatorContext) {
|
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-04-28 22:20:37 +02:00
|
|
|
modules[0].(ccLinkedInterface).setStatic(true)
|
|
|
|
modules[1].(ccLinkedInterface).setStatic(false)
|
2015-03-26 22:43:45 +01:00
|
|
|
} else if c.buildStatic() {
|
2015-01-31 02:27:36 +01:00
|
|
|
modules = mctx.CreateLocalVariations("static")
|
2015-04-28 22:20:37 +02:00
|
|
|
modules[0].(ccLinkedInterface).setStatic(true)
|
2015-03-26 22:43:45 +01:00
|
|
|
} else if c.buildShared() {
|
2015-01-31 02:27:36 +01:00
|
|
|
modules = mctx.CreateLocalVariations("shared")
|
2015-04-28 22:20:37 +02:00
|
|
|
modules[0].(ccLinkedInterface).setStatic(false)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-28 22:30:13 +02:00
|
|
|
|
|
|
|
// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
|
|
|
|
// modifies the slice contents in place, and returns a subslice of the original slice
|
|
|
|
func lastUniqueElements(list []string) []string {
|
|
|
|
totalSkip := 0
|
|
|
|
for i := len(list) - 1; i >= totalSkip; i-- {
|
|
|
|
skip := 0
|
|
|
|
for j := i - 1; j >= totalSkip; j-- {
|
|
|
|
if list[i] == list[j] {
|
|
|
|
skip++
|
|
|
|
} else {
|
|
|
|
list[j+skip] = list[j]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalSkip += skip
|
|
|
|
}
|
|
|
|
return list[totalSkip:]
|
|
|
|
}
|
2015-10-29 01:23:31 +01:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|