2015-03-18 21:28:46 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
// This file contains the module types for compiling C/C++ for Android, and converts the properties
|
|
|
|
// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
|
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
"github.com/google/blueprint"
|
2015-10-29 01:23:31 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
"android/soong"
|
2015-01-31 02:27:36 +01:00
|
|
|
"android/soong/common"
|
2015-03-18 21:28:46 +01:00
|
|
|
"android/soong/genrule"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
2016-01-04 23:34:37 +01: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-17 23:20:06 +02: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-29 23:25:03 +01:00
|
|
|
common.RegisterBottomUpMutator("link", linkageMutator)
|
|
|
|
common.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
|
|
|
|
common.RegisterBottomUpMutator("deps", depsMutator)
|
2015-06-17 23:20:06 +02:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
var (
|
2015-04-08 02:11:30 +02:00
|
|
|
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", common.Config.PrebuiltOS)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
LibcRoot = pctx.SourcePathVariable("LibcRoot", "bionic/libc")
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Flags used by lots of devices. Putting them in package static variables will save bytes in
|
|
|
|
// build.ninja so they aren't repeated for every file
|
|
|
|
var (
|
|
|
|
commonGlobalCflags = []string{
|
|
|
|
"-DANDROID",
|
|
|
|
"-fmessage-length=0",
|
|
|
|
"-W",
|
|
|
|
"-Wall",
|
|
|
|
"-Wno-unused",
|
|
|
|
"-Winit-self",
|
|
|
|
"-Wpointer-arith",
|
|
|
|
|
|
|
|
// COMMON_RELEASE_CFLAGS
|
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceGlobalCflags = []string{
|
2015-11-25 02:53:15 +01:00
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// TARGET_ERROR_FLAGS
|
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
2016-03-02 00:16:50 +01:00
|
|
|
"-Werror=date-time",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
2015-09-12 02:41:10 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 02:21:04 +01:00
|
|
|
noOverrideGlobalCflags = []string{
|
|
|
|
"-Werror=int-to-pointer-cast",
|
|
|
|
"-Werror=pointer-to-int-cast",
|
|
|
|
}
|
|
|
|
|
2015-09-12 02:41:10 +02:00
|
|
|
illegalFlags = []string{
|
|
|
|
"-w",
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-03-30 02:31:57 +02:00
|
|
|
if common.CurrentHostType() == common.Linux {
|
|
|
|
commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " "))
|
2016-03-04 02:21:04 +01:00
|
|
|
pctx.StaticVariable("noOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("commonClangGlobalCflags",
|
2016-01-13 01:22:40 +01:00
|
|
|
strings.Join(append(clangFilterUnknownCflags(commonGlobalCflags), "${clangExtraCflags}"), " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
pctx.StaticVariable("deviceClangGlobalCflags",
|
2016-01-13 01:22:40 +01:00
|
|
|
strings.Join(append(clangFilterUnknownCflags(deviceGlobalCflags), "${clangExtraTargetCflags}"), " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
pctx.StaticVariable("hostClangGlobalCflags",
|
|
|
|
strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " "))
|
2016-03-04 02:21:04 +01:00
|
|
|
pctx.StaticVariable("noOverrideClangGlobalCflags",
|
|
|
|
strings.Join(append(clangFilterUnknownCflags(noOverrideGlobalCflags), "${clangExtraNoOverrideCflags}"), " "))
|
|
|
|
|
2015-03-11 20:03:03 +01:00
|
|
|
pctx.StaticVariable("commonClangGlobalCppflags",
|
2016-01-13 01:22:40 +01:00
|
|
|
strings.Join(append(clangFilterUnknownCflags(commonGlobalCppflags), "${clangExtraCppflags}"), " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// Everything in this list is a crime against abstraction and dependency tracking.
|
|
|
|
// Do not add anything to this list.
|
2015-12-19 00:11:17 +01:00
|
|
|
pctx.PrefixedPathsForOptionalSourceVariable("commonGlobalIncludes", "-isystem ",
|
2015-09-24 00:26:20 +02:00
|
|
|
[]string{
|
|
|
|
"system/core/include",
|
2016-03-02 00:27:03 +01:00
|
|
|
"system/media/audio/include",
|
2015-09-24 00:26:20 +02: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 02:42:34 +01: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 02:27:36 +01:00
|
|
|
|
2016-03-16 19:37:17 +01: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-03-21 23:12:34 +01:00
|
|
|
return "clang-2690385", nil
|
2016-03-16 19:37:17 +01:00
|
|
|
})
|
|
|
|
pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}/bin")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type Deps struct {
|
|
|
|
SharedLibs, LateSharedLibs []string
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-04-11 23:37:39 +02:00
|
|
|
ObjFiles []string
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
Cflags, ReexportedCflags []string
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
CrtBegin, CrtEnd string
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type PathDeps struct {
|
|
|
|
SharedLibs, LateSharedLibs common.Paths
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs common.Paths
|
2015-09-24 00:26:20 +02:00
|
|
|
|
|
|
|
ObjFiles common.Paths
|
|
|
|
WholeStaticLibObjFiles common.Paths
|
|
|
|
|
|
|
|
Cflags, ReexportedCflags []string
|
|
|
|
|
|
|
|
CrtBegin, CrtEnd common.OptionalPath
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type Flags struct {
|
2015-04-22 22:07:53 +02:00
|
|
|
GlobalFlags []string // Flags that apply to C, C++, and assembly source files
|
|
|
|
AsFlags []string // Flags that apply to assembly source files
|
|
|
|
CFlags []string // Flags that apply to C and C++ source files
|
|
|
|
ConlyFlags []string // Flags that apply to C source files
|
|
|
|
CppFlags []string // Flags that apply to C++ source files
|
|
|
|
YaccFlags []string // Flags that apply to Yacc source files
|
|
|
|
LdFlags []string // Flags that apply to linker command lines
|
|
|
|
|
|
|
|
Nocrt bool
|
|
|
|
Toolchain Toolchain
|
|
|
|
Clang bool
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
RequiredInstructionSet string
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type BaseCompilerProperties struct {
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files.
|
2015-07-01 03:15:24 +02:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of source files that should not be used to build the C/C++ module.
|
|
|
|
// This is most useful in the arch/multilib variants to remove non-common files
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C and C++ compiles.
|
|
|
|
Cflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C++ compiles
|
|
|
|
Cppflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for C compiles
|
|
|
|
Conlyflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for .S compiles
|
|
|
|
Asflags []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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-11 22:39:40 +02:00
|
|
|
// list of module-specific flags that will be used for .y and .yy compiles
|
|
|
|
Yaccflags []string
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// the instruction set architecture to use to compile the C/C++
|
|
|
|
// module.
|
|
|
|
Instruction_set string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of directories relative to the root of the source tree that will
|
|
|
|
// be added to the include path using -I.
|
|
|
|
// If possible, don't use this. If adding paths from the current directory use
|
|
|
|
// local_include_dirs, if adding paths from other modules use export_include_dirs in
|
|
|
|
// that module.
|
|
|
|
Include_dirs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-09-14 21:30:50 +02:00
|
|
|
// list of files relative to the root of the source tree that will be included
|
|
|
|
// using -include.
|
|
|
|
// If possible, don't use this.
|
|
|
|
Include_files []string `android:"arch_variant"`
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I
|
|
|
|
Local_include_dirs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-09-14 21:30:50 +02:00
|
|
|
// list of files relative to the Blueprints file that will be included
|
|
|
|
// using -include.
|
|
|
|
// If possible, don't use this.
|
|
|
|
Local_include_files []string `android:"arch_variant"`
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// pass -frtti instead of -fno-rtti
|
|
|
|
Rtti *bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type BaseLinkerProperties struct {
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of modules whose object files should be linked into this module
|
|
|
|
// in their entirety. For static library modules, all of the .o files from the intermediate
|
|
|
|
// directory of the dependency will be linked into this modules .a file. For a shared library,
|
|
|
|
// the dependency's .a file will be linked into this module using -Wl,--whole-archive.
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of modules that should be statically linked into this module.
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// list of modules that should be dynamically linked into this module.
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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-11 22:39:40 +02:00
|
|
|
// allow the module to contain undefined symbols. By default,
|
|
|
|
// modules cannot contain undefined symbols that are not satisified by their immediate
|
|
|
|
// dependencies. Set this flag to true to remove --no-undefined from the linker flags.
|
|
|
|
// This flag should only be necessary for compiling low-level libraries like libc.
|
2015-10-29 01:23:31 +01:00
|
|
|
Allow_undefined_symbols *bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
|
|
|
|
// list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I for any module that links against this module
|
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// don't link in crt_begin and crt_end. This flag should only be necessary for
|
|
|
|
// compiling crt or libc.
|
2015-10-29 01:23:31 +01:00
|
|
|
Nocrt *bool `android:"arch_variant"`
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type BinaryLinkerProperties struct {
|
|
|
|
// compile executable with -static
|
|
|
|
Static_executable *bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// set the name of the output
|
|
|
|
Stem string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// append to the name of the output
|
|
|
|
Suffix string `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// if set, add an extra objcopy --prefix-symbols= step
|
|
|
|
Prefix_symbols string
|
|
|
|
}
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type TestLinkerProperties struct {
|
|
|
|
// if set, build against the gtest library. Defaults to true.
|
|
|
|
Gtest bool
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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-11 22:39:40 +02:00
|
|
|
|
2016-04-11 23:37:39 +02: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-04 23:34:37 +01: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 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// Minimum sdk version supported when compiling against the ndk
|
|
|
|
Sdk_version string
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// don't insert default compiler flags into asflags, cflags,
|
|
|
|
// cppflags, conlyflags, ldflags, or include_dirs
|
|
|
|
No_default_compiler_flags *bool
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
AndroidMkSharedLibs []string `blueprint:"mutated"`
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type InstallerProperties struct {
|
2015-05-11 22:39:40 +02:00
|
|
|
// install to a subdirectory of the default install path for the module
|
|
|
|
Relative_install_path string
|
|
|
|
}
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type UnusedProperties struct {
|
2016-04-16 01:27:17 +02:00
|
|
|
Native_coverage *bool
|
|
|
|
Required []string
|
|
|
|
Strip string
|
|
|
|
Tags []string
|
|
|
|
Sanitize struct {
|
|
|
|
Never bool `android:"arch_variant"`
|
|
|
|
Address bool `android:"arch_variant"`
|
|
|
|
Thread bool `android:"arch_variant"`
|
|
|
|
Undefined bool `android:"arch_variant"`
|
|
|
|
All_undefined bool `android:"arch_variant"`
|
|
|
|
Misc_undefined []string `android:"arch_variant"`
|
|
|
|
Coverage bool `android:"arch_variant"`
|
|
|
|
Recover []string
|
|
|
|
} `android:"arch_variant"`
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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
|
|
|
|
compile(ctx ModuleContext, flags Flags) common.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
type linker interface {
|
|
|
|
feature
|
|
|
|
link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles common.Paths) common.Path
|
2016-04-12 00:06:20 +02:00
|
|
|
installable() bool
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type installer interface {
|
|
|
|
props() []interface{}
|
|
|
|
install(ctx ModuleContext, path common.Path)
|
|
|
|
inData() bool
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02: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}
|
|
|
|
objDepTag = dependencyTag{name: "obj"}
|
|
|
|
crtBeginDepTag = dependencyTag{name: "crtbegin"}
|
|
|
|
crtEndDepTag = dependencyTag{name: "crtend"}
|
|
|
|
reuseObjTag = dependencyTag{name: "reuse objects"}
|
|
|
|
)
|
|
|
|
|
2016-01-04 23:34:37 +01: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-11 22:39:40 +02:00
|
|
|
common.AndroidModuleBase
|
2015-11-03 01:43:11 +01:00
|
|
|
common.DefaultableModule
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
Properties BaseProperties
|
|
|
|
unused UnusedProperties
|
|
|
|
|
|
|
|
// initialize before calling Init
|
|
|
|
hod common.HostOrDeviceSupported
|
|
|
|
multilib common.Multilib
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// delegates, initialize before calling Init
|
|
|
|
customizer Customizer
|
|
|
|
features []feature
|
|
|
|
compiler compiler
|
|
|
|
linker linker
|
|
|
|
installer installer
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
outputFile common.OptionalPath
|
2015-04-28 22:30:13 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
cachedToolchain Toolchain
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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()...)
|
|
|
|
}
|
|
|
|
for _, feature := range c.features {
|
|
|
|
props = append(props, feature.props()...)
|
|
|
|
}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
_, props = common.InitAndroidArchModule(c, c.hod, c.multilib, props...)
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return common.InitDefaultableModule(c, c, props...)
|
|
|
|
}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type baseModuleContext struct {
|
|
|
|
common.AndroidBaseContext
|
|
|
|
moduleContextImpl
|
|
|
|
}
|
2015-11-03 01:43:11 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type moduleContext struct {
|
|
|
|
common.AndroidModuleContext
|
|
|
|
moduleContextImpl
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func newModule(hod common.HostOrDeviceSupported, multilib common.Multilib) *Module {
|
|
|
|
module := newBaseModule(hod, multilib)
|
|
|
|
module.features = []feature{
|
|
|
|
&stlFeature{},
|
|
|
|
}
|
|
|
|
return module
|
|
|
|
}
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.compiler != nil {
|
|
|
|
flags = c.compiler.flags(ctx, flags)
|
|
|
|
}
|
|
|
|
if c.linker != nil {
|
|
|
|
flags = c.linker.flags(ctx, flags)
|
|
|
|
}
|
|
|
|
for _, feature := range c.features {
|
|
|
|
flags = feature.flags(ctx, flags)
|
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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-18 21:28:46 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
deps := c.depsToPaths(ctx)
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, deps.Cflags...)
|
|
|
|
|
|
|
|
var objFiles common.Paths
|
|
|
|
if c.compiler != nil {
|
|
|
|
objFiles = c.compiler.compile(ctx, flags)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 00:06:20 +02:00
|
|
|
if c.installer != nil && c.linker.installable() {
|
2016-01-04 23:34:37 +01:00
|
|
|
c.installer.install(ctx, outputFile)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
return c.cachedToolchain
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (c *Module) begin(ctx BaseModuleContext) {
|
|
|
|
if c.compiler != nil {
|
|
|
|
c.compiler.begin(ctx)
|
|
|
|
}
|
|
|
|
if c.linker != nil {
|
|
|
|
c.linker.begin(ctx)
|
|
|
|
}
|
|
|
|
for _, feature := range c.features {
|
|
|
|
feature.begin(ctx)
|
|
|
|
}
|
2015-04-25 02:31:52 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02: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)
|
|
|
|
}
|
|
|
|
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-04 23:34:37 +01:00
|
|
|
func (c *Module) depsMutator(actx common.AndroidBottomUpMutatorContext) {
|
|
|
|
ctx := &baseModuleContext{
|
|
|
|
AndroidBaseContext: actx,
|
|
|
|
moduleContextImpl: moduleContextImpl{
|
|
|
|
mod: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.ctx = ctx
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.customizer != nil {
|
|
|
|
c.customizer.CustomizeProperties(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.begin(ctx)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
deps := c.deps(ctx)
|
2015-04-28 22:30:13 +02:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
c.Properties.AndroidMkSharedLibs = deps.SharedLibs
|
|
|
|
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
|
|
|
|
deps.WholeStaticLibs...)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, staticDepTag,
|
|
|
|
deps.StaticLibs...)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
|
|
|
|
deps.LateStaticLibs...)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, sharedDepTag,
|
|
|
|
deps.SharedLibs...)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
|
|
|
|
deps.LateSharedLibs...)
|
2016-04-11 23:37:39 +02:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddDependency(ctx.module(), objDepTag, deps.ObjFiles...)
|
|
|
|
|
|
|
|
if deps.CrtBegin != "" {
|
|
|
|
actx.AddDependency(ctx.module(), crtBeginDepTag, deps.CrtBegin)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
if deps.CrtEnd != "" {
|
|
|
|
actx.AddDependency(ctx.module(), crtEndDepTag, deps.CrtEnd)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func depsMutator(ctx common.AndroidBottomUpMutatorContext) {
|
2016-01-04 23:34:37 +01:00
|
|
|
if c, ok := ctx.Module().(*Module); ok {
|
2015-10-29 23:25:03 +01:00
|
|
|
c.depsMutator(ctx)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 00:06:20 +02:00
|
|
|
// Convert dependencies to paths. Returns a PathDeps containing paths
|
|
|
|
func (c *Module) depsToPaths(ctx common.AndroidModuleContext) PathDeps {
|
|
|
|
var depPaths PathDeps
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
|
|
|
name := ctx.OtherModuleName(m)
|
|
|
|
tag := ctx.OtherModuleDependencyTag(m)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
a, _ := m.(common.AndroidModule)
|
|
|
|
if a == nil {
|
|
|
|
ctx.ModuleErrorf("module %q not an android module", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
c, _ := m.(*Module)
|
|
|
|
if c == nil {
|
|
|
|
if tag != common.DefaultsDepTag {
|
|
|
|
ctx.ModuleErrorf("depends on non-cc module %q", name)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if !a.Enabled() {
|
|
|
|
ctx.ModuleErrorf("depends on disabled module %q", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if a.HostOrDevice() != ctx.HostOrDevice() {
|
|
|
|
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), name)
|
|
|
|
return
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-04-22 22:07:53 +02:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if !c.outputFile.Valid() {
|
|
|
|
ctx.ModuleErrorf("module %q missing output file", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if tag == reuseObjTag {
|
|
|
|
depPaths.ObjFiles = append(depPaths.ObjFiles,
|
|
|
|
c.compiler.(*libraryCompiler).reuseObjFiles...)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02: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-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02: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-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
|
|
|
|
postfix := " (required by " + ctx.OtherModuleName(m) + ")"
|
|
|
|
for i := range missingDeps {
|
|
|
|
missingDeps[i] += postfix
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
ctx.AddMissingDependencies(missingDeps)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02: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-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return depPaths
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) InstallInData() bool {
|
|
|
|
if c.installer == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return c.installer.inData()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiler
|
|
|
|
|
|
|
|
type baseCompiler struct {
|
|
|
|
Properties BaseCompilerProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ compiler = (*baseCompiler)(nil)
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) props() []interface{} {
|
|
|
|
return []interface{}{&compiler.Properties}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) begin(ctx BaseModuleContext) {}
|
|
|
|
func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps { return deps }
|
|
|
|
|
|
|
|
// 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-22 22:07:53 +02:00
|
|
|
// Include dir cflags
|
2016-01-04 23:34:37 +01:00
|
|
|
rootIncludeDirs := common.PathsForSource(ctx, compiler.Properties.Include_dirs)
|
|
|
|
localIncludeDirs := common.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-09-24 00:26:32 +02:00
|
|
|
includeDirsToFlags(localIncludeDirs),
|
|
|
|
includeDirsToFlags(rootIncludeDirs))
|
2015-04-22 22:07:53 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
rootIncludeFiles := common.PathsForSource(ctx, compiler.Properties.Include_files)
|
|
|
|
localIncludeFiles := common.PathsForModuleSrc(ctx, compiler.Properties.Local_include_files)
|
2015-09-14 21:30:50 +02:00
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
includeFilesToFlags(rootIncludeFiles),
|
|
|
|
includeFilesToFlags(localIncludeFiles))
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if !ctx.noDefaultCompilerFlags() {
|
|
|
|
if !ctx.sdk() || ctx.Host() {
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
|
|
|
"${commonGlobalIncludes}",
|
|
|
|
toolchain.IncludeFlags(),
|
2016-01-08 02:42:34 +01:00
|
|
|
"${commonNativehelperInclude}")
|
2015-04-22 22:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, []string{
|
2015-09-24 00:26:20 +02:00
|
|
|
"-I" + common.PathForModuleSrc(ctx).String(),
|
|
|
|
"-I" + common.PathForModuleOut(ctx).String(),
|
|
|
|
"-I" + common.PathForModuleGen(ctx).String(),
|
2015-04-22 22:07:53 +02:00
|
|
|
}...)
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
instructionSet := compiler.Properties.Instruction_set
|
|
|
|
if flags.RequiredInstructionSet != "" {
|
|
|
|
instructionSet = flags.RequiredInstructionSet
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2015-11-03 23:27:00 +01: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-04 23:34:37 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, compiler.Properties.Release.Cflags...)
|
2015-11-03 23:27:00 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CFlags = clangFilterUnknownCflags(flags.CFlags)
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, compiler.Properties.Clang_cflags...)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, compiler.Properties.Clang_asflags...)
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags)
|
|
|
|
flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags)
|
|
|
|
flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
target := "-target " + toolchain.ClangTriple()
|
|
|
|
gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, target, gccPrefix)
|
|
|
|
flags.AsFlags = append(flags.AsFlags, target, gccPrefix)
|
|
|
|
flags.LdFlags = append(flags.LdFlags, target, gccPrefix)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if !ctx.noDefaultCompilerFlags() {
|
2015-04-22 02:38:44 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
2016-01-13 07:25:34 +01:00
|
|
|
flags.AsFlags = append(flags.AsFlags, toolchain.ClangAsflags())
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}")
|
2015-04-22 02:38:44 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-01-31 02:27:36 +01:00
|
|
|
toolchain.ClangCflags(),
|
|
|
|
"${commonClangGlobalCflags}",
|
2015-05-07 23:11:29 +02:00
|
|
|
fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice()))
|
2016-01-13 01:22:40 +01:00
|
|
|
|
|
|
|
flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
|
2015-04-22 02:38:44 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
2015-01-31 02:27:36 +01:00
|
|
|
toolchain.Cflags(),
|
|
|
|
"${commonGlobalCflags}",
|
2015-05-07 23:11:29 +02:00
|
|
|
fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice()))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-12-16 01:07:43 +01:00
|
|
|
if Bool(ctx.AConfig().ProductVariables.Brillo) {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__")
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2016-01-04 23:34:37 +01:00
|
|
|
if Bool(compiler.Properties.Rtti) {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "-frtti")
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags())
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags())
|
2015-04-22 22:07:53 +02:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-24 01:11:30 +01:00
|
|
|
if flags.Clang {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainClangCflags())
|
|
|
|
} else {
|
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainCflags())
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if !ctx.sdk() {
|
2015-09-12 02:41:10 +02: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-01 22:36:34 +01: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 02:27:36 +01:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags) common.Paths {
|
|
|
|
// Compile files listed in c.Properties.Srcs into objects
|
|
|
|
objFiles := compiler.compileObjs(ctx, flags, "", compiler.Properties.Srcs, compiler.Properties.Exclude_srcs)
|
|
|
|
if ctx.Failed() {
|
2015-03-18 21:28:46 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var genSrcs common.Paths
|
2015-03-18 21:28:46 +01:00
|
|
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
|
|
|
if gen, ok := module.(genrule.SourceFileGenerator); ok {
|
2016-01-04 23:34:37 +01:00
|
|
|
genSrcs = append(genSrcs, gen.GeneratedSourceFiles()...)
|
2015-03-18 21:28:46 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if len(genSrcs) != 0 {
|
|
|
|
genObjs := TransformSourceToObj(ctx, "", genSrcs, flagsToBuilderFlags(flags), nil)
|
|
|
|
objFiles = append(objFiles, genObjs...)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return objFiles
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// Compile a list of source files into objects a specified subdirectory
|
|
|
|
func (compiler *baseCompiler) compileObjs(ctx common.AndroidModuleContext, flags Flags,
|
|
|
|
subdir string, srcFiles, excludes []string) common.Paths {
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
buildFlags := flagsToBuilderFlags(flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
inputFiles := ctx.ExpandSources(srcFiles, excludes)
|
|
|
|
srcPaths, deps := genSources(ctx, inputFiles, buildFlags)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 00:06:20 +02:00
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
|
|
|
VariantIsStaticBinary bool `blueprint:"mutated"`
|
|
|
|
RunPaths []string `blueprint:"mutated"`
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 02:35:50 +02:00
|
|
|
func (linker *baseLinker) begin(ctx BaseModuleContext) {
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
2016-04-12 00:06:20 +02:00
|
|
|
linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"}
|
2016-03-31 02:35:50 +02:00
|
|
|
} else {
|
2016-04-12 00:06:20 +02:00
|
|
|
linker.dynamicProperties.RunPaths = []string{"../lib", "lib"}
|
2016-03-31 02:35:50 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (linker *baseLinker) props() []interface{} {
|
|
|
|
return []interface{}{&linker.Properties, &linker.dynamicProperties}
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
2015-04-27 20:13:34 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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-26 22:43:45 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01: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-27 20:13:34 +02:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
if ctx.sdk() {
|
|
|
|
version := ctx.sdkVersion()
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs,
|
|
|
|
"ndk_libc."+version,
|
|
|
|
"ndk_libm."+version,
|
|
|
|
)
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return deps
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (linker *baseLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
toolchain := ctx.toolchain()
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if !ctx.noDefaultCompilerFlags() {
|
|
|
|
if ctx.Device() && !Bool(linker.Properties.Allow_undefined_symbols) {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
if flags.Clang {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags())
|
2015-04-28 22:30:13 +02:00
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
|
2015-04-28 22:30:13 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
|
2015-04-28 22:30:13 +02:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 02:35:50 +02:00
|
|
|
if ctx.Host() && !linker.static() {
|
|
|
|
rpath_prefix := `\$$ORIGIN/`
|
|
|
|
if ctx.Darwin() {
|
|
|
|
rpath_prefix = "@loader_path/"
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
for _, rpath := range linker.dynamicProperties.RunPaths {
|
2016-03-31 02:35:50 +02:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 02:33:52 +02:00
|
|
|
if flags.Clang {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainClangLdflags())
|
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainLdflags())
|
2015-04-28 22:30:13 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return flags
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (linker *baseLinker) static() bool {
|
|
|
|
return linker.dynamicProperties.VariantIsStatic
|
|
|
|
}
|
2015-03-28 02:23:34 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (linker *baseLinker) staticBinary() bool {
|
|
|
|
return linker.dynamicProperties.VariantIsStaticBinary
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (linker *baseLinker) setStatic(static bool) {
|
|
|
|
linker.dynamicProperties.VariantIsStatic = static
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type baseLinkerInterface interface {
|
2015-03-26 22:43:45 +01: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-28 22:20:37 +02:00
|
|
|
setStatic(bool)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2015-04-28 22:20:37 +02:00
|
|
|
// Returns whether a specific variant is a static library or binary
|
2015-03-26 22:43:45 +01:00
|
|
|
static() bool
|
2015-04-28 22:20:37 +02:00
|
|
|
|
|
|
|
// Returns whether a module is a static binary
|
|
|
|
staticBinary() bool
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type exportedFlagsProducer interface {
|
|
|
|
exportedFlags() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type baseInstaller struct {
|
|
|
|
Properties InstallerProperties
|
|
|
|
|
|
|
|
dir string
|
|
|
|
dir64 string
|
|
|
|
data bool
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-03-24 21:14:12 +01:00
|
|
|
path common.OutputPath
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ installer = (*baseInstaller)(nil)
|
|
|
|
|
|
|
|
func (installer *baseInstaller) props() []interface{} {
|
|
|
|
return []interface{}{&installer.Properties}
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (installer *baseInstaller) inData() bool {
|
|
|
|
return installer.data
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Combined static+shared libraries
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type libraryCompiler struct {
|
|
|
|
baseCompiler
|
2015-05-11 22:39:40 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
linker *libraryLinker
|
|
|
|
Properties LibraryCompilerProperties
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// For reusing static library objects for shared library
|
2015-09-24 00:26:20 +02:00
|
|
|
reuseObjFiles common.Paths
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ compiler = (*libraryCompiler)(nil)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryCompiler) props() []interface{} {
|
|
|
|
props := library.baseCompiler.props()
|
|
|
|
return append(props, &library.Properties)
|
2015-03-24 01:50:24 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = library.baseCompiler.flags(ctx, flags)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
|
|
|
// all code is position independent, and then those warnings get promoted to
|
|
|
|
// errors.
|
|
|
|
if ctx.HostType() != common.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-fPIC")
|
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 01:50:24 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return flags
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags) common.Paths {
|
|
|
|
var objFiles common.Paths
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
objFiles = library.baseCompiler.compile(ctx, flags)
|
|
|
|
library.reuseObjFiles = objFiles
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if library.linker.static() {
|
|
|
|
objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceStaticLibrary,
|
|
|
|
library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs)...)
|
|
|
|
} else {
|
|
|
|
objFiles = append(objFiles, library.compileObjs(ctx, flags, common.DeviceSharedLibrary,
|
|
|
|
library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs)...)
|
|
|
|
}
|
2015-07-09 03:13:11 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return objFiles
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type libraryLinker struct {
|
|
|
|
baseLinker
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
Properties LibraryLinkerProperties
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
dynamicProperties struct {
|
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
exportFlags []string
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// If we're used as a whole_static_lib, our missing dependencies need
|
|
|
|
// to be given
|
|
|
|
wholeStaticMissingDeps []string
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// For whole_static_libs
|
|
|
|
objFiles common.Paths
|
2016-03-11 03:14:25 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ linker = (*libraryLinker)(nil)
|
|
|
|
var _ exportedFlagsProducer = (*libraryLinker)(nil)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) props() []interface{} {
|
|
|
|
props := library.baseLinker.props()
|
|
|
|
return append(props, &library.Properties, &library.dynamicProperties)
|
|
|
|
}
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = library.baseLinker.flags(ctx, flags)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.Nocrt = Bool(library.Properties.Nocrt)
|
2015-04-29 02:39:43 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if !library.static() {
|
2015-01-31 02:27:36 +01:00
|
|
|
libName := ctx.ModuleName()
|
|
|
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
|
|
|
sharedFlag := "-Wl,-shared"
|
2015-10-20 23:29:35 +02:00
|
|
|
if flags.Clang || ctx.Host() {
|
2015-01-31 02:27:36 +01:00
|
|
|
sharedFlag = "-shared"
|
|
|
|
}
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2016-03-04 03:05:38 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-dynamiclib",
|
|
|
|
"-single_module",
|
|
|
|
//"-read_only_relocs suppress",
|
2015-11-25 02:53:15 +01:00
|
|
|
"-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(),
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
sharedFlag,
|
2015-11-25 02:53:15 +01:00
|
|
|
"-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix(),
|
2015-05-01 01:36:18 +02:00
|
|
|
)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
|
|
|
return flags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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) exportedFlags() []string {
|
|
|
|
return library.exportFlags
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) linkStatic(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
objFiles = append(objFiles, deps.WholeStaticLibObjFiles...)
|
2016-01-04 23:34:37 +01:00
|
|
|
library.objFiles = objFiles
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
2016-01-04 23:34:37 +01:00
|
|
|
TransformDarwinObjToStaticLib(ctx, objFiles, flagsToBuilderFlags(flags), outputFile)
|
2015-05-01 01:36:18 +02:00
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
TransformObjToStaticLib(ctx, objFiles, flagsToBuilderFlags(flags), outputFile)
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return outputFile
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) linkShared(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, ctx.ModuleName()+flags.Toolchain.ShlibSuffix())
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var linkerDeps common.Paths
|
2015-07-07 02:48:31 +02:00
|
|
|
|
2016-01-04 23:34:37 +01: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-04 23:59:08 +01:00
|
|
|
if !ctx.Darwin() {
|
2015-09-24 00:26:20 +02:00
|
|
|
if versionScript.Valid() {
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
2015-09-24 00:26:20 +02:00
|
|
|
linkerDeps = append(linkerDeps, versionScript.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if unexportedSymbols.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceNotWeakSymbols.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceWeakSymbols.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-24 00:26:20 +02:00
|
|
|
if versionScript.Valid() {
|
2015-12-04 23:59:08 +01:00
|
|
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if unexportedSymbols.Valid() {
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
2015-09-24 00:26:20 +02:00
|
|
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceNotWeakSymbols.Valid() {
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
|
2015-09-24 00:26:20 +02:00
|
|
|
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-09-24 00:26:20 +02:00
|
|
|
if forceWeakSymbols.Valid() {
|
2016-01-04 23:34:37 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
|
2015-09-24 00:26:20 +02:00
|
|
|
linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
|
2015-12-04 23:59:08 +01:00
|
|
|
}
|
2015-07-07 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
sharedLibs := deps.SharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs,
|
|
|
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, flagsToBuilderFlags(flags), outputFile)
|
|
|
|
|
|
|
|
return outputFile
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var out common.Path
|
|
|
|
if library.static() {
|
|
|
|
out = library.linkStatic(ctx, flags, deps, objFiles)
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
out = library.linkShared(ctx, flags, deps, objFiles)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)
|
|
|
|
library.exportFlags = []string{includeDirsToFlags(includeDirs)}
|
|
|
|
library.exportFlags = append(library.exportFlags, deps.ReexportedCflags...)
|
|
|
|
|
|
|
|
return out
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) buildStatic() bool {
|
|
|
|
return library.dynamicProperties.BuildStatic
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) buildShared() bool {
|
|
|
|
return library.dynamicProperties.BuildShared
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) getWholeStaticMissingDeps() []string {
|
|
|
|
return library.wholeStaticMissingDeps
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
func (library *libraryLinker) installable() bool {
|
|
|
|
return !library.static()
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type libraryInstaller struct {
|
|
|
|
baseInstaller
|
|
|
|
|
|
|
|
linker *libraryLinker
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryInstaller) install(ctx ModuleContext, file common.Path) {
|
|
|
|
if !library.linker.static() {
|
|
|
|
library.baseInstaller.install(ctx, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-18 22:01:18 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
module.installer = &libraryInstaller{
|
|
|
|
baseInstaller: baseInstaller{
|
|
|
|
dir: "lib",
|
|
|
|
dir64: "lib64",
|
|
|
|
},
|
|
|
|
linker: linker,
|
|
|
|
}
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func libraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostAndDeviceSupported, true, true)
|
|
|
|
return module.Init()
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Objects (for crt*.o)
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type objectLinker struct {
|
2016-04-11 23:37:39 +02:00
|
|
|
Properties ObjectLinkerProperties
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func objectFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
module.linker = &objectLinker{}
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:37:39 +02:00
|
|
|
func (object *objectLinker) props() []interface{} {
|
|
|
|
return []interface{}{&object.Properties}
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*objectLinker) begin(ctx BaseModuleContext) {}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-11 23:37:39 +02:00
|
|
|
func (object *objectLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
|
2016-01-04 23:34:37 +01:00
|
|
|
return deps
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*objectLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
2016-03-31 02:33:52 +02:00
|
|
|
if flags.Clang {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
|
|
|
|
} else {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags())
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return flags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (object *objectLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var outputFile common.Path
|
2015-01-31 02:27:36 +01:00
|
|
|
if len(objFiles) == 1 {
|
|
|
|
outputFile = objFiles[0]
|
|
|
|
} else {
|
2015-09-24 00:26:20 +02:00
|
|
|
output := common.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
|
2016-01-04 23:34:37 +01:00
|
|
|
TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output)
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile = output
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
2016-01-04 23:34:37 +01:00
|
|
|
return outputFile
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
func (*objectLinker) installable() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Executables
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type binaryLinker struct {
|
|
|
|
baseLinker
|
2015-05-11 22:39:40 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
Properties BinaryLinkerProperties
|
2015-05-11 22:39:40 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
hostToolPath common.OptionalPath
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ linker = (*binaryLinker)(nil)
|
|
|
|
|
|
|
|
func (binary *binaryLinker) props() []interface{} {
|
|
|
|
return append(binary.baseLinker.props(), &binary.Properties)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) buildStatic() bool {
|
|
|
|
return Bool(binary.Properties.Static_executable)
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) buildShared() bool {
|
|
|
|
return !Bool(binary.Properties.Static_executable)
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) getStem(ctx BaseModuleContext) string {
|
2015-03-26 23:12:10 +01:00
|
|
|
stem := ctx.ModuleName()
|
2016-01-04 23:34:37 +01:00
|
|
|
if binary.Properties.Stem != "" {
|
|
|
|
stem = binary.Properties.Stem
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-26 23:12:10 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return stem + binary.Properties.Suffix
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps = binary.baseLinker.deps(ctx, deps)
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2016-01-04 23:34:37 +01:00
|
|
|
if !ctx.sdk() {
|
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
deps.CrtBegin = "crtbegin_static"
|
2015-04-29 03:17:56 +02:00
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
deps.CrtBegin = "crtbegin_dynamic"
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
deps.CrtEnd = "crtend_android"
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
deps.CrtBegin = "ndk_crtbegin_static." + ctx.sdkVersion()
|
2015-04-29 03:17:56 +02:00
|
|
|
} else {
|
2016-01-04 23:34:37 +01:00
|
|
|
deps.CrtBegin = "ndk_crtbegin_dynamic." + ctx.sdkVersion()
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
deps.CrtEnd = "ndk_crtend_android." + ctx.sdkVersion()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
if inList("libc++_static", deps.StaticLibs) {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
|
2015-04-28 22:30:13 +02:00
|
|
|
}
|
2015-03-26 22:43:45 +01:00
|
|
|
// static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with
|
|
|
|
// --start-group/--end-group along with libgcc. If they are in deps.StaticLibs,
|
|
|
|
// move them to the beginning of deps.LateStaticLibs
|
|
|
|
var groupLibs []string
|
2016-01-04 23:34:37 +01:00
|
|
|
deps.StaticLibs, groupLibs = filterList(deps.StaticLibs,
|
2015-03-26 22:43:45 +01:00
|
|
|
[]string{"libc", "libc_nomalloc", "libcompiler_rt"})
|
2016-01-04 23:34:37 +01:00
|
|
|
deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...)
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
func (*binaryLinker) installable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 01:50:24 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func binaryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBinary(common.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) ModifyProperties(ctx ModuleContext) {
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
2016-01-04 23:34:37 +01:00
|
|
|
binary.Properties.Static_executable = proptools.BoolPtr(false)
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
|
|
|
binary.dynamicProperties.VariantIsStaticBinary = true
|
2015-04-28 22:20:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = binary.baseLinker.flags(ctx, flags)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
if ctx.Host() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-pie")
|
|
|
|
if ctx.HostType() == common.Windows {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
|
|
|
// all code is position independent, and then those warnings get promoted to
|
|
|
|
// errors.
|
|
|
|
if ctx.HostType() != common.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-fpie")
|
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Device() {
|
2016-01-04 23:34:37 +01:00
|
|
|
if Bool(binary.Properties.Static_executable) {
|
2015-03-26 22:43:45 +01:00
|
|
|
// Clang driver needs -static to create static executable.
|
|
|
|
// However, bionic/linker uses -shared to overwrite.
|
|
|
|
// Linker for x86 targets does not allow coexistance of -static and -shared,
|
|
|
|
// so we add -static only if -shared is not used.
|
|
|
|
if !inList("-shared", flags.LdFlags) {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-static")
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-26 22:43:45 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Bstatic",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
linker := "/system/bin/linker"
|
|
|
|
if flags.Toolchain.Is64Bit() {
|
2016-01-04 23:34:37 +01:00
|
|
|
linker += "64"
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
flags.LdFlags = append(flags.LdFlags,
|
2015-12-01 23:09:48 +01:00
|
|
|
"-pie",
|
2015-03-26 22:43:45 +01:00
|
|
|
"-nostdlib",
|
|
|
|
"-Bdynamic",
|
|
|
|
fmt.Sprintf("-Wl,-dynamic-linker,%s", linker),
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,-z,nocopyreloc",
|
|
|
|
)
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
} else if ctx.Darwin() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names")
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
return flags
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
outputFile := common.PathForModuleOut(ctx, binary.getStem(ctx)+flags.Toolchain.ExecutableSuffix())
|
|
|
|
if ctx.HostOrDevice().Host() {
|
|
|
|
binary.hostToolPath = common.OptionalPathForPath(outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
ret := outputFile
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if binary.Properties.Prefix_symbols != "" {
|
2015-03-26 22:44:11 +01:00
|
|
|
afterPrefixSymbols := outputFile
|
2016-01-04 23:34:37 +01:00
|
|
|
outputFile = common.PathForModuleOut(ctx, binary.getStem(ctx)+".intermediate")
|
|
|
|
TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile,
|
|
|
|
flagsToBuilderFlags(flags), afterPrefixSymbols)
|
2015-03-26 22:44:11 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
var linkerDeps common.Paths
|
2015-07-07 02:48:31 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
sharedLibs := deps.SharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
2015-04-28 22:25:36 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs,
|
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
|
|
|
|
flagsToBuilderFlags(flags), outputFile)
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return ret
|
2015-09-17 01:00:08 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) HostToolPath() common.OptionalPath {
|
|
|
|
return binary.hostToolPath
|
2015-09-17 01:00:08 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func testPerSrcMutator(mctx common.AndroidBottomUpMutatorContext) {
|
2016-01-04 23:34:37 +01: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 01:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-11 22:39:40 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type testLinker struct {
|
|
|
|
binaryLinker
|
|
|
|
Properties TestLinkerProperties
|
2015-12-22 00:25:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 02:35:50 +02:00
|
|
|
func (test *testLinker) begin(ctx BaseModuleContext) {
|
|
|
|
test.binaryLinker.begin(ctx)
|
|
|
|
|
|
|
|
runpath := "../../lib"
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
|
|
|
runpath += "64"
|
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
test.dynamicProperties.RunPaths = append([]string{runpath}, test.dynamicProperties.RunPaths...)
|
2016-03-31 02:35:50 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (test *testLinker) props() []interface{} {
|
|
|
|
return append(test.binaryLinker.props(), &test.Properties)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = test.binaryLinker.flags(ctx, flags)
|
|
|
|
|
|
|
|
if !test.Properties.Gtest {
|
2015-12-22 00:25:58 +01:00
|
|
|
return flags
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING")
|
2015-03-24 19:13:38 +01:00
|
|
|
if ctx.Host() {
|
2015-03-24 01:50:24 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-O0", "-g")
|
2015-12-22 00:25:58 +01:00
|
|
|
|
|
|
|
if ctx.HostType() == common.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-lpthread")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID")
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(danalbert): Make gtest export its dependencies.
|
2015-04-22 22:07:53 +02:00
|
|
|
flags.CFlags = append(flags.CFlags,
|
2015-09-24 00:26:20 +02:00
|
|
|
"-I"+common.PathForSource(ctx, "external/gtest/include").String())
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-03-24 22:15:58 +01:00
|
|
|
return flags
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (test *testLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
if test.Properties.Gtest {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest")
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
deps = test.binaryLinker.deps(ctx, deps)
|
|
|
|
return deps
|
2015-12-22 00:25:58 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type testInstaller struct {
|
|
|
|
baseInstaller
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 02:48:09 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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-19 22:05:33 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func testFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewTest(common.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type benchmarkLinker struct {
|
|
|
|
binaryLinker
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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-21 23:55:28 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 00:44:20 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
return module
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func benchmarkFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBenchmark(common.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Static library
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func libraryStaticFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostAndDeviceSupported, false, true)
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Shared libraries
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func librarySharedFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostAndDeviceSupported, true, false)
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host static library
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func libraryHostStaticFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostSupported, false, true)
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host Shared libraries
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func libraryHostSharedFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewLibrary(common.HostSupported, true, false)
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host Binaries
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func binaryHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBinary(common.HostSupported)
|
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 00:09:47 +01:00
|
|
|
//
|
|
|
|
// Host Tests
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func testHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewTest(common.HostSupported)
|
|
|
|
return module.Init()
|
2015-03-27 00:09:47 +01:00
|
|
|
}
|
|
|
|
|
2015-05-08 00:44:20 +02:00
|
|
|
//
|
|
|
|
// Host Benchmarks
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func benchmarkHostFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := NewBenchmark(common.HostSupported)
|
|
|
|
return module.Init()
|
2015-05-08 00:44:20 +02:00
|
|
|
}
|
|
|
|
|
2015-11-03 01:43:11 +01:00
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
2016-01-04 23:34:37 +01:00
|
|
|
type Defaults struct {
|
2015-11-03 01:43:11 +01:00
|
|
|
common.AndroidModuleBase
|
|
|
|
common.DefaultsModule
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*Defaults) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func defaultsFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &Defaults{}
|
2015-11-03 01:43:11 +01:00
|
|
|
|
|
|
|
propertyStructs := []interface{}{
|
2016-01-04 23:34:37 +01:00
|
|
|
&BaseProperties{},
|
|
|
|
&BaseCompilerProperties{},
|
|
|
|
&BaseLinkerProperties{},
|
|
|
|
&LibraryCompilerProperties{},
|
|
|
|
&LibraryLinkerProperties{},
|
|
|
|
&BinaryLinkerProperties{},
|
|
|
|
&TestLinkerProperties{},
|
|
|
|
&UnusedProperties{},
|
|
|
|
&StlProperties{},
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2015-07-09 03:13:11 +02:00
|
|
|
_, propertyStructs = common.InitAndroidArchModule(module, common.HostAndDeviceDefault,
|
|
|
|
common.MultilibDefault, propertyStructs...)
|
2015-11-03 01:43:11 +01:00
|
|
|
|
|
|
|
return common.InitDefaultsModule(module, module, propertyStructs...)
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// Device libraries shipped with gcc
|
|
|
|
//
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type toolchainLibraryLinker struct {
|
|
|
|
baseLinker
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ baseLinkerInterface = (*toolchainLibraryLinker)(nil)
|
|
|
|
|
|
|
|
func (*toolchainLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2015-01-31 02:27:36 +01:00
|
|
|
// toolchain libraries can't have any dependencies
|
2016-01-04 23:34:37 +01:00
|
|
|
return deps
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*toolchainLibraryLinker) buildStatic() bool {
|
|
|
|
return true
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*toolchainLibraryLinker) buildShared() bool {
|
|
|
|
return false
|
|
|
|
}
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2016-01-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *toolchainLibraryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
libName := ctx.ModuleName() + staticLibraryExtension
|
2015-09-24 00:26:20 +02:00
|
|
|
outputFile := common.PathForModuleOut(ctx, libName)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-13 01:22:40 +01:00
|
|
|
if flags.Clang {
|
|
|
|
ctx.ModuleErrorf("toolchain_library must use GCC, not Clang")
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return outputFile
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
func (*toolchainLibraryLinker) installable() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-03-19 07:38:50 +01:00
|
|
|
// NDK prebuilt libraries.
|
|
|
|
//
|
|
|
|
// These differ from regular prebuilts in that they aren't stripped and usually aren't installed
|
|
|
|
// either (with the exception of the shared STLs, which are installed to the app's directory rather
|
|
|
|
// than to the system image).
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func getNdkLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, version string) common.SourcePath {
|
|
|
|
return common.PathForSource(ctx, fmt.Sprintf("prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib",
|
|
|
|
version, toolchain.Name()))
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 03:17:56 +02:00
|
|
|
func ndkPrebuiltModuleToPath(ctx common.AndroidModuleContext, toolchain Toolchain,
|
2015-09-24 00:26:20 +02:00
|
|
|
ext string, version string) common.Path {
|
2015-04-29 03:17:56 +02:00
|
|
|
|
|
|
|
// NDK prebuilts are named like: ndk_NAME.EXT.SDK_VERSION.
|
|
|
|
// We want to translate to just NAME.EXT
|
|
|
|
name := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0]
|
|
|
|
dir := getNdkLibDir(ctx, toolchain, version)
|
2015-09-24 00:26:20 +02:00
|
|
|
return dir.Join(ctx, name+ext)
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type ndkPrebuiltObjectLinker struct {
|
|
|
|
objectLinker
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*ndkPrebuiltObjectLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2015-04-29 03:17:56 +02:00
|
|
|
// NDK objects can't have any dependencies
|
2016-01-04 23:34:37 +01:00
|
|
|
return deps
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(common.DeviceSupported, common.MultilibBoth)
|
|
|
|
module.linker = &ndkPrebuiltObjectLinker{}
|
|
|
|
return module.Init()
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps, objFiles common.Paths) common.Path {
|
2015-04-29 03:17:56 +02:00
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
|
|
|
|
ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name")
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion())
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type ndkPrebuiltLibraryLinker struct {
|
|
|
|
libraryLinker
|
|
|
|
Properties struct {
|
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
|
|
|
}
|
2015-04-29 03:17:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil)
|
|
|
|
var _ exportedFlagsProducer = (*libraryLinker)(nil)
|
2015-04-29 03:17:56 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (ndk *ndkPrebuiltLibraryLinker) props() []interface{} {
|
2016-04-12 00:06:20 +02:00
|
|
|
return append(ndk.libraryLinker.props(), &ndk.Properties)
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (*ndkPrebuiltLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2015-03-19 07:38:50 +01:00
|
|
|
// NDK libraries can't have any dependencies
|
2016-01-04 23:34:37 +01:00
|
|
|
return deps
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps, objFiles common.Paths) common.Path {
|
2015-03-19 07:38:50 +01:00
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
|
|
|
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, ndk.Properties.Export_include_dirs)
|
|
|
|
ndk.exportFlags = []string{common.JoinWithPrefix(includeDirs.Strings(), "-isystem ")}
|
2015-03-19 07:38:50 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(),
|
|
|
|
ctx.sdkVersion())
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The NDK STLs are slightly different from the prebuilt system libraries:
|
|
|
|
// * Are not specific to each platform version.
|
|
|
|
// * The libraries are not in a predictable location for each STL.
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type ndkPrebuiltStlLinker struct {
|
|
|
|
ndkPrebuiltLibraryLinker
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01: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 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 00:26:20 +02:00
|
|
|
func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl string) common.SourcePath {
|
2015-03-19 07:38:50 +01:00
|
|
|
gccVersion := toolchain.GccVersion()
|
|
|
|
var libDir string
|
|
|
|
switch stl {
|
|
|
|
case "libstlport":
|
|
|
|
libDir = "cxx-stl/stlport/libs"
|
|
|
|
case "libc++":
|
|
|
|
libDir = "cxx-stl/llvm-libc++/libs"
|
|
|
|
case "libgnustl":
|
|
|
|
libDir = fmt.Sprintf("cxx-stl/gnu-libstdc++/%s/libs", gccVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
if libDir != "" {
|
2015-09-24 00:26:20 +02:00
|
|
|
ndkSrcRoot := "prebuilts/ndk/current/sources"
|
|
|
|
return common.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0])
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleErrorf("Unknown NDK STL: %s", stl)
|
2015-09-24 00:26:20 +02:00
|
|
|
return common.PathForSource(ctx, "")
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
|
|
|
deps PathDeps, objFiles common.Paths) common.Path {
|
2015-03-19 07:38:50 +01:00
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
|
|
|
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
includeDirs := common.PathsForModuleSrc(ctx, ndk.Properties.Export_include_dirs)
|
|
|
|
ndk.exportFlags = []string{includeDirsToFlags(includeDirs)}
|
2015-03-19 07:38:50 +01:00
|
|
|
|
|
|
|
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
2015-11-25 02:53:15 +01:00
|
|
|
libExt := flags.Toolchain.ShlibSuffix()
|
2016-01-04 23:34:37 +01:00
|
|
|
if ndk.dynamicProperties.BuildStatic {
|
2015-03-19 07:38:50 +01:00
|
|
|
libExt = staticLibraryExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
stlName := strings.TrimSuffix(libName, "_shared")
|
|
|
|
stlName = strings.TrimSuffix(stlName, "_static")
|
|
|
|
libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
|
2016-01-04 23:34:37 +01:00
|
|
|
return libDir.Join(ctx, libName+libExt)
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func linkageMutator(mctx common.AndroidBottomUpMutatorContext) {
|
2016-01-04 23:34:37 +01: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 00:06:20 +02: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-04 23:34:37 +01: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 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-28 22:30:13 +02:00
|
|
|
|
|
|
|
// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
|
|
|
|
// modifies the slice contents in place, and returns a subslice of the original slice
|
|
|
|
func lastUniqueElements(list []string) []string {
|
|
|
|
totalSkip := 0
|
|
|
|
for i := len(list) - 1; i >= totalSkip; i-- {
|
|
|
|
skip := 0
|
|
|
|
for j := i - 1; j >= totalSkip; j-- {
|
|
|
|
if list[i] == list[j] {
|
|
|
|
skip++
|
|
|
|
} else {
|
|
|
|
list[j+skip] = list[j]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalSkip += skip
|
|
|
|
}
|
|
|
|
return list[totalSkip:]
|
|
|
|
}
|
2015-10-29 01:23:31 +01:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|