2015-03-19 04:28:46 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
2015-01-31 09:27:36 +08: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 08:50:24 +08:00
|
|
|
"github.com/google/blueprint"
|
2015-10-29 08:23:31 +08:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-24 08:50:24 +08:00
|
|
|
|
2015-06-18 05:20:06 +08:00
|
|
|
"android/soong"
|
2015-01-31 09:27:36 +08:00
|
|
|
"android/soong/common"
|
2015-03-19 04:28:46 +08:00
|
|
|
"android/soong/genrule"
|
2015-01-31 09:27:36 +08:00
|
|
|
)
|
|
|
|
|
2015-06-18 05:20:06 +08:00
|
|
|
func init() {
|
2016-01-05 06:34:37 +08:00
|
|
|
soong.RegisterModuleType("cc_library_static", libraryStaticFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_shared", librarySharedFactory)
|
|
|
|
soong.RegisterModuleType("cc_library", libraryFactory)
|
|
|
|
soong.RegisterModuleType("cc_object", objectFactory)
|
|
|
|
soong.RegisterModuleType("cc_binary", binaryFactory)
|
|
|
|
soong.RegisterModuleType("cc_test", testFactory)
|
|
|
|
soong.RegisterModuleType("cc_benchmark", benchmarkFactory)
|
|
|
|
soong.RegisterModuleType("cc_defaults", defaultsFactory)
|
|
|
|
|
|
|
|
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", libraryHostStaticFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
|
|
|
|
soong.RegisterModuleType("cc_binary_host", binaryHostFactory)
|
|
|
|
soong.RegisterModuleType("cc_test_host", testHostFactory)
|
|
|
|
soong.RegisterModuleType("cc_benchmark_host", benchmarkHostFactory)
|
2015-06-18 05:20:06 +08:00
|
|
|
|
|
|
|
// 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-30 06:25:03 +08:00
|
|
|
common.RegisterBottomUpMutator("link", linkageMutator)
|
|
|
|
common.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
|
|
|
|
common.RegisterBottomUpMutator("deps", depsMutator)
|
2016-01-07 06:41:07 +08:00
|
|
|
|
|
|
|
common.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
|
|
|
|
common.RegisterBottomUpMutator("asan", sanitizerMutator(asan))
|
|
|
|
|
|
|
|
common.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
|
|
|
|
common.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan))
|
2015-06-18 05:20:06 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
var (
|
2015-04-08 08:11:30 +08:00
|
|
|
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", common.Config.PrebuiltOS)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
LibcRoot = pctx.SourcePathVariable("LibcRoot", "bionic/libc")
|
2015-01-31 09:27:36 +08: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",
|
|
|
|
|
|
|
|
// COMMON_RELEASE_CFLAGS
|
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceGlobalCflags = []string{
|
2015-11-25 09:53:15 +08:00
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// TARGET_ERROR_FLAGS
|
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
2016-03-02 07:16:50 +08:00
|
|
|
"-Werror=date-time",
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
2015-09-12 08:41:10 +08:00
|
|
|
}
|
|
|
|
|
2016-03-04 09:21:04 +08:00
|
|
|
noOverrideGlobalCflags = []string{
|
|
|
|
"-Werror=int-to-pointer-cast",
|
|
|
|
"-Werror=pointer-to-int-cast",
|
|
|
|
}
|
|
|
|
|
2015-09-12 08:41:10 +08:00
|
|
|
illegalFlags = []string{
|
|
|
|
"-w",
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-03-30 08:31:57 +08:00
|
|
|
if common.CurrentHostType() == common.Linux {
|
|
|
|
commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " "))
|
2016-03-04 09:21:04 +08:00
|
|
|
pctx.StaticVariable("noOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("commonClangGlobalCflags",
|
2016-01-13 08:22:40 +08:00
|
|
|
strings.Join(append(clangFilterUnknownCflags(commonGlobalCflags), "${clangExtraCflags}"), " "))
|
2015-01-31 09:27:36 +08:00
|
|
|
pctx.StaticVariable("deviceClangGlobalCflags",
|
2016-01-13 08:22:40 +08:00
|
|
|
strings.Join(append(clangFilterUnknownCflags(deviceGlobalCflags), "${clangExtraTargetCflags}"), " "))
|
2015-01-31 09:27:36 +08:00
|
|
|
pctx.StaticVariable("hostClangGlobalCflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
|
2016-03-04 09:21:04 +08:00
|
|
|
pctx.StaticVariable("noOverrideClangGlobalCflags",
|
|
|
|
strings.Join(append(clangFilterUnknownCflags(noOverrideGlobalCflags), "${clangExtraNoOverrideCflags}"), " "))
|
|
|
|
|
2015-03-12 03:03:03 +08:00
|
|
|
pctx.StaticVariable("commonClangGlobalCppflags",
|
2016-01-13 08:22:40 +08:00
|
|
|
strings.Join(append(clangFilterUnknownCflags(commonGlobalCppflags), "${clangExtraCppflags}"), " "))
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
// Everything in this list is a crime against abstraction and dependency tracking.
|
|
|
|
// Do not add anything to this list.
|
2015-12-19 07:11:17 +08:00
|
|
|
pctx.PrefixedPathsForOptionalSourceVariable("commonGlobalIncludes", "-isystem ",
|
2015-09-24 06:26:20 +08:00
|
|
|
[]string{
|
|
|
|
"system/core/include",
|
2016-03-02 07:27:03 +08:00
|
|
|
"system/media/audio/include",
|
2015-09-24 06:26:20 +08:00
|
|
|
"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",
|
|
|
|
})
|
2016-01-08 09:42:34 +08:00
|
|
|
// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
|
|
|
|
// with this, since there is no associated library.
|
|
|
|
pctx.PrefixedPathsForOptionalSourceVariable("commonNativehelperInclude", "-I",
|
|
|
|
[]string{"libnativehelper/include/nativehelper"})
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-03-17 02:37:17 +08:00
|
|
|
pctx.SourcePathVariable("clangDefaultBase", "prebuilts/clang/host")
|
|
|
|
pctx.VariableFunc("clangBase", func(config interface{}) (string, error) {
|
|
|
|
if override := config.(common.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
|
|
|
return override, nil
|
|
|
|
}
|
|
|
|
return "${clangDefaultBase}", nil
|
|
|
|
})
|
|
|
|
pctx.VariableFunc("clangVersion", func(config interface{}) (string, error) {
|
|
|
|
if override := config.(common.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
|
|
|
return override, nil
|
|
|
|
}
|
2016-04-27 05:34:07 +08:00
|
|
|
return "clang-2812033", nil
|
2016-03-17 02:37:17 +08:00
|
|
|
})
|
2016-01-07 06:41:07 +08:00
|
|
|
pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}")
|
|
|
|
pctx.StaticVariable("clangBin", "${clangPath}/bin")
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type Deps struct {
|
|
|
|
SharedLibs, LateSharedLibs []string
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
2015-09-24 06:26:20 +08:00
|
|
|
|
2016-04-12 05:37:39 +08:00
|
|
|
ObjFiles []string
|
2015-03-18 06:06:21 +08:00
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
GeneratedSources []string
|
|
|
|
GeneratedHeaders []string
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
Cflags, ReexportedCflags []string
|
2015-03-25 05:15:58 +08:00
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
CrtBegin, CrtEnd string
|
2015-03-18 06:06:21 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type PathDeps struct {
|
|
|
|
SharedLibs, LateSharedLibs common.Paths
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs common.Paths
|
2015-09-24 06:26:20 +08:00
|
|
|
|
|
|
|
ObjFiles common.Paths
|
|
|
|
WholeStaticLibObjFiles common.Paths
|
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
GeneratedSources common.Paths
|
|
|
|
GeneratedHeaders common.Paths
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
Cflags, ReexportedCflags []string
|
|
|
|
|
|
|
|
CrtBegin, CrtEnd common.OptionalPath
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type Flags struct {
|
2015-04-23 04:07:53 +08: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
|
2016-01-07 06:41:07 +08:00
|
|
|
libFlags []string // Flags to add libraries early to the link order
|
2015-04-23 04:07:53 +08:00
|
|
|
|
|
|
|
Nocrt bool
|
|
|
|
Toolchain Toolchain
|
|
|
|
Clang bool
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
RequiredInstructionSet string
|
2016-01-07 06:41:07 +08:00
|
|
|
DynamicLinker string
|
|
|
|
|
|
|
|
CFlagsDeps common.Paths // Files depended on by compiler flags
|
2015-03-18 06:06:21 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type BaseCompilerProperties struct {
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
|
2015-07-01 09:15:24 +08: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-18 06:06:21 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of module-specific flags that will be used for C and C++ compiles.
|
|
|
|
Cflags []string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of module-specific flags that will be used for C++ compiles
|
|
|
|
Cppflags []string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of module-specific flags that will be used for C compiles
|
|
|
|
Conlyflags []string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of module-specific flags that will be used for .S compiles
|
|
|
|
Asflags []string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08: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"`
|
|
|
|
|
|
|
|
// list of module-specific flags that will be used for .S compiles when
|
|
|
|
// compiling with clang
|
|
|
|
Clang_asflags []string `android:"arch_variant"`
|
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of module-specific flags that will be used for .y and .yy compiles
|
|
|
|
Yaccflags []string
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// the instruction set architecture to use to compile the C/C++
|
|
|
|
// module.
|
|
|
|
Instruction_set string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08: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 08:31:52 +08:00
|
|
|
|
2015-09-15 03:30:50 +08: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-12 04:39:40 +08: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 08:31:52 +08:00
|
|
|
|
2015-09-15 03:30:50 +08: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"`
|
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
// list of generated sources to compile. These are the names of gensrcs or
|
|
|
|
// genrule modules.
|
|
|
|
Generated_sources []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of generated headers to add to the include path. These are the names
|
|
|
|
// of genrule modules.
|
|
|
|
Generated_headers []string `android:"arch_variant"`
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// pass -frtti instead of -fno-rtti
|
|
|
|
Rtti *bool
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
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 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type BaseLinkerProperties struct {
|
2015-05-12 04:39:40 +08: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 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of modules that should be statically linked into this module.
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// list of modules that should be dynamically linked into this module.
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// list of module-specific flags that will be used for all link steps
|
|
|
|
Ldflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// don't insert default compiler flags into asflags, cflags,
|
|
|
|
// cppflags, conlyflags, ldflags, or include_dirs
|
|
|
|
No_default_compiler_flags *bool
|
|
|
|
|
|
|
|
// 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-05-12 04:39:40 +08: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 08:23:31 +08:00
|
|
|
Allow_undefined_symbols *bool
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// don't link in libgcc.a
|
|
|
|
No_libgcc *bool
|
|
|
|
|
|
|
|
// -l arguments to pass to linker for host-provided shared libraries
|
|
|
|
Host_ldlibs []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type LibraryCompilerProperties struct {
|
|
|
|
Static struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2016-04-06 07:42:05 +08:00
|
|
|
type FlagExporterProperties struct {
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type LibraryLinkerProperties struct {
|
|
|
|
Static struct {
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
|
|
|
// local file name to pass to the linker as --version_script
|
|
|
|
Version_script *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -unexported_symbols_list
|
|
|
|
Unexported_symbols_list *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -force_symbols_not_weak_list
|
|
|
|
Force_symbols_not_weak_list *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -force_symbols_weak_list
|
|
|
|
Force_symbols_weak_list *string `android:"arch_variant"`
|
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// don't link in crt_begin and crt_end. This flag should only be necessary for
|
|
|
|
// compiling crt or libc.
|
2015-10-29 08:23:31 +08:00
|
|
|
Nocrt *bool `android:"arch_variant"`
|
2016-01-07 06:41:07 +08:00
|
|
|
|
|
|
|
VariantName string `blueprint:"mutated"`
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type BinaryLinkerProperties struct {
|
|
|
|
// compile executable with -static
|
|
|
|
Static_executable *bool
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// set the name of the output
|
|
|
|
Stem string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// append to the name of the output
|
|
|
|
Suffix string `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// if set, add an extra objcopy --prefix-symbols= step
|
|
|
|
Prefix_symbols string
|
|
|
|
}
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type TestLinkerProperties struct {
|
|
|
|
// if set, build against the gtest library. Defaults to true.
|
|
|
|
Gtest bool
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// 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-05-12 04:39:40 +08:00
|
|
|
|
2016-04-12 05:37:39 +08:00
|
|
|
type ObjectLinkerProperties struct {
|
|
|
|
// names of other cc_object modules to link into this module using partial linking
|
|
|
|
Objs []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// Properties used to compile all C or C++ modules
|
|
|
|
type BaseProperties struct {
|
|
|
|
// compile module with clang instead of gcc
|
|
|
|
Clang *bool `android:"arch_variant"`
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2015-05-12 04:39:40 +08:00
|
|
|
// Minimum sdk version supported when compiling against the ndk
|
|
|
|
Sdk_version string
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// don't insert default compiler flags into asflags, cflags,
|
|
|
|
// cppflags, conlyflags, ldflags, or include_dirs
|
|
|
|
No_default_compiler_flags *bool
|
2016-04-12 06:06:20 +08:00
|
|
|
|
|
|
|
AndroidMkSharedLibs []string `blueprint:"mutated"`
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type InstallerProperties struct {
|
2015-05-12 04:39:40 +08:00
|
|
|
// install to a subdirectory of the default install path for the module
|
|
|
|
Relative_install_path string
|
|
|
|
}
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
type StripProperties struct {
|
|
|
|
Strip struct {
|
|
|
|
None bool
|
|
|
|
Keep_symbols bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type UnusedProperties struct {
|
2016-04-16 07:27:17 +08:00
|
|
|
Native_coverage *bool
|
|
|
|
Required []string
|
|
|
|
Tags []string
|
2015-11-03 08:43:11 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type ModuleContextIntf interface {
|
|
|
|
module() *Module
|
|
|
|
static() bool
|
|
|
|
staticBinary() bool
|
|
|
|
clang() bool
|
|
|
|
toolchain() Toolchain
|
|
|
|
noDefaultCompilerFlags() bool
|
|
|
|
sdk() bool
|
|
|
|
sdkVersion() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ModuleContext interface {
|
|
|
|
common.AndroidModuleContext
|
|
|
|
ModuleContextIntf
|
|
|
|
}
|
|
|
|
|
|
|
|
type BaseModuleContext interface {
|
|
|
|
common.AndroidBaseContext
|
|
|
|
ModuleContextIntf
|
|
|
|
}
|
|
|
|
|
|
|
|
type Customizer interface {
|
|
|
|
CustomizeProperties(BaseModuleContext)
|
|
|
|
Properties() []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type feature interface {
|
|
|
|
begin(ctx BaseModuleContext)
|
|
|
|
deps(ctx BaseModuleContext, deps Deps) Deps
|
|
|
|
flags(ctx ModuleContext, flags Flags) Flags
|
|
|
|
props() []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type compiler interface {
|
|
|
|
feature
|
2016-04-21 05:21:14 +08:00
|
|
|
compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type linker interface {
|
|
|
|
feature
|
|
|
|
link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles common.Paths) common.Path
|
2016-04-12 06:06:20 +08:00
|
|
|
installable() bool
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type installer interface {
|
|
|
|
props() []interface{}
|
|
|
|
install(ctx ModuleContext, path common.Path)
|
|
|
|
inData() bool
|
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
library bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
sharedDepTag = dependencyTag{name: "shared", library: true}
|
|
|
|
lateSharedDepTag = dependencyTag{name: "late shared", library: true}
|
|
|
|
staticDepTag = dependencyTag{name: "static", library: true}
|
|
|
|
lateStaticDepTag = dependencyTag{name: "late static", library: true}
|
|
|
|
wholeStaticDepTag = dependencyTag{name: "whole static", library: true}
|
2016-04-21 05:21:14 +08:00
|
|
|
genSourceDepTag = dependencyTag{name: "gen source"}
|
|
|
|
genHeaderDepTag = dependencyTag{name: "gen header"}
|
2016-04-12 06:06:20 +08:00
|
|
|
objDepTag = dependencyTag{name: "obj"}
|
|
|
|
crtBeginDepTag = dependencyTag{name: "crtbegin"}
|
|
|
|
crtEndDepTag = dependencyTag{name: "crtend"}
|
|
|
|
reuseObjTag = dependencyTag{name: "reuse objects"}
|
|
|
|
)
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// Module contains the properties and members used by all C/C++ module types, and implements
|
|
|
|
// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
|
|
|
|
// to construct the output file. Behavior can be customized with a Customizer interface
|
|
|
|
type Module struct {
|
2015-05-12 04:39:40 +08:00
|
|
|
common.AndroidModuleBase
|
2015-11-03 08:43:11 +08:00
|
|
|
common.DefaultableModule
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
Properties BaseProperties
|
|
|
|
unused UnusedProperties
|
|
|
|
|
|
|
|
// initialize before calling Init
|
|
|
|
hod common.HostOrDeviceSupported
|
|
|
|
multilib common.Multilib
|
2015-04-25 08:31:52 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// delegates, initialize before calling Init
|
|
|
|
customizer Customizer
|
|
|
|
features []feature
|
|
|
|
compiler compiler
|
|
|
|
linker linker
|
|
|
|
installer installer
|
2016-04-05 06:07:06 +08:00
|
|
|
stl *stl
|
2016-01-07 06:41:07 +08:00
|
|
|
sanitize *sanitize
|
|
|
|
|
|
|
|
androidMkSharedLibDeps []string
|
2015-03-18 06:06:21 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
outputFile common.OptionalPath
|
2015-04-29 04:30:13 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
cachedToolchain Toolchain
|
2015-03-18 06:06:21 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *Module) Init() (blueprint.Module, []interface{}) {
|
|
|
|
props := []interface{}{&c.Properties, &c.unused}
|
|
|
|
if c.customizer != nil {
|
|
|
|
props = append(props, c.customizer.Properties()...)
|
|
|
|
}
|
|
|
|
if c.compiler != nil {
|
|
|
|
props = append(props, c.compiler.props()...)
|
|
|
|
}
|
|
|
|
if c.linker != nil {
|
|
|
|
props = append(props, c.linker.props()...)
|
|
|
|
}
|
|
|
|
if c.installer != nil {
|
|
|
|
props = append(props, c.installer.props()...)
|
|
|
|
}
|
2016-04-05 06:07:06 +08:00
|
|
|
if c.stl != nil {
|
|
|
|
props = append(props, c.stl.props()...)
|
|
|
|
}
|
2016-01-07 06:41:07 +08:00
|
|
|
if c.sanitize != nil {
|
|
|
|
props = append(props, c.sanitize.props()...)
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
for _, feature := range c.features {
|
|
|
|
props = append(props, feature.props()...)
|
|
|
|
}
|
2015-03-18 06:06:21 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
_, props = common.InitAndroidArchModule(c, c.hod, c.multilib, props...)
|
2015-03-18 06:06:21 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return common.InitDefaultableModule(c, c, props...)
|
|
|
|
}
|
2015-03-18 06:06:21 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type baseModuleContext struct {
|
|
|
|
common.AndroidBaseContext
|
|
|
|
moduleContextImpl
|
|
|
|
}
|
2015-11-03 08:43:11 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type moduleContext struct {
|
|
|
|
common.AndroidModuleContext
|
|
|
|
moduleContextImpl
|
2015-03-18 06:06:21 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type moduleContextImpl struct {
|
|
|
|
mod *Module
|
|
|
|
ctx BaseModuleContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) module() *Module {
|
|
|
|
return ctx.mod
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) clang() bool {
|
|
|
|
return ctx.mod.clang(ctx.ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) toolchain() Toolchain {
|
|
|
|
return ctx.mod.toolchain(ctx.ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) static() bool {
|
|
|
|
if ctx.mod.linker == nil {
|
|
|
|
panic(fmt.Errorf("static called on module %q with no linker", ctx.ctx.ModuleName()))
|
|
|
|
}
|
|
|
|
if linker, ok := ctx.mod.linker.(baseLinkerInterface); ok {
|
|
|
|
return linker.static()
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("static called on module %q that doesn't use base linker", ctx.ctx.ModuleName()))
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (ctx *moduleContextImpl) staticBinary() bool {
|
|
|
|
if ctx.mod.linker == nil {
|
|
|
|
panic(fmt.Errorf("staticBinary called on module %q with no linker", ctx.ctx.ModuleName()))
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
if linker, ok := ctx.mod.linker.(baseLinkerInterface); ok {
|
|
|
|
return linker.staticBinary()
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("staticBinary called on module %q that doesn't use base linker", ctx.ctx.ModuleName()))
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
|
|
|
|
return Bool(ctx.mod.Properties.No_default_compiler_flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) sdk() bool {
|
|
|
|
return ctx.mod.Properties.Sdk_version != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) sdkVersion() string {
|
|
|
|
return ctx.mod.Properties.Sdk_version
|
|
|
|
}
|
|
|
|
|
|
|
|
func newBaseModule(hod common.HostOrDeviceSupported, multilib common.Multilib) *Module {
|
|
|
|
return &Module{
|
|
|
|
hod: hod,
|
|
|
|
multilib: multilib,
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func newModule(hod common.HostOrDeviceSupported, multilib common.Multilib) *Module {
|
|
|
|
module := newBaseModule(hod, multilib)
|
2016-04-05 06:07:06 +08:00
|
|
|
module.stl = &stl{}
|
2016-01-07 06:41:07 +08:00
|
|
|
module.sanitize = &sanitize{}
|
2016-01-05 06:34:37 +08:00
|
|
|
return module
|
|
|
|
}
|
2015-03-19 08:17:35 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *Module) GenerateAndroidBuildActions(actx common.AndroidModuleContext) {
|
|
|
|
ctx := &moduleContext{
|
|
|
|
AndroidModuleContext: actx,
|
|
|
|
moduleContextImpl: moduleContextImpl{
|
|
|
|
mod: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.ctx = ctx
|
|
|
|
|
|
|
|
flags := Flags{
|
|
|
|
Toolchain: c.toolchain(ctx),
|
|
|
|
Clang: c.clang(ctx),
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
if c.compiler != nil {
|
|
|
|
flags = c.compiler.flags(ctx, flags)
|
|
|
|
}
|
|
|
|
if c.linker != nil {
|
|
|
|
flags = c.linker.flags(ctx, flags)
|
|
|
|
}
|
2016-04-05 06:07:06 +08:00
|
|
|
if c.stl != nil {
|
|
|
|
flags = c.stl.flags(ctx, flags)
|
|
|
|
}
|
2016-01-07 06:41:07 +08:00
|
|
|
if c.sanitize != nil {
|
|
|
|
flags = c.sanitize.flags(ctx, flags)
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
for _, feature := range c.features {
|
|
|
|
flags = feature.flags(ctx, flags)
|
|
|
|
}
|
2015-03-19 04:28:46 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.CFlags, _ = filterList(flags.CFlags, illegalFlags)
|
|
|
|
flags.CppFlags, _ = filterList(flags.CppFlags, illegalFlags)
|
|
|
|
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, illegalFlags)
|
|
|
|
|
|
|
|
// Optimization to reduce size of build.ninja
|
|
|
|
// Replace the long list of flags for each file with a module-local variable
|
|
|
|
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-03-19 04:28:46 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
deps := c.depsToPaths(ctx)
|
2015-01-31 09:27:36 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-19 05:01:18 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, deps.Cflags...)
|
|
|
|
|
|
|
|
var objFiles common.Paths
|
|
|
|
if c.compiler != nil {
|
2016-04-21 05:21:14 +08:00
|
|
|
objFiles = c.compiler.compile(ctx, flags, deps)
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if c.linker != nil {
|
|
|
|
outputFile := c.linker.link(ctx, flags, deps, objFiles)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.outputFile = common.OptionalPathForPath(outputFile)
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
if c.installer != nil && c.linker.installable() {
|
2016-01-05 06:34:37 +08:00
|
|
|
c.installer.install(ctx, outputFile)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *Module) toolchain(ctx BaseModuleContext) Toolchain {
|
|
|
|
if c.cachedToolchain == nil {
|
|
|
|
arch := ctx.Arch()
|
|
|
|
hod := ctx.HostOrDevice()
|
|
|
|
ht := ctx.HostType()
|
|
|
|
factory := toolchainFactories[hod][ht][arch.ArchType]
|
|
|
|
if factory == nil {
|
|
|
|
ctx.ModuleErrorf("Toolchain not found for %s %s arch %q", hod.String(), ht.String(), arch.String())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
c.cachedToolchain = factory(arch)
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
return c.cachedToolchain
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *Module) begin(ctx BaseModuleContext) {
|
|
|
|
if c.compiler != nil {
|
|
|
|
c.compiler.begin(ctx)
|
|
|
|
}
|
|
|
|
if c.linker != nil {
|
|
|
|
c.linker.begin(ctx)
|
|
|
|
}
|
2016-04-05 06:07:06 +08:00
|
|
|
if c.stl != nil {
|
|
|
|
c.stl.begin(ctx)
|
|
|
|
}
|
2016-01-07 06:41:07 +08:00
|
|
|
if c.sanitize != nil {
|
|
|
|
c.sanitize.begin(ctx)
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
for _, feature := range c.features {
|
|
|
|
feature.begin(ctx)
|
|
|
|
}
|
2015-04-25 08:31:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
func (c *Module) deps(ctx BaseModuleContext) Deps {
|
|
|
|
deps := Deps{}
|
|
|
|
|
|
|
|
if c.compiler != nil {
|
|
|
|
deps = c.compiler.deps(ctx, deps)
|
|
|
|
}
|
|
|
|
if c.linker != nil {
|
|
|
|
deps = c.linker.deps(ctx, deps)
|
|
|
|
}
|
2016-04-05 06:07:06 +08:00
|
|
|
if c.stl != nil {
|
|
|
|
deps = c.stl.deps(ctx, deps)
|
|
|
|
}
|
2016-01-07 06:41:07 +08:00
|
|
|
if c.sanitize != nil {
|
|
|
|
deps = c.sanitize.deps(ctx, deps)
|
|
|
|
}
|
2016-04-12 06:06:20 +08:00
|
|
|
for _, feature := range c.features {
|
|
|
|
deps = feature.deps(ctx, deps)
|
|
|
|
}
|
|
|
|
|
|
|
|
deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
|
|
|
|
deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
|
|
|
|
deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
|
|
|
|
deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
|
|
|
|
deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *Module) depsMutator(actx common.AndroidBottomUpMutatorContext) {
|
|
|
|
ctx := &baseModuleContext{
|
|
|
|
AndroidBaseContext: actx,
|
|
|
|
moduleContextImpl: moduleContextImpl{
|
|
|
|
mod: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.ctx = ctx
|
2015-03-25 05:15:58 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if c.customizer != nil {
|
|
|
|
c.customizer.CustomizeProperties(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.begin(ctx)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
deps := c.deps(ctx)
|
2015-04-29 04:30:13 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
c.Properties.AndroidMkSharedLibs = deps.SharedLibs
|
|
|
|
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
|
|
|
|
deps.WholeStaticLibs...)
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, staticDepTag,
|
|
|
|
deps.StaticLibs...)
|
2015-03-25 05:15:58 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
|
|
|
|
deps.LateStaticLibs...)
|
2015-03-25 05:15:58 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, sharedDepTag,
|
|
|
|
deps.SharedLibs...)
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
|
|
|
|
deps.LateSharedLibs...)
|
2016-04-12 05:37:39 +08:00
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
actx.AddDependency(ctx.module(), genSourceDepTag, deps.GeneratedSources...)
|
|
|
|
actx.AddDependency(ctx.module(), genHeaderDepTag, deps.GeneratedHeaders...)
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
actx.AddDependency(ctx.module(), objDepTag, deps.ObjFiles...)
|
|
|
|
|
|
|
|
if deps.CrtBegin != "" {
|
|
|
|
actx.AddDependency(ctx.module(), crtBeginDepTag, deps.CrtBegin)
|
2015-03-25 05:15:58 +08:00
|
|
|
}
|
2016-04-12 06:06:20 +08:00
|
|
|
if deps.CrtEnd != "" {
|
|
|
|
actx.AddDependency(ctx.module(), crtEndDepTag, deps.CrtEnd)
|
2015-03-25 05:15:58 +08:00
|
|
|
}
|
2015-10-30 06:25:03 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-10-30 06:25:03 +08:00
|
|
|
func depsMutator(ctx common.AndroidBottomUpMutatorContext) {
|
2016-01-05 06:34:37 +08:00
|
|
|
if c, ok := ctx.Module().(*Module); ok {
|
2015-10-30 06:25:03 +08:00
|
|
|
c.depsMutator(ctx)
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *Module) clang(ctx BaseModuleContext) bool {
|
|
|
|
clang := Bool(c.Properties.Clang)
|
|
|
|
|
|
|
|
if c.Properties.Clang == nil {
|
|
|
|
if ctx.Host() {
|
|
|
|
clang = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
|
|
|
|
clang = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.toolchain(ctx).ClangSupported() {
|
|
|
|
clang = false
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang
|
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
// Convert dependencies to paths. Returns a PathDeps containing paths
|
|
|
|
func (c *Module) depsToPaths(ctx common.AndroidModuleContext) PathDeps {
|
|
|
|
var depPaths PathDeps
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
|
|
|
name := ctx.OtherModuleName(m)
|
|
|
|
tag := ctx.OtherModuleDependencyTag(m)
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
a, _ := m.(common.AndroidModule)
|
|
|
|
if a == nil {
|
|
|
|
ctx.ModuleErrorf("module %q not an android module", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
c, _ := m.(*Module)
|
|
|
|
if c == nil {
|
2016-04-21 05:21:14 +08:00
|
|
|
switch tag {
|
|
|
|
case common.DefaultsDepTag:
|
|
|
|
case genSourceDepTag:
|
|
|
|
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
|
|
|
|
depPaths.GeneratedSources = append(depPaths.GeneratedSources,
|
|
|
|
genRule.GeneratedSourceFiles()...)
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
|
|
|
|
}
|
|
|
|
case genHeaderDepTag:
|
|
|
|
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
|
|
|
|
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
|
|
|
|
genRule.GeneratedSourceFiles()...)
|
|
|
|
depPaths.Cflags = append(depPaths.Cflags,
|
|
|
|
includeDirsToFlags(common.Paths{genRule.GeneratedHeaderDir()}))
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q is not a genrule", name)
|
|
|
|
}
|
|
|
|
default:
|
2016-04-12 06:06:20 +08:00
|
|
|
ctx.ModuleErrorf("depends on non-cc module %q", name)
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2016-04-12 06:06:20 +08:00
|
|
|
return
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
if !a.Enabled() {
|
|
|
|
ctx.ModuleErrorf("depends on disabled module %q", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
if a.HostOrDevice() != ctx.HostOrDevice() {
|
|
|
|
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), name)
|
|
|
|
return
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2015-04-23 04:07:53 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
if !c.outputFile.Valid() {
|
|
|
|
ctx.ModuleErrorf("module %q missing output file", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
if tag == reuseObjTag {
|
|
|
|
depPaths.ObjFiles = append(depPaths.ObjFiles,
|
|
|
|
c.compiler.(*libraryCompiler).reuseObjFiles...)
|
|
|
|
return
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
var cflags []string
|
|
|
|
if t, _ := tag.(dependencyTag); t.library {
|
|
|
|
if i, ok := c.linker.(exportedFlagsProducer); ok {
|
|
|
|
cflags = i.exportedFlags()
|
|
|
|
depPaths.Cflags = append(depPaths.Cflags, cflags...)
|
|
|
|
}
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
var depPtr *common.Paths
|
|
|
|
|
|
|
|
switch tag {
|
|
|
|
case sharedDepTag:
|
|
|
|
depPtr = &depPaths.SharedLibs
|
|
|
|
case lateSharedDepTag:
|
|
|
|
depPtr = &depPaths.LateSharedLibs
|
|
|
|
case staticDepTag:
|
|
|
|
depPtr = &depPaths.StaticLibs
|
|
|
|
case lateStaticDepTag:
|
|
|
|
depPtr = &depPaths.LateStaticLibs
|
|
|
|
case wholeStaticDepTag:
|
|
|
|
depPtr = &depPaths.WholeStaticLibs
|
|
|
|
depPaths.ReexportedCflags = append(depPaths.ReexportedCflags, cflags...)
|
|
|
|
staticLib, _ := c.linker.(*libraryLinker)
|
|
|
|
if staticLib == nil || !staticLib.static() {
|
|
|
|
ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m))
|
|
|
|
return
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
|
|
|
|
postfix := " (required by " + ctx.OtherModuleName(m) + ")"
|
|
|
|
for i := range missingDeps {
|
|
|
|
missingDeps[i] += postfix
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2016-04-12 06:06:20 +08:00
|
|
|
ctx.AddMissingDependencies(missingDeps)
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2016-04-12 06:06:20 +08:00
|
|
|
depPaths.WholeStaticLibObjFiles =
|
|
|
|
append(depPaths.WholeStaticLibObjFiles, staticLib.objFiles...)
|
|
|
|
case objDepTag:
|
|
|
|
depPtr = &depPaths.ObjFiles
|
|
|
|
case crtBeginDepTag:
|
|
|
|
depPaths.CrtBegin = c.outputFile
|
|
|
|
case crtEndDepTag:
|
|
|
|
depPaths.CrtEnd = c.outputFile
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unknown dependency tag: %s", ctx.OtherModuleDependencyTag(m)))
|
|
|
|
}
|
|
|
|
|
|
|
|
if depPtr != nil {
|
|
|
|
*depPtr = append(*depPtr, c.outputFile.Path())
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return depPaths
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) InstallInData() bool {
|
|
|
|
if c.installer == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return c.installer.inData()
|
|
|
|
}
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
type appendVariantName interface {
|
|
|
|
appendVariantName(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) appendVariantName(name string) {
|
|
|
|
if c.linker == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if l, ok := c.linker.(appendVariantName); ok {
|
|
|
|
l.appendVariantName(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// Compiler
|
|
|
|
|
|
|
|
type baseCompiler struct {
|
|
|
|
Properties BaseCompilerProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ compiler = (*baseCompiler)(nil)
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) props() []interface{} {
|
|
|
|
return []interface{}{&compiler.Properties}
|
|
|
|
}
|
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
func (compiler *baseCompiler) begin(ctx BaseModuleContext) {}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
|
|
|
|
deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
// Create a Flags struct that collects the compile flags from global values,
|
|
|
|
// per-target values, module type values, and per-module Blueprints properties
|
|
|
|
func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
toolchain := ctx.toolchain()
|
|
|
|
|
|
|
|
flags.CFlags = append(flags.CFlags, compiler.Properties.Cflags...)
|
|
|
|
flags.CppFlags = append(flags.CppFlags, compiler.Properties.Cppflags...)
|
|
|
|
flags.ConlyFlags = append(flags.ConlyFlags, compiler.Properties.Conlyflags...)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, compiler.Properties.Asflags...)
|
|
|
|
flags.YaccFlags = append(flags.YaccFlags, compiler.Properties.Yaccflags...)
|
|
|
|
|
2015-04-23 04:07:53 +08:00
|
|
|
// Include dir cflags
|
2016-01-05 06:34:37 +08:00
|
|
|
rootIncludeDirs := common.PathsForSource(ctx, compiler.Properties.Include_dirs)
|
|
|
|
localIncludeDirs := common.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
|
2015-04-23 04:07:53 +08:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-09-24 06:26:32 +08:00
|
|
|
includeDirsToFlags(localIncludeDirs),
|
|
|
|
includeDirsToFlags(rootIncludeDirs))
|
2015-04-23 04:07:53 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
rootIncludeFiles := common.PathsForSource(ctx, compiler.Properties.Include_files)
|
|
|
|
localIncludeFiles := common.PathsForModuleSrc(ctx, compiler.Properties.Local_include_files)
|
2015-09-15 03:30:50 +08:00
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
includeFilesToFlags(rootIncludeFiles),
|
|
|
|
includeFilesToFlags(localIncludeFiles))
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if !ctx.noDefaultCompilerFlags() {
|
|
|
|
if !ctx.sdk() || ctx.Host() {
|
2015-04-23 04:07:53 +08:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
"${commonGlobalIncludes}",
|
|
|
|
toolchain.IncludeFlags(),
|
2016-01-08 09:42:34 +08:00
|
|
|
"${commonNativehelperInclude}")
|
2015-04-23 04:07:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, []string{
|
2015-09-24 06:26:20 +08:00
|
|
|
"-I" + common.PathForModuleSrc(ctx).String(),
|
|
|
|
"-I" + common.PathForModuleOut(ctx).String(),
|
|
|
|
"-I" + common.PathForModuleGen(ctx).String(),
|
2015-04-23 04:07:53 +08:00
|
|
|
}...)
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
instructionSet := compiler.Properties.Instruction_set
|
|
|
|
if flags.RequiredInstructionSet != "" {
|
|
|
|
instructionSet = flags.RequiredInstructionSet
|
2015-11-25 09:53:15 +08:00
|
|
|
}
|
2015-11-04 06:27:00 +08:00
|
|
|
instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet)
|
|
|
|
if flags.Clang {
|
|
|
|
instructionSetFlags, err = toolchain.ClangInstructionSetFlags(instructionSet)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: debug
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, compiler.Properties.Release.Cflags...)
|
2015-11-04 06:27:00 +08:00
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CFlags = clangFilterUnknownCflags(flags.CFlags)
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, compiler.Properties.Clang_cflags...)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, compiler.Properties.Clang_asflags...)
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags)
|
|
|
|
flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags)
|
|
|
|
flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
target := "-target " + toolchain.ClangTriple()
|
|
|
|
gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
|
|
|
|
|
2015-03-24 08:50:24 +08: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 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if !ctx.noDefaultCompilerFlags() {
|
2015-04-22 08:38:44 +08:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
|
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
if flags.Clang {
|
2016-01-13 14:25:34 +08:00
|
|
|
flags.AsFlags = append(flags.AsFlags, toolchain.ClangAsflags())
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}")
|
2015-04-22 08:38:44 +08:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-01-31 09:27:36 +08:00
|
|
|
toolchain.ClangCflags(),
|
|
|
|
"${commonClangGlobalCflags}",
|
2015-05-08 05:11:29 +08:00
|
|
|
fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice()))
|
2016-01-13 08:22:40 +08:00
|
|
|
|
|
|
|
flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
|
2015-04-22 08:38:44 +08:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-01-31 09:27:36 +08:00
|
|
|
toolchain.Cflags(),
|
|
|
|
"${commonGlobalCflags}",
|
2015-05-08 05:11:29 +08:00
|
|
|
fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice()))
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-12-16 08:07:43 +08:00
|
|
|
if Bool(ctx.AConfig().ProductVariables.Brillo) {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__")
|
|
|
|
}
|
|
|
|
|
2015-03-25 02:13:38 +08:00
|
|
|
if ctx.Device() {
|
2016-01-05 06:34:37 +08:00
|
|
|
if Bool(compiler.Properties.Rtti) {
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "-frtti")
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags())
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags())
|
2015-04-23 04:07:53 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-11-24 08:11:30 +08:00
|
|
|
if flags.Clang {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainClangCflags())
|
|
|
|
} else {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainCflags())
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if !ctx.sdk() {
|
2015-09-12 08:41:10 +08:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 05:36:34 +08:00
|
|
|
// We can enforce some rules more strictly in the code we own. strict
|
|
|
|
// indicates if this is code that we can be stricter with. If we have
|
|
|
|
// rules that we want to apply to *our* code (but maybe can't for
|
|
|
|
// vendor/device specific things), we could extend this to be a ternary
|
|
|
|
// value.
|
|
|
|
strict := true
|
|
|
|
if strings.HasPrefix(common.PathForModuleSrc(ctx).String(), "external/") {
|
|
|
|
strict = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can be used to make some annotations stricter for code we can fix
|
|
|
|
// (such as when we mark functions as deprecated).
|
|
|
|
if strict {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT")
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths {
|
2016-01-05 06:34:37 +08:00
|
|
|
// Compile files listed in c.Properties.Srcs into objects
|
2016-04-21 05:21:14 +08:00
|
|
|
objFiles := compiler.compileObjs(ctx, flags, "",
|
|
|
|
compiler.Properties.Srcs, compiler.Properties.Exclude_srcs,
|
|
|
|
deps.GeneratedSources, deps.GeneratedHeaders)
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.Failed() {
|
2015-03-19 04:28:46 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return objFiles
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// Compile a list of source files into objects a specified subdirectory
|
|
|
|
func (compiler *baseCompiler) compileObjs(ctx common.AndroidModuleContext, flags Flags,
|
2016-04-21 05:21:14 +08:00
|
|
|
subdir string, srcFiles, excludes []string, extraSrcs, deps common.Paths) common.Paths {
|
2015-03-18 06:06:21 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
buildFlags := flagsToBuilderFlags(flags)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
inputFiles := ctx.ExpandSources(srcFiles, excludes)
|
2016-04-21 05:21:14 +08:00
|
|
|
inputFiles = append(inputFiles, extraSrcs...)
|
|
|
|
srcPaths, gendeps := genSources(ctx, inputFiles, buildFlags)
|
|
|
|
|
|
|
|
deps = append(deps, gendeps...)
|
2016-01-07 06:41:07 +08:00
|
|
|
deps = append(deps, flags.CFlagsDeps...)
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return TransformSourceToObj(ctx, subdir, srcPaths, buildFlags, deps)
|
|
|
|
}
|
|
|
|
|
|
|
|
// baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties
|
|
|
|
type baseLinker struct {
|
|
|
|
Properties BaseLinkerProperties
|
|
|
|
dynamicProperties struct {
|
2016-04-12 06:06:20 +08:00
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
|
|
|
VariantIsStaticBinary bool `blueprint:"mutated"`
|
|
|
|
RunPaths []string `blueprint:"mutated"`
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 08:35:50 +08:00
|
|
|
func (linker *baseLinker) begin(ctx BaseModuleContext) {
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
2016-04-12 06:06:20 +08:00
|
|
|
linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"}
|
2016-03-31 08:35:50 +08:00
|
|
|
} else {
|
2016-04-12 06:06:20 +08:00
|
|
|
linker.dynamicProperties.RunPaths = []string{"../lib", "lib"}
|
2016-03-31 08:35:50 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (linker *baseLinker) props() []interface{} {
|
|
|
|
return []interface{}{&linker.Properties, &linker.dynamicProperties}
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
2015-04-28 02:13:34 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
|
|
|
|
|
|
|
if ctx.ModuleName() != "libcompiler_rt-extras" {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libcompiler_rt-extras")
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.Device() {
|
|
|
|
// libgcc and libatomic have to be last on the command line
|
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic")
|
|
|
|
if !Bool(linker.Properties.No_libgcc) {
|
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc")
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
if !linker.static() {
|
|
|
|
if linker.Properties.System_shared_libs != nil {
|
|
|
|
deps.LateSharedLibs = append(deps.LateSharedLibs,
|
|
|
|
linker.Properties.System_shared_libs...)
|
|
|
|
} else if !ctx.sdk() {
|
|
|
|
deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm")
|
2015-04-28 02:13:34 +08:00
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
if ctx.sdk() {
|
|
|
|
version := ctx.sdkVersion()
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs,
|
|
|
|
"ndk_libc."+version,
|
|
|
|
"ndk_libm."+version,
|
|
|
|
)
|
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return deps
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (linker *baseLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
toolchain := ctx.toolchain()
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...)
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if !ctx.noDefaultCompilerFlags() {
|
|
|
|
if ctx.Device() && !Bool(linker.Properties.Allow_undefined_symbols) {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
if flags.Clang {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags())
|
2015-04-29 04:30:13 +08:00
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
|
2015-04-29 04:30:13 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
|
2015-04-29 04:30:13 +08:00
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-03-31 08:35:50 +08:00
|
|
|
if ctx.Host() && !linker.static() {
|
|
|
|
rpath_prefix := `\$$ORIGIN/`
|
|
|
|
if ctx.Darwin() {
|
|
|
|
rpath_prefix = "@loader_path/"
|
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
for _, rpath := range linker.dynamicProperties.RunPaths {
|
2016-03-31 08:35:50 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 08:33:52 +08:00
|
|
|
if flags.Clang {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainClangLdflags())
|
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainLdflags())
|
2015-04-29 04:30:13 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return flags
|
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (linker *baseLinker) static() bool {
|
|
|
|
return linker.dynamicProperties.VariantIsStatic
|
|
|
|
}
|
2015-03-28 09:23:34 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (linker *baseLinker) staticBinary() bool {
|
|
|
|
return linker.dynamicProperties.VariantIsStaticBinary
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (linker *baseLinker) setStatic(static bool) {
|
|
|
|
linker.dynamicProperties.VariantIsStatic = static
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
func (linker *baseLinker) isDependencyRoot() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type baseLinkerInterface interface {
|
2015-03-27 05:43:45 +08:00
|
|
|
// 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-29 04:20:37 +08:00
|
|
|
setStatic(bool)
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2015-04-29 04:20:37 +08:00
|
|
|
// Returns whether a specific variant is a static library or binary
|
2015-03-27 05:43:45 +08:00
|
|
|
static() bool
|
2015-04-29 04:20:37 +08:00
|
|
|
|
|
|
|
// Returns whether a module is a static binary
|
|
|
|
staticBinary() bool
|
2016-01-07 06:41:07 +08:00
|
|
|
|
|
|
|
// Returns true for dependency roots (binaries)
|
|
|
|
// TODO(ccross): also handle dlopenable libraries
|
|
|
|
isDependencyRoot() bool
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type baseInstaller struct {
|
|
|
|
Properties InstallerProperties
|
|
|
|
|
|
|
|
dir string
|
|
|
|
dir64 string
|
|
|
|
data bool
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-03-25 04:14:12 +08:00
|
|
|
path common.OutputPath
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var _ installer = (*baseInstaller)(nil)
|
|
|
|
|
|
|
|
func (installer *baseInstaller) props() []interface{} {
|
|
|
|
return []interface{}{&installer.Properties}
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (installer *baseInstaller) install(ctx ModuleContext, file common.Path) {
|
|
|
|
subDir := installer.dir
|
|
|
|
if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
|
|
|
|
subDir = installer.dir64
|
|
|
|
}
|
|
|
|
dir := common.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path)
|
|
|
|
installer.path = ctx.InstallFile(dir, file)
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (installer *baseInstaller) inData() bool {
|
|
|
|
return installer.data
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Combined static+shared libraries
|
|
|
|
//
|
|
|
|
|
2016-04-06 07:42:05 +08:00
|
|
|
type flagExporter struct {
|
|
|
|
Properties FlagExporterProperties
|
|
|
|
|
|
|
|
flags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) {
|
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
|
|
|
|
f.flags = append(f.flags, common.JoinWithPrefix(includeDirs.Strings(), inc))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) reexportFlags(flags []string) {
|
|
|
|
f.flags = append(f.flags, flags...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) exportedFlags() []string {
|
|
|
|
return f.flags
|
|
|
|
}
|
|
|
|
|
|
|
|
type exportedFlagsProducer interface {
|
|
|
|
exportedFlags() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ exportedFlagsProducer = (*flagExporter)(nil)
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type libraryCompiler struct {
|
|
|
|
baseCompiler
|
2015-05-12 04:39:40 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
linker *libraryLinker
|
|
|
|
Properties LibraryCompilerProperties
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// For reusing static library objects for shared library
|
2015-09-24 06:26:20 +08:00
|
|
|
reuseObjFiles common.Paths
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var _ compiler = (*libraryCompiler)(nil)
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryCompiler) props() []interface{} {
|
|
|
|
props := library.baseCompiler.props()
|
|
|
|
return append(props, &library.Properties)
|
2015-03-24 08:50:24 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = library.baseCompiler.flags(ctx, flags)
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08: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-03-24 08:50:24 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if library.linker.static() {
|
|
|
|
flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
|
|
|
|
}
|
2015-03-24 08:50:24 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return flags
|
2015-03-18 06:06:21 +08:00
|
|
|
}
|
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) common.Paths {
|
2016-01-05 06:34:37 +08:00
|
|
|
var objFiles common.Paths
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-04-21 05:21:14 +08:00
|
|
|
objFiles = library.baseCompiler.compile(ctx, flags, deps)
|
2016-04-12 06:06:20 +08:00
|
|
|
library.reuseObjFiles = objFiles
|
2015-03-19 08:17:35 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if library.linker.static() {
|
|
|
|
objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceStaticLibrary,
|
2016-04-21 05:21:14 +08:00
|
|
|
library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs,
|
|
|
|
nil, deps.GeneratedHeaders)...)
|
2016-01-05 06:34:37 +08:00
|
|
|
} else {
|
|
|
|
objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceSharedLibrary,
|
2016-04-21 05:21:14 +08:00
|
|
|
library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs,
|
|
|
|
nil, deps.GeneratedHeaders)...)
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2015-07-09 09:13:11 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return objFiles
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type libraryLinker struct {
|
|
|
|
baseLinker
|
2016-04-06 07:42:05 +08:00
|
|
|
flagExporter
|
2016-04-29 05:50:03 +08:00
|
|
|
stripper
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
Properties LibraryLinkerProperties
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
dynamicProperties struct {
|
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// If we're used as a whole_static_lib, our missing dependencies need
|
|
|
|
// to be given
|
|
|
|
wholeStaticMissingDeps []string
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
// For whole_static_libs
|
|
|
|
objFiles common.Paths
|
2016-03-11 10:14:25 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var _ linker = (*libraryLinker)(nil)
|
2016-01-07 06:41:07 +08:00
|
|
|
var _ appendVariantName = (*libraryLinker)(nil)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) props() []interface{} {
|
|
|
|
props := library.baseLinker.props()
|
2016-04-06 07:42:05 +08:00
|
|
|
return append(props,
|
|
|
|
&library.Properties,
|
|
|
|
&library.dynamicProperties,
|
2016-04-29 05:50:03 +08:00
|
|
|
&library.flagExporter.Properties,
|
|
|
|
&library.stripper.StripProperties)
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
2015-03-25 05:15:58 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = library.baseLinker.flags(ctx, flags)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.Nocrt = Bool(library.Properties.Nocrt)
|
2015-04-29 08:39:43 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if !library.static() {
|
2016-05-04 09:02:42 +08:00
|
|
|
libName := ctx.ModuleName() + library.Properties.VariantName
|
2015-01-31 09:27:36 +08:00
|
|
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
|
|
|
sharedFlag := "-Wl,-shared"
|
2015-10-21 05:29:35 +08:00
|
|
|
if flags.Clang || ctx.Host() {
|
2015-01-31 09:27:36 +08:00
|
|
|
sharedFlag = "-shared"
|
|
|
|
}
|
2015-03-25 02:13:38 +08:00
|
|
|
if ctx.Device() {
|
2016-03-04 10:05:38 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2015-03-24 08:50:24 +08:00
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
if ctx.Darwin() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-dynamiclib",
|
|
|
|
"-single_module",
|
|
|
|
//"-read_only_relocs suppress",
|
2015-11-25 09:53:15 +08:00
|
|
|
"-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(),
|
2015-05-01 07:36:18 +08:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
sharedFlag,
|
2015-11-25 09:53:15 +08:00
|
|
|
"-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix(),
|
2015-05-01 07:36:18 +08:00
|
|
|
)
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2015-03-24 08:50:24 +08:00
|
|
|
|
|
|
|
return flags
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps = library.baseLinker.deps(ctx, deps)
|
|
|
|
if library.static() {
|
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Static.Whole_static_libs...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
|
|
|
|
} else {
|
|
|
|
if ctx.Device() && !Bool(library.Properties.Nocrt) {
|
|
|
|
if !ctx.sdk() {
|
|
|
|
deps.CrtBegin = "crtbegin_so"
|
|
|
|
deps.CrtEnd = "crtend_so"
|
|
|
|
} else {
|
|
|
|
deps.CrtBegin = "ndk_crtbegin_so." + ctx.sdkVersion()
|
|
|
|
deps.CrtEnd = "ndk_crtend_so." + ctx.sdkVersion()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryLinker) linkStatic(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-03-25 05:15:58 +08:00
|
|
|
objFiles = append(objFiles, deps.WholeStaticLibObjFiles...)
|
2016-01-05 06:34:37 +08:00
|
|
|
library.objFiles = objFiles
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
outputFile := common.PathForModuleOut(ctx,
|
|
|
|
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
if ctx.Darwin() {
|
2016-01-05 06:34:37 +08:00
|
|
|
TransformDarwinObjToStaticLib(ctx, objFiles, flagsToBuilderFlags(flags), outputFile)
|
2015-05-01 07:36:18 +08:00
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
TransformObjToStaticLib(ctx, objFiles, flagsToBuilderFlags(flags), outputFile)
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return outputFile
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) linkShared(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
var linkerDeps common.Paths
|
2015-07-07 08:48:31 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
versionScript := common.OptionalPathForModuleSrc(ctx, library.Properties.Version_script)
|
|
|
|
unexportedSymbols := common.OptionalPathForModuleSrc(ctx, library.Properties.Unexported_symbols_list)
|
|
|
|
forceNotWeakSymbols := common.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_not_weak_list)
|
|
|
|
forceWeakSymbols := common.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_weak_list)
|
2015-12-05 06:59:08 +08:00
|
|
|
if !ctx.Darwin() {
|
2015-09-24 06:26:20 +08:00
|
|
|
if versionScript.Valid() {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
2015-09-24 06:26:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, versionScript.Path())
|
2015-12-05 06:59:08 +08:00
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
if unexportedSymbols.Valid() {
|
2015-12-05 06:59:08 +08:00
|
|
|
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
if forceNotWeakSymbols.Valid() {
|
2015-12-05 06:59:08 +08:00
|
|
|
ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
if forceWeakSymbols.Valid() {
|
2015-12-05 06:59:08 +08:00
|
|
|
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-24 06:26:20 +08:00
|
|
|
if versionScript.Valid() {
|
2015-12-05 06:59:08 +08:00
|
|
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
if unexportedSymbols.Valid() {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
2015-09-24 06:26:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
2015-12-05 06:59:08 +08:00
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
if forceNotWeakSymbols.Valid() {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
|
2015-09-24 06:26:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
|
2015-12-05 06:59:08 +08:00
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
if forceWeakSymbols.Valid() {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
|
2015-09-24 06:26:20 +08:00
|
|
|
linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
|
2015-12-05 06:59:08 +08:00
|
|
|
}
|
2015-07-07 08:48:31 +08:00
|
|
|
}
|
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
fileName := ctx.ModuleName() + library.Properties.VariantName + flags.Toolchain.ShlibSuffix()
|
|
|
|
outputFile := common.PathForModuleOut(ctx, fileName)
|
|
|
|
ret := outputFile
|
|
|
|
|
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
|
|
|
if library.stripper.needsStrip(ctx) {
|
|
|
|
strippedOutputFile := outputFile
|
|
|
|
outputFile = common.PathForModuleOut(ctx, "unstripped", fileName)
|
|
|
|
library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
sharedLibs := deps.SharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs,
|
|
|
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
2016-04-29 05:50:03 +08:00
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
2016-01-05 06:34:37 +08:00
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
return ret
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var out common.Path
|
|
|
|
if library.static() {
|
|
|
|
out = library.linkStatic(ctx, flags, deps, objFiles)
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
out = library.linkShared(ctx, flags, deps, objFiles)
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-06 07:42:05 +08:00
|
|
|
library.exportIncludes(ctx, "-I")
|
|
|
|
library.reexportFlags(deps.ReexportedCflags)
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
return out
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) buildStatic() bool {
|
|
|
|
return library.dynamicProperties.BuildStatic
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) buildShared() bool {
|
|
|
|
return library.dynamicProperties.BuildShared
|
|
|
|
}
|
2015-03-19 05:01:18 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *libraryLinker) getWholeStaticMissingDeps() []string {
|
|
|
|
return library.wholeStaticMissingDeps
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
func (library *libraryLinker) installable() bool {
|
|
|
|
return !library.static()
|
|
|
|
}
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
func (library *libraryLinker) appendVariantName(variant string) {
|
|
|
|
library.Properties.VariantName += variant
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type libraryInstaller struct {
|
|
|
|
baseInstaller
|
|
|
|
|
2016-05-04 09:02:42 +08:00
|
|
|
linker *libraryLinker
|
|
|
|
sanitize *sanitize
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryInstaller) install(ctx ModuleContext, file common.Path) {
|
|
|
|
if !library.linker.static() {
|
|
|
|
library.baseInstaller.install(ctx, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 09:02:42 +08:00
|
|
|
func (library *libraryInstaller) inData() bool {
|
|
|
|
return library.baseInstaller.inData() || library.sanitize.inData()
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func NewLibrary(hod common.HostOrDeviceSupported, shared, static bool) *Module {
|
|
|
|
module := newModule(hod, common.MultilibBoth)
|
|
|
|
|
|
|
|
linker := &libraryLinker{}
|
|
|
|
linker.dynamicProperties.BuildShared = shared
|
|
|
|
linker.dynamicProperties.BuildStatic = static
|
|
|
|
module.linker = linker
|
|
|
|
|
|
|
|
module.compiler = &libraryCompiler{
|
|
|
|
linker: linker,
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
module.installer = &libraryInstaller{
|
|
|
|
baseInstaller: baseInstaller{
|
|
|
|
dir: "lib",
|
|
|
|
dir64: "lib64",
|
|
|
|
},
|
2016-05-04 09:02:42 +08:00
|
|
|
linker: linker,
|
|
|
|
sanitize: module.sanitize,
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func libraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostAndDeviceSupported, true, true)
|
|
|
|
return module.Init()
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
//
|
|
|
|
// Objects (for crt*.o)
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type objectLinker struct {
|
2016-04-12 05:37:39 +08:00
|
|
|
Properties ObjectLinkerProperties
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func objectFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
module.linker = &objectLinker{}
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 05:37:39 +08:00
|
|
|
func (object *objectLinker) props() []interface{} {
|
|
|
|
return []interface{}{&object.Properties}
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*objectLinker) begin(ctx BaseModuleContext) {}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-04-12 05:37:39 +08:00
|
|
|
func (object *objectLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
|
2016-01-05 06:34:37 +08:00
|
|
|
return deps
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*objectLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
2016-03-31 08:33:52 +08:00
|
|
|
if flags.Clang {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
|
|
|
|
} else {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags())
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return flags
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (object *objectLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
var outputFile common.Path
|
2015-01-31 09:27:36 +08:00
|
|
|
if len(objFiles) == 1 {
|
|
|
|
outputFile = objFiles[0]
|
|
|
|
} else {
|
2015-09-24 06:26:20 +08:00
|
|
|
output := common.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
|
2016-01-05 06:34:37 +08:00
|
|
|
TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output)
|
2015-09-24 06:26:20 +08:00
|
|
|
outputFile = output
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
2016-01-05 06:34:37 +08:00
|
|
|
return outputFile
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
func (*objectLinker) installable() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
//
|
|
|
|
// Executables
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type binaryLinker struct {
|
|
|
|
baseLinker
|
2016-04-29 05:50:03 +08:00
|
|
|
stripper
|
2015-05-12 04:39:40 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
Properties BinaryLinkerProperties
|
2015-05-12 04:39:40 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
hostToolPath common.OptionalPath
|
2015-05-12 04:39:40 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var _ linker = (*binaryLinker)(nil)
|
|
|
|
|
|
|
|
func (binary *binaryLinker) props() []interface{} {
|
2016-04-29 05:50:03 +08:00
|
|
|
return append(binary.baseLinker.props(),
|
|
|
|
&binary.Properties,
|
|
|
|
&binary.stripper.StripProperties)
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) buildStatic() bool {
|
|
|
|
return Bool(binary.Properties.Static_executable)
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) buildShared() bool {
|
|
|
|
return !Bool(binary.Properties.Static_executable)
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) getStem(ctx BaseModuleContext) string {
|
2015-03-27 06:12:10 +08:00
|
|
|
stem := ctx.ModuleName()
|
2016-01-05 06:34:37 +08:00
|
|
|
if binary.Properties.Stem != "" {
|
|
|
|
stem = binary.Properties.Stem
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2015-03-27 06:12:10 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return stem + binary.Properties.Suffix
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps = binary.baseLinker.deps(ctx, deps)
|
2015-03-25 02:13:38 +08:00
|
|
|
if ctx.Device() {
|
2016-01-05 06:34:37 +08:00
|
|
|
if !ctx.sdk() {
|
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
deps.CrtBegin = "crtbegin_static"
|
2015-04-29 09:17:56 +08:00
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.CrtBegin = "crtbegin_dynamic"
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.CrtEnd = "crtend_android"
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
deps.CrtBegin = "ndk_crtbegin_static." + ctx.sdkVersion()
|
2015-04-29 09:17:56 +08:00
|
|
|
} else {
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.CrtBegin = "ndk_crtbegin_dynamic." + ctx.sdkVersion()
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.CrtEnd = "ndk_crtend_android." + ctx.sdkVersion()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
if inList("libc++_static", deps.StaticLibs) {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
|
2015-04-29 04:30:13 +08:00
|
|
|
}
|
2015-03-27 05:43:45 +08: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
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.StaticLibs, groupLibs = filterList(deps.StaticLibs,
|
2015-03-27 05:43:45 +08:00
|
|
|
[]string{"libc", "libc_nomalloc", "libcompiler_rt"})
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...)
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
if !Bool(binary.Properties.Static_executable) && inList("libc", deps.StaticLibs) {
|
|
|
|
ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" +
|
|
|
|
"from static libs or set static_executable: true")
|
|
|
|
}
|
|
|
|
return deps
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
func (*binaryLinker) installable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
func (binary *binaryLinker) isDependencyRoot() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func NewBinary(hod common.HostOrDeviceSupported) *Module {
|
|
|
|
module := newModule(hod, common.MultilibFirst)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
module.linker = &binaryLinker{}
|
|
|
|
module.installer = &baseInstaller{
|
|
|
|
dir: "bin",
|
|
|
|
}
|
|
|
|
return module
|
|
|
|
}
|
2015-03-24 08:50:24 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func binaryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBinary(common.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) ModifyProperties(ctx ModuleContext) {
|
2015-05-01 07:36:18 +08:00
|
|
|
if ctx.Darwin() {
|
2016-01-05 06:34:37 +08:00
|
|
|
binary.Properties.Static_executable = proptools.BoolPtr(false)
|
2015-05-01 07:36:18 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
binary.dynamicProperties.VariantIsStaticBinary = true
|
2015-04-29 04:20:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = binary.baseLinker.flags(ctx, flags)
|
2015-03-25 05:15:58 +08:00
|
|
|
|
2015-11-25 09:53:15 +08: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 08:50:24 +08:00
|
|
|
|
2015-03-25 02:13:38 +08:00
|
|
|
if ctx.Device() {
|
2016-01-05 06:34:37 +08:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
2015-03-27 05:43:45 +08: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 09:27:36 +08:00
|
|
|
|
2015-03-27 05:43:45 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Bstatic",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
|
|
|
|
|
|
|
} else {
|
2016-01-07 06:41:07 +08:00
|
|
|
if flags.DynamicLinker == "" {
|
|
|
|
flags.DynamicLinker = "/system/bin/linker"
|
|
|
|
if flags.Toolchain.Is64Bit() {
|
|
|
|
flags.DynamicLinker += "64"
|
|
|
|
}
|
2015-03-27 05:43:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
2015-12-02 06:09:48 +08:00
|
|
|
"-pie",
|
2015-03-27 05:43:45 +08:00
|
|
|
"-nostdlib",
|
|
|
|
"-Bdynamic",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,-z,nocopyreloc",
|
|
|
|
)
|
|
|
|
}
|
2015-05-01 07:36:18 +08:00
|
|
|
} else if ctx.Darwin() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names")
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
return flags
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
|
|
|
|
outputFile := common.PathForModuleOut(ctx, fileName)
|
|
|
|
ret := outputFile
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.HostOrDevice().Host() {
|
|
|
|
binary.hostToolPath = common.OptionalPathForPath(outputFile)
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
var linkerDeps common.Paths
|
2015-07-07 08:48:31 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
sharedLibs := deps.SharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
2015-04-29 04:25:36 +08:00
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
if flags.DynamicLinker != "" {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, " -Wl,-dynamic-linker,"+flags.DynamicLinker)
|
|
|
|
}
|
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
|
|
|
if binary.stripper.needsStrip(ctx) {
|
|
|
|
strippedOutputFile := outputFile
|
|
|
|
outputFile = common.PathForModuleOut(ctx, "unstripped", fileName)
|
|
|
|
binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
|
|
|
if binary.Properties.Prefix_symbols != "" {
|
|
|
|
afterPrefixSymbols := outputFile
|
|
|
|
outputFile = common.PathForModuleOut(ctx, "unprefixed", fileName)
|
|
|
|
TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile,
|
|
|
|
flagsToBuilderFlags(flags), afterPrefixSymbols)
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs,
|
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
|
2016-04-29 05:50:03 +08:00
|
|
|
builderFlags, outputFile)
|
2015-03-19 05:01:18 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return ret
|
2015-09-17 07:00:08 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (binary *binaryLinker) HostToolPath() common.OptionalPath {
|
|
|
|
return binary.hostToolPath
|
2015-09-17 07:00:08 +08:00
|
|
|
}
|
|
|
|
|
2016-04-29 05:50:03 +08:00
|
|
|
type stripper struct {
|
|
|
|
StripProperties StripProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stripper *stripper) needsStrip(ctx ModuleContext) bool {
|
|
|
|
return !ctx.AConfig().EmbeddedInMake() && !stripper.StripProperties.Strip.None
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stripper *stripper) strip(ctx ModuleContext, in, out common.ModuleOutPath,
|
|
|
|
flags builderFlags) {
|
2016-05-04 06:10:29 +08:00
|
|
|
if ctx.Darwin() {
|
|
|
|
TransformDarwinStrip(ctx, in, out)
|
|
|
|
} else {
|
|
|
|
flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols
|
|
|
|
// TODO(ccross): don't add gnu debuglink for user builds
|
|
|
|
flags.stripAddGnuDebuglink = true
|
|
|
|
TransformStrip(ctx, in, out, flags)
|
|
|
|
}
|
2016-04-29 05:50:03 +08:00
|
|
|
}
|
|
|
|
|
2015-10-30 06:25:03 +08:00
|
|
|
func testPerSrcMutator(mctx common.AndroidBottomUpMutatorContext) {
|
2016-01-05 06:34:37 +08:00
|
|
|
if m, ok := mctx.Module().(*Module); ok {
|
|
|
|
if test, ok := m.linker.(*testLinker); ok {
|
|
|
|
if Bool(test.Properties.Test_per_src) {
|
|
|
|
testNames := make([]string, len(m.compiler.(*baseCompiler).Properties.Srcs))
|
|
|
|
for i, src := range m.compiler.(*baseCompiler).Properties.Srcs {
|
|
|
|
testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
|
|
|
|
}
|
|
|
|
tests := mctx.CreateLocalVariations(testNames...)
|
|
|
|
for i, src := range m.compiler.(*baseCompiler).Properties.Srcs {
|
|
|
|
tests[i].(*Module).compiler.(*baseCompiler).Properties.Srcs = []string{src}
|
|
|
|
tests[i].(*Module).linker.(*testLinker).binaryLinker.Properties.Stem = testNames[i]
|
|
|
|
}
|
2015-09-17 07:00:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-12 04:39:40 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type testLinker struct {
|
|
|
|
binaryLinker
|
|
|
|
Properties TestLinkerProperties
|
2015-12-22 07:25:58 +08:00
|
|
|
}
|
|
|
|
|
2016-03-31 08:35:50 +08:00
|
|
|
func (test *testLinker) begin(ctx BaseModuleContext) {
|
|
|
|
test.binaryLinker.begin(ctx)
|
|
|
|
|
|
|
|
runpath := "../../lib"
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
|
|
|
runpath += "64"
|
|
|
|
}
|
2016-04-12 06:06:20 +08:00
|
|
|
test.dynamicProperties.RunPaths = append([]string{runpath}, test.dynamicProperties.RunPaths...)
|
2016-03-31 08:35:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (test *testLinker) props() []interface{} {
|
|
|
|
return append(test.binaryLinker.props(), &test.Properties)
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = test.binaryLinker.flags(ctx, flags)
|
|
|
|
|
|
|
|
if !test.Properties.Gtest {
|
2015-12-22 07:25:58 +08:00
|
|
|
return flags
|
|
|
|
}
|
2015-03-19 05:01:18 +08:00
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING")
|
2015-03-25 02:13:38 +08:00
|
|
|
if ctx.Host() {
|
2015-03-24 08:50:24 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, "-O0", "-g")
|
2015-12-22 07:25:58 +08: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-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2015-03-25 05:15:58 +08:00
|
|
|
return flags
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (test *testLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
if test.Properties.Gtest {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest")
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
deps = test.binaryLinker.deps(ctx, deps)
|
|
|
|
return deps
|
2015-12-22 07:25:58 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type testInstaller struct {
|
|
|
|
baseInstaller
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (installer *testInstaller) install(ctx ModuleContext, file common.Path) {
|
|
|
|
installer.dir = filepath.Join(installer.dir, ctx.ModuleName())
|
|
|
|
installer.dir64 = filepath.Join(installer.dir64, ctx.ModuleName())
|
|
|
|
installer.baseInstaller.install(ctx, file)
|
2015-04-25 08:48:09 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func NewTest(hod common.HostOrDeviceSupported) *Module {
|
|
|
|
module := newModule(hod, common.MultilibBoth)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
linker := &testLinker{}
|
|
|
|
linker.Properties.Gtest = true
|
|
|
|
module.linker = linker
|
|
|
|
module.installer = &testInstaller{
|
|
|
|
baseInstaller: baseInstaller{
|
|
|
|
dir: "nativetest",
|
|
|
|
dir64: "nativetest64",
|
|
|
|
data: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return module
|
2015-03-20 05:05:33 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func testFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewTest(common.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
2015-05-08 06:44:20 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type benchmarkLinker struct {
|
|
|
|
binaryLinker
|
2015-05-08 06:44:20 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (benchmark *benchmarkLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps = benchmark.binaryLinker.deps(ctx, deps)
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libbenchmark", "libbase")
|
|
|
|
return deps
|
2015-12-22 06:55:28 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func NewBenchmark(hod common.HostOrDeviceSupported) *Module {
|
|
|
|
module := newModule(hod, common.MultilibFirst)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
module.linker = &benchmarkLinker{}
|
|
|
|
module.installer = &baseInstaller{
|
|
|
|
dir: "nativetest",
|
|
|
|
dir64: "nativetest64",
|
|
|
|
data: true,
|
2015-05-08 06:44:20 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
return module
|
2015-05-08 06:44:20 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func benchmarkFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBenchmark(common.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
2015-05-08 06:44:20 +08:00
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
//
|
|
|
|
// Static library
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func libraryStaticFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostAndDeviceSupported, false, true)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Shared libraries
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func librarySharedFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostAndDeviceSupported, true, false)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host static library
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func libraryHostStaticFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostSupported, false, true)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host Shared libraries
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func libraryHostSharedFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostSupported, true, false)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host Binaries
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func binaryHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBinary(common.HostSupported)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-03-27 07:09:47 +08:00
|
|
|
//
|
|
|
|
// Host Tests
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func testHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewTest(common.HostSupported)
|
|
|
|
return module.Init()
|
2015-03-27 07:09:47 +08:00
|
|
|
}
|
|
|
|
|
2015-05-08 06:44:20 +08:00
|
|
|
//
|
|
|
|
// Host Benchmarks
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func benchmarkHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBenchmark(common.HostSupported)
|
|
|
|
return module.Init()
|
2015-05-08 06:44:20 +08:00
|
|
|
}
|
|
|
|
|
2015-11-03 08:43:11 +08:00
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
2016-01-05 06:34:37 +08:00
|
|
|
type Defaults struct {
|
2015-11-03 08:43:11 +08:00
|
|
|
common.AndroidModuleBase
|
|
|
|
common.DefaultsModule
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*Defaults) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
2015-11-03 08:43:11 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func defaultsFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &Defaults{}
|
2015-11-03 08:43:11 +08:00
|
|
|
|
|
|
|
propertyStructs := []interface{}{
|
2016-01-05 06:34:37 +08:00
|
|
|
&BaseProperties{},
|
|
|
|
&BaseCompilerProperties{},
|
|
|
|
&BaseLinkerProperties{},
|
|
|
|
&LibraryCompilerProperties{},
|
2016-04-06 07:42:05 +08:00
|
|
|
&FlagExporterProperties{},
|
2016-01-05 06:34:37 +08:00
|
|
|
&LibraryLinkerProperties{},
|
|
|
|
&BinaryLinkerProperties{},
|
|
|
|
&TestLinkerProperties{},
|
|
|
|
&UnusedProperties{},
|
|
|
|
&StlProperties{},
|
2016-01-07 06:41:07 +08:00
|
|
|
&SanitizeProperties{},
|
2016-04-29 05:50:03 +08:00
|
|
|
&StripProperties{},
|
2015-11-03 08:43:11 +08:00
|
|
|
}
|
|
|
|
|
2015-07-09 09:13:11 +08:00
|
|
|
_, propertyStructs = common.InitAndroidArchModule(module, common.HostAndDeviceDefault,
|
|
|
|
common.MultilibDefault, propertyStructs...)
|
2015-11-03 08:43:11 +08:00
|
|
|
|
|
|
|
return common.InitDefaultsModule(module, module, propertyStructs...)
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
//
|
|
|
|
// Device libraries shipped with gcc
|
|
|
|
//
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type toolchainLibraryLinker struct {
|
|
|
|
baseLinker
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var _ baseLinkerInterface = (*toolchainLibraryLinker)(nil)
|
|
|
|
|
|
|
|
func (*toolchainLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2015-01-31 09:27:36 +08:00
|
|
|
// toolchain libraries can't have any dependencies
|
2016-01-05 06:34:37 +08:00
|
|
|
return deps
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*toolchainLibraryLinker) buildStatic() bool {
|
|
|
|
return true
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*toolchainLibraryLinker) buildShared() bool {
|
|
|
|
return false
|
|
|
|
}
|
2015-03-24 08:50:24 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func toolchainLibraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
module.linker = &toolchainLibraryLinker{}
|
|
|
|
module.Properties.Clang = proptools.BoolPtr(false)
|
|
|
|
return module.Init()
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (library *toolchainLibraryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
libName := ctx.ModuleName() + staticLibraryExtension
|
2015-09-24 06:26:20 +08:00
|
|
|
outputFile := common.PathForModuleOut(ctx, libName)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2016-01-13 08:22:40 +08:00
|
|
|
if flags.Clang {
|
|
|
|
ctx.ModuleErrorf("toolchain_library must use GCC, not Clang")
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return outputFile
|
2015-03-19 05:01:18 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 06:06:20 +08:00
|
|
|
func (*toolchainLibraryLinker) installable() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-03-19 14:38:50 +08: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 06:26:20 +08: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 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 09:17:56 +08:00
|
|
|
func ndkPrebuiltModuleToPath(ctx common.AndroidModuleContext, toolchain Toolchain,
|
2015-09-24 06:26:20 +08:00
|
|
|
ext string, version string) common.Path {
|
2015-04-29 09:17:56 +08: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 06:26:20 +08:00
|
|
|
return dir.Join(ctx, name+ext)
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type ndkPrebuiltObjectLinker struct {
|
|
|
|
objectLinker
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*ndkPrebuiltObjectLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2015-04-29 09:17:56 +08:00
|
|
|
// NDK objects can't have any dependencies
|
2016-01-05 06:34:37 +08:00
|
|
|
return deps
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
module.linker = &ndkPrebuiltObjectLinker{}
|
|
|
|
return module.Init()
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps, objFiles common.Paths) common.Path {
|
2015-04-29 09:17:56 +08: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")
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion())
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type ndkPrebuiltLibraryLinker struct {
|
|
|
|
libraryLinker
|
2015-04-29 09:17:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil)
|
|
|
|
var _ exportedFlagsProducer = (*libraryLinker)(nil)
|
2015-04-29 09:17:56 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (ndk *ndkPrebuiltLibraryLinker) props() []interface{} {
|
2016-04-06 07:42:05 +08:00
|
|
|
return append(ndk.libraryLinker.props(), &ndk.Properties, &ndk.flagExporter.Properties)
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (*ndkPrebuiltLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2015-03-19 14:38:50 +08:00
|
|
|
// NDK libraries can't have any dependencies
|
2016-01-05 06:34:37 +08:00
|
|
|
return deps
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func ndkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
linker := &ndkPrebuiltLibraryLinker{}
|
|
|
|
linker.dynamicProperties.BuildShared = true
|
|
|
|
module.linker = linker
|
|
|
|
return module.Init()
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps, objFiles common.Paths) common.Path {
|
2015-03-19 14:38:50 +08: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")
|
|
|
|
}
|
|
|
|
|
2016-04-06 07:42:05 +08:00
|
|
|
ndk.exportIncludes(ctx, "-isystem")
|
2015-03-19 14:38:50 +08:00
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(),
|
|
|
|
ctx.sdkVersion())
|
2015-03-19 14:38:50 +08: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.
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type ndkPrebuiltStlLinker struct {
|
|
|
|
ndkPrebuiltLibraryLinker
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func ndkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
linker := &ndkPrebuiltStlLinker{}
|
|
|
|
linker.dynamicProperties.BuildShared = true
|
|
|
|
module.linker = linker
|
|
|
|
return module.Init()
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func ndkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
linker := &ndkPrebuiltStlLinker{}
|
|
|
|
linker.dynamicProperties.BuildStatic = true
|
|
|
|
module.linker = linker
|
|
|
|
return module.Init()
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl string) common.SourcePath {
|
2015-03-19 14:38:50 +08: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 06:26:20 +08:00
|
|
|
ndkSrcRoot := "prebuilts/ndk/current/sources"
|
|
|
|
return common.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0])
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleErrorf("Unknown NDK STL: %s", stl)
|
2015-09-24 06:26:20 +08:00
|
|
|
return common.PathForSource(ctx, "")
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps, objFiles common.Paths) common.Path {
|
2015-03-19 14:38:50 +08: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")
|
|
|
|
}
|
|
|
|
|
2016-04-06 07:42:05 +08:00
|
|
|
ndk.exportIncludes(ctx, "-I")
|
2015-03-19 14:38:50 +08:00
|
|
|
|
|
|
|
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
2015-11-25 09:53:15 +08:00
|
|
|
libExt := flags.Toolchain.ShlibSuffix()
|
2016-01-05 06:34:37 +08:00
|
|
|
if ndk.dynamicProperties.BuildStatic {
|
2015-03-19 14:38:50 +08:00
|
|
|
libExt = staticLibraryExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
stlName := strings.TrimSuffix(libName, "_shared")
|
|
|
|
stlName = strings.TrimSuffix(stlName, "_static")
|
|
|
|
libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
|
2016-01-05 06:34:37 +08:00
|
|
|
return libDir.Join(ctx, libName+libExt)
|
2015-03-19 14:38:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-30 06:25:03 +08:00
|
|
|
func linkageMutator(mctx common.AndroidBottomUpMutatorContext) {
|
2016-01-05 06:34:37 +08:00
|
|
|
if m, ok := mctx.Module().(*Module); ok {
|
|
|
|
if m.linker != nil {
|
|
|
|
if linker, ok := m.linker.(baseLinkerInterface); ok {
|
|
|
|
var modules []blueprint.Module
|
|
|
|
if linker.buildStatic() && linker.buildShared() {
|
|
|
|
modules = mctx.CreateLocalVariations("static", "shared")
|
2016-04-12 06:06:20 +08:00
|
|
|
static := modules[0].(*Module)
|
|
|
|
shared := modules[1].(*Module)
|
|
|
|
|
|
|
|
static.linker.(baseLinkerInterface).setStatic(true)
|
|
|
|
shared.linker.(baseLinkerInterface).setStatic(false)
|
|
|
|
|
|
|
|
if staticCompiler, ok := static.compiler.(*libraryCompiler); ok {
|
|
|
|
sharedCompiler := shared.compiler.(*libraryCompiler)
|
|
|
|
if len(staticCompiler.Properties.Static.Cflags) == 0 &&
|
|
|
|
len(sharedCompiler.Properties.Shared.Cflags) == 0 {
|
|
|
|
// Optimize out compiling common .o files twice for static+shared libraries
|
|
|
|
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
|
|
|
sharedCompiler.baseCompiler.Properties.Srcs = nil
|
|
|
|
}
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
} else if linker.buildStatic() {
|
|
|
|
modules = mctx.CreateLocalVariations("static")
|
|
|
|
modules[0].(*Module).linker.(baseLinkerInterface).setStatic(true)
|
|
|
|
} else if linker.buildShared() {
|
|
|
|
modules = mctx.CreateLocalVariations("shared")
|
|
|
|
modules[0].(*Module).linker.(baseLinkerInterface).setStatic(false)
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("library %q not static or shared", mctx.ModuleName()))
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 04:30:13 +08: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 08:23:31 +08:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|