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"
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
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.
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterBottomUpMutator("link", linkageMutator)
|
|
|
|
android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
|
|
|
|
android.RegisterBottomUpMutator("deps", depsMutator)
|
2016-01-06 23:41:07 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
|
|
|
|
android.RegisterBottomUpMutator("asan", sanitizerMutator(asan))
|
2016-01-06 23:41:07 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
|
|
|
|
android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan))
|
2015-06-17 23:20:06 +02:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
var (
|
2016-05-19 00:37:25 +02:00
|
|
|
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.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
|
|
|
}
|
2016-07-08 06:40:39 +02:00
|
|
|
|
|
|
|
ndkPrebuiltSharedLibs = []string{
|
|
|
|
"android",
|
|
|
|
"c",
|
|
|
|
"dl",
|
|
|
|
"EGL",
|
|
|
|
"GLESv1_CM",
|
|
|
|
"GLESv2",
|
|
|
|
"GLESv3",
|
|
|
|
"jnigraphics",
|
|
|
|
"log",
|
|
|
|
"mediandk",
|
|
|
|
"m",
|
|
|
|
"OpenMAXAL",
|
|
|
|
"OpenSLES",
|
|
|
|
"stdc++",
|
|
|
|
"vulkan",
|
|
|
|
"z",
|
|
|
|
}
|
|
|
|
ndkPrebuiltSharedLibraries = addPrefix(append([]string(nil), ndkPrebuiltSharedLibs...), "lib")
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-06-02 02:09:44 +02:00
|
|
|
if android.BuildOs == android.Linux {
|
2016-03-30 02:31:57 +02:00
|
|
|
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) {
|
2016-05-19 00:37:25 +02:00
|
|
|
if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
2016-03-16 19:37:17 +01:00
|
|
|
return override, nil
|
|
|
|
}
|
|
|
|
return "${clangDefaultBase}", nil
|
|
|
|
})
|
|
|
|
pctx.VariableFunc("clangVersion", func(config interface{}) (string, error) {
|
2016-05-19 00:37:25 +02:00
|
|
|
if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
2016-03-16 19:37:17 +01:00
|
|
|
return override, nil
|
|
|
|
}
|
2016-04-26 23:34:07 +02:00
|
|
|
return "clang-2812033", nil
|
2016-03-16 19:37:17 +01:00
|
|
|
})
|
2016-01-06 23:41:07 +01:00
|
|
|
pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}")
|
|
|
|
pctx.StaticVariable("clangBin", "${clangPath}/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-06-07 03:22:19 +02:00
|
|
|
ReexportSharedLibHeaders, ReexportStaticLibHeaders []string
|
|
|
|
|
2016-04-11 23:37:39 +02:00
|
|
|
ObjFiles []string
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-04-20 23:21:14 +02:00
|
|
|
GeneratedSources []string
|
|
|
|
GeneratedHeaders []string
|
|
|
|
|
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 {
|
2016-05-19 00:37:25 +02:00
|
|
|
SharedLibs, LateSharedLibs android.Paths
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
ObjFiles android.Paths
|
|
|
|
WholeStaticLibObjFiles android.Paths
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
GeneratedSources android.Paths
|
|
|
|
GeneratedHeaders android.Paths
|
2016-04-20 23:21:14 +02:00
|
|
|
|
2016-07-09 09:14:08 +02:00
|
|
|
Flags, ReexportedFlags []string
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
CrtBegin, CrtEnd android.OptionalPath
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
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
|
2016-01-06 23:41:07 +01:00
|
|
|
libFlags []string // Flags to add libraries early to the link order
|
2015-04-22 22:07:53 +02:00
|
|
|
|
|
|
|
Nocrt bool
|
|
|
|
Toolchain Toolchain
|
|
|
|
Clang bool
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
RequiredInstructionSet string
|
2016-01-06 23:41:07 +01:00
|
|
|
DynamicLinker string
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
CFlagsDeps android.Paths // Files depended on by compiler flags
|
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-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
|
|
|
|
2016-04-20 23:21:14 +02:00
|
|
|
// list of generated sources to compile. These are the names of gensrcs or
|
|
|
|
// genrule modules.
|
|
|
|
Generated_sources []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of generated headers to add to the include path. These are the names
|
|
|
|
// of genrule modules.
|
|
|
|
Generated_headers []string `android:"arch_variant"`
|
|
|
|
|
2016-01-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.
|
2016-05-06 00:57:15 +02:00
|
|
|
Whole_static_libs []string `android:"arch_variant,variant_prepend"`
|
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.
|
2016-05-06 00:57:15 +02:00
|
|
|
Static_libs []string `android:"arch_variant,variant_prepend"`
|
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"`
|
2016-06-07 03:22:19 +02:00
|
|
|
|
|
|
|
// list of shared libraries to re-export include directories from. Entries must be
|
|
|
|
// present in shared_libs.
|
|
|
|
Export_shared_lib_headers []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of static libraries to re-export include directories from. Entries must be
|
|
|
|
// present in static_libs.
|
|
|
|
Export_static_lib_headers []string `android:"arch_variant"`
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LibraryCompilerProperties struct {
|
|
|
|
Static struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2016-04-06 01:42:05 +02:00
|
|
|
type FlagExporterProperties struct {
|
|
|
|
// list of directories relative to the Blueprints file that will
|
|
|
|
// be added to the include path using -I for any module that links against this module
|
|
|
|
Export_include_dirs []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type LibraryLinkerProperties struct {
|
|
|
|
Static struct {
|
2016-07-07 06:48:39 +02:00
|
|
|
Enabled *bool `android:"arch_variant"`
|
2016-01-04 23:34:37 +01:00
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
2016-07-07 06:48:39 +02:00
|
|
|
Enabled *bool `android:"arch_variant"`
|
2016-01-04 23:34:37 +01:00
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
|
|
|
// local file name to pass to the linker as --version_script
|
|
|
|
Version_script *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -unexported_symbols_list
|
|
|
|
Unexported_symbols_list *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -force_symbols_not_weak_list
|
|
|
|
Force_symbols_not_weak_list *string `android:"arch_variant"`
|
|
|
|
// local file name to pass to the linker as -force_symbols_weak_list
|
|
|
|
Force_symbols_weak_list *string `android:"arch_variant"`
|
|
|
|
|
2015-05-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-06 23:41:07 +01:00
|
|
|
|
|
|
|
VariantName string `blueprint:"mutated"`
|
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-05-25 00:39:04 +02:00
|
|
|
HideFromMake bool `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-04-28 23:50:03 +02:00
|
|
|
type StripProperties struct {
|
|
|
|
Strip struct {
|
|
|
|
None bool
|
|
|
|
Keep_symbols bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type UnusedProperties struct {
|
2016-04-16 01:27:17 +02:00
|
|
|
Native_coverage *bool
|
|
|
|
Required []string
|
|
|
|
Tags []string
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type ModuleContextIntf interface {
|
|
|
|
static() bool
|
|
|
|
staticBinary() bool
|
|
|
|
clang() bool
|
|
|
|
toolchain() Toolchain
|
|
|
|
noDefaultCompilerFlags() bool
|
|
|
|
sdk() bool
|
|
|
|
sdkVersion() string
|
2016-03-31 06:00:30 +02:00
|
|
|
selectedStl() string
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ModuleContext interface {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleContext
|
2016-01-04 23:34:37 +01:00
|
|
|
ModuleContextIntf
|
|
|
|
}
|
|
|
|
|
|
|
|
type BaseModuleContext interface {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.BaseContext
|
2016-01-04 23:34:37 +01:00
|
|
|
ModuleContextIntf
|
|
|
|
}
|
|
|
|
|
|
|
|
type Customizer interface {
|
|
|
|
CustomizeProperties(BaseModuleContext)
|
|
|
|
Properties() []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type feature interface {
|
|
|
|
begin(ctx BaseModuleContext)
|
|
|
|
deps(ctx BaseModuleContext, deps Deps) Deps
|
|
|
|
flags(ctx ModuleContext, flags Flags) Flags
|
|
|
|
props() []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type compiler interface {
|
|
|
|
feature
|
2016-05-19 00:37:25 +02:00
|
|
|
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type linker interface {
|
|
|
|
feature
|
2016-05-19 00:37:25 +02:00
|
|
|
link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
|
2016-04-12 00:06:20 +02:00
|
|
|
installable() bool
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type installer interface {
|
|
|
|
props() []interface{}
|
2016-05-19 00:37:25 +02:00
|
|
|
install(ctx ModuleContext, path android.Path)
|
2016-01-04 23:34:37 +01:00
|
|
|
inData() bool
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
library bool
|
2016-06-07 03:22:19 +02:00
|
|
|
|
|
|
|
reexportFlags bool
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2016-06-07 03:22:19 +02:00
|
|
|
sharedDepTag = dependencyTag{name: "shared", library: true}
|
|
|
|
sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
|
|
|
|
lateSharedDepTag = dependencyTag{name: "late shared", library: true}
|
|
|
|
staticDepTag = dependencyTag{name: "static", library: true}
|
|
|
|
staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
|
|
|
|
lateStaticDepTag = dependencyTag{name: "late static", library: true}
|
|
|
|
wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
|
|
|
|
genSourceDepTag = dependencyTag{name: "gen source"}
|
|
|
|
genHeaderDepTag = dependencyTag{name: "gen header"}
|
|
|
|
objDepTag = dependencyTag{name: "obj"}
|
|
|
|
crtBeginDepTag = dependencyTag{name: "crtbegin"}
|
|
|
|
crtEndDepTag = dependencyTag{name: "crtend"}
|
|
|
|
reuseObjTag = dependencyTag{name: "reuse objects"}
|
2016-04-12 00:06:20 +02:00
|
|
|
)
|
|
|
|
|
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 {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
|
|
|
android.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
|
2016-05-19 00:37:25 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
|
|
|
multilib android.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
|
2016-04-05 00:07:06 +02:00
|
|
|
stl *stl
|
2016-01-06 23:41:07 +01:00
|
|
|
sanitize *sanitize
|
|
|
|
|
|
|
|
androidMkSharedLibDeps []string
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile android.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()...)
|
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
props = append(props, c.stl.props()...)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
props = append(props, c.sanitize.props()...)
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
for _, feature := range c.features {
|
|
|
|
props = append(props, feature.props()...)
|
|
|
|
}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
_, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
return android.InitDefaultableModule(c, c, props...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type baseModuleContext struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.BaseContext
|
2016-01-04 23:34:37 +01:00
|
|
|
moduleContextImpl
|
|
|
|
}
|
2015-11-03 01:43:11 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type moduleContext struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleContext
|
2016-01-04 23:34:37 +01:00
|
|
|
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) 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 {
|
2016-06-07 21:34:45 +02:00
|
|
|
if ctx.ctx.Device() {
|
|
|
|
return ctx.mod.Properties.Sdk_version != ""
|
|
|
|
}
|
|
|
|
return false
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) sdkVersion() string {
|
2016-06-07 21:34:45 +02:00
|
|
|
if ctx.ctx.Device() {
|
|
|
|
return ctx.mod.Properties.Sdk_version
|
|
|
|
}
|
|
|
|
return ""
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 06:00:30 +02:00
|
|
|
func (ctx *moduleContextImpl) selectedStl() string {
|
|
|
|
if stl := ctx.mod.stl; stl != nil {
|
|
|
|
return stl.Properties.SelectedStl
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
|
2016-01-04 23:34:37 +01:00
|
|
|
module := newBaseModule(hod, multilib)
|
2016-04-05 00:07:06 +02:00
|
|
|
module.stl = &stl{}
|
2016-01-06 23:41:07 +01:00
|
|
|
module.sanitize = &sanitize{}
|
2016-01-04 23:34:37 +01:00
|
|
|
return module
|
|
|
|
}
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
2016-01-04 23:34:37 +01:00
|
|
|
ctx := &moduleContext{
|
2016-05-19 00:37:25 +02:00
|
|
|
ModuleContext: actx,
|
2016-01-04 23:34:37 +01:00
|
|
|
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)
|
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
flags = c.stl.flags(ctx, flags)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
flags = c.sanitize.flags(ctx, flags)
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
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-07-09 09:14:08 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var objFiles android.Paths
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.compiler != nil {
|
2016-04-20 23:21:14 +02:00
|
|
|
objFiles = c.compiler.compile(ctx, flags, deps)
|
2016-01-04 23:34:37 +01:00
|
|
|
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
|
|
|
|
}
|
2016-05-19 00:37:25 +02:00
|
|
|
c.outputFile = android.OptionalPathForPath(outputFile)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
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()
|
2016-06-02 02:09:44 +02:00
|
|
|
os := ctx.Os()
|
|
|
|
factory := toolchainFactories[os][arch.ArchType]
|
2016-01-04 23:34:37 +01:00
|
|
|
if factory == nil {
|
2016-06-02 02:09:44 +02:00
|
|
|
ctx.ModuleErrorf("Toolchain not found for %s arch %q", os.String(), arch.String())
|
2016-01-04 23:34:37 +01:00
|
|
|
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)
|
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
c.stl.begin(ctx)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
c.sanitize.begin(ctx)
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
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)
|
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
deps = c.stl.deps(ctx, deps)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
deps = c.sanitize.deps(ctx, deps)
|
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
for _, feature := range c.features {
|
|
|
|
deps = feature.deps(ctx, deps)
|
|
|
|
}
|
|
|
|
|
|
|
|
deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
|
|
|
|
deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
|
|
|
|
deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
|
|
|
|
deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
|
|
|
|
deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
|
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
for _, lib := range deps.ReexportSharedLibHeaders {
|
|
|
|
if !inList(lib, deps.SharedLibs) {
|
|
|
|
ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, lib := range deps.ReexportStaticLibHeaders {
|
|
|
|
if !inList(lib, deps.StaticLibs) {
|
|
|
|
ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
|
2016-01-04 23:34:37 +01:00
|
|
|
ctx := &baseModuleContext{
|
2016-05-19 00:37:25 +02:00
|
|
|
BaseContext: actx,
|
2016-01-04 23:34:37 +01:00
|
|
|
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-07-09 08:23:48 +02:00
|
|
|
c.Properties.AndroidMkSharedLibs = append([]string(nil), deps.SharedLibs...)
|
|
|
|
|
|
|
|
if ctx.sdk() {
|
|
|
|
version := "." + ctx.sdkVersion()
|
|
|
|
|
|
|
|
rewriteNdkLibs := func(list []string) []string {
|
|
|
|
for i, entry := range list {
|
|
|
|
if inList(entry, ndkPrebuiltSharedLibraries) {
|
|
|
|
list[i] = "ndk_" + entry + version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
deps.SharedLibs = rewriteNdkLibs(deps.SharedLibs)
|
|
|
|
deps.LateSharedLibs = rewriteNdkLibs(deps.LateSharedLibs)
|
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
|
|
|
|
deps.WholeStaticLibs...)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
for _, lib := range deps.StaticLibs {
|
|
|
|
depTag := staticDepTag
|
|
|
|
if inList(lib, deps.ReexportStaticLibHeaders) {
|
|
|
|
depTag = staticExportDepTag
|
|
|
|
}
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag,
|
|
|
|
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-06-07 03:22:19 +02:00
|
|
|
for _, lib := range deps.SharedLibs {
|
|
|
|
depTag := sharedDepTag
|
|
|
|
if inList(lib, deps.ReexportSharedLibHeaders) {
|
|
|
|
depTag = sharedExportDepTag
|
|
|
|
}
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag,
|
|
|
|
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-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
|
|
|
|
actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
|
2016-04-20 23:21:14 +02:00
|
|
|
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, objDepTag, deps.ObjFiles...)
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
if deps.CrtBegin != "" {
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
if deps.CrtEnd != "" {
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, 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
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func depsMutator(ctx android.BottomUpMutatorContext) {
|
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
|
2016-05-19 00:37:25 +02:00
|
|
|
func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
2016-04-12 00:06:20 +02:00
|
|
|
var depPaths PathDeps
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
// Whether a module can link to another module, taking into
|
|
|
|
// account NDK linking.
|
|
|
|
linkTypeOk := func(from, to *Module) bool {
|
|
|
|
if from.Target().Os != android.Android {
|
|
|
|
// Host code is not restricted
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if from.Properties.Sdk_version == "" {
|
|
|
|
// Platform code can link to anything
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if _, ok := to.linker.(*toolchainLibraryLinker); ok {
|
|
|
|
// These are always allowed
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
|
|
|
|
// These are allowed, but don't set sdk_version
|
|
|
|
return true
|
|
|
|
}
|
2016-07-08 05:41:36 +02:00
|
|
|
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
|
|
|
|
// These are allowed, but don't set sdk_version
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return to.Properties.Sdk_version != ""
|
2016-06-07 21:34:45 +02: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-05-19 00:37:25 +02:00
|
|
|
a, _ := m.(android.Module)
|
2016-04-12 00:06:20 +02:00
|
|
|
if a == nil {
|
|
|
|
ctx.ModuleErrorf("module %q not an android module", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
cc, _ := m.(*Module)
|
|
|
|
if cc == nil {
|
2016-04-20 23:21:14 +02:00
|
|
|
switch tag {
|
2016-05-19 00:37:25 +02:00
|
|
|
case android.DefaultsDepTag:
|
2016-04-20 23:21:14 +02:00
|
|
|
case genSourceDepTag:
|
|
|
|
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
|
|
|
|
depPaths.GeneratedSources = append(depPaths.GeneratedSources,
|
|
|
|
genRule.GeneratedSourceFiles()...)
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
|
|
|
|
}
|
|
|
|
case genHeaderDepTag:
|
|
|
|
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
|
|
|
|
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
|
|
|
|
genRule.GeneratedSourceFiles()...)
|
2016-07-09 09:14:08 +02:00
|
|
|
depPaths.Flags = append(depPaths.Flags,
|
2016-05-19 00:37:25 +02:00
|
|
|
includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
|
2016-04-20 23:21:14 +02:00
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q is not a genrule", name)
|
|
|
|
}
|
|
|
|
default:
|
2016-04-12 00:06:20 +02:00
|
|
|
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-06-02 02:09:44 +02:00
|
|
|
if a.Target().Os != ctx.Os() {
|
|
|
|
ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.Target().Arch.ArchType != ctx.Arch().ArchType {
|
|
|
|
ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-04-22 22:07:53 +02:00
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
if !cc.outputFile.Valid() {
|
2016-04-12 00:06:20 +02:00
|
|
|
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,
|
2016-06-07 21:34:45 +02:00
|
|
|
cc.compiler.(*libraryCompiler).reuseObjFiles...)
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
if t, ok := tag.(dependencyTag); ok && t.library {
|
2016-06-07 21:34:45 +02:00
|
|
|
if i, ok := cc.linker.(exportedFlagsProducer); ok {
|
2016-07-09 09:14:08 +02:00
|
|
|
flags := i.exportedFlags()
|
|
|
|
depPaths.Flags = append(depPaths.Flags, flags...)
|
2016-06-07 03:22:19 +02:00
|
|
|
|
|
|
|
if t.reexportFlags {
|
2016-07-09 09:14:08 +02:00
|
|
|
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
|
2016-06-07 03:22:19 +02:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
2016-06-07 21:34:45 +02:00
|
|
|
|
|
|
|
if !linkTypeOk(c, cc) {
|
|
|
|
ctx.ModuleErrorf("depends on non-NDK-built library %q", name)
|
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var depPtr *android.Paths
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
switch tag {
|
2016-06-07 03:22:19 +02:00
|
|
|
case sharedDepTag, sharedExportDepTag:
|
2016-04-12 00:06:20 +02:00
|
|
|
depPtr = &depPaths.SharedLibs
|
|
|
|
case lateSharedDepTag:
|
|
|
|
depPtr = &depPaths.LateSharedLibs
|
2016-06-07 03:22:19 +02:00
|
|
|
case staticDepTag, staticExportDepTag:
|
2016-04-12 00:06:20 +02:00
|
|
|
depPtr = &depPaths.StaticLibs
|
|
|
|
case lateStaticDepTag:
|
|
|
|
depPtr = &depPaths.LateStaticLibs
|
|
|
|
case wholeStaticDepTag:
|
|
|
|
depPtr = &depPaths.WholeStaticLibs
|
2016-06-07 21:34:45 +02:00
|
|
|
staticLib, _ := cc.linker.(*libraryLinker)
|
2016-04-12 00:06:20 +02:00
|
|
|
if staticLib == nil || !staticLib.static() {
|
2016-06-07 21:34:45 +02:00
|
|
|
ctx.ModuleErrorf("module %q not a static library", name)
|
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 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:
|
2016-06-07 21:34:45 +02:00
|
|
|
depPaths.CrtBegin = cc.outputFile
|
2016-04-12 00:06:20 +02:00
|
|
|
case crtEndDepTag:
|
2016-06-07 21:34:45 +02:00
|
|
|
depPaths.CrtEnd = cc.outputFile
|
2016-04-12 00:06:20 +02:00
|
|
|
default:
|
2016-06-07 03:22:19 +02:00
|
|
|
panic(fmt.Errorf("unknown dependency tag: %s", tag))
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if depPtr != nil {
|
2016-06-07 21:34:45 +02:00
|
|
|
*depPtr = append(*depPtr, cc.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}
|
|
|
|
}
|
|
|
|
|
2016-04-20 23:21:14 +02:00
|
|
|
func (compiler *baseCompiler) begin(ctx BaseModuleContext) {}
|
|
|
|
|
|
|
|
func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|
|
|
deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
|
|
|
|
deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
// Create a Flags struct that collects the compile flags from global values,
|
|
|
|
// per-target values, module type values, and per-module Blueprints properties
|
|
|
|
func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
toolchain := ctx.toolchain()
|
|
|
|
|
2016-05-25 23:47:21 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs)
|
|
|
|
localIncludeDirs := android.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
|
|
|
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{
|
2016-05-19 00:37:25 +02:00
|
|
|
"-I" + android.PathForModuleSrc(ctx).String(),
|
|
|
|
"-I" + android.PathForModuleOut(ctx).String(),
|
|
|
|
"-I" + android.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)
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:47:21 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags)
|
|
|
|
|
2015-11-03 23:27:00 +01:00
|
|
|
// 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 {
|
2016-05-25 23:47:21 +02:00
|
|
|
CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags)
|
|
|
|
CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags)
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
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()
|
2016-05-17 03:01:46 +02:00
|
|
|
var gccPrefix string
|
|
|
|
if !ctx.Darwin() {
|
|
|
|
gccPrefix = "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
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-06-02 02:09:44 +02:00
|
|
|
hod := "host"
|
|
|
|
if ctx.Os().Class == android.Device {
|
|
|
|
hod = "device"
|
|
|
|
}
|
|
|
|
|
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}",
|
2016-06-02 02:09:44 +02:00
|
|
|
fmt.Sprintf("${%sClangGlobalCflags}", hod))
|
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}",
|
2016-06-02 02:09:44 +02:00
|
|
|
fmt.Sprintf("${%sGlobalCflags}", hod))
|
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
|
2016-05-19 00:37:25 +02:00
|
|
|
if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") {
|
2016-03-01 22:36:34 +01:00
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths {
|
2016-01-04 23:34:37 +01:00
|
|
|
// Compile files listed in c.Properties.Srcs into objects
|
2016-04-20 23:21:14 +02:00
|
|
|
objFiles := compiler.compileObjs(ctx, flags, "",
|
|
|
|
compiler.Properties.Srcs, compiler.Properties.Exclude_srcs,
|
|
|
|
deps.GeneratedSources, deps.GeneratedHeaders)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if ctx.Failed() {
|
2015-03-18 21:28:46 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
2016-05-19 00:37:25 +02:00
|
|
|
func (compiler *baseCompiler) compileObjs(ctx android.ModuleContext, flags Flags,
|
|
|
|
subdir string, srcFiles, excludes []string, extraSrcs, deps android.Paths) android.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)
|
2016-04-20 23:21:14 +02:00
|
|
|
inputFiles = append(inputFiles, extraSrcs...)
|
|
|
|
srcPaths, gendeps := genSources(ctx, inputFiles, buildFlags)
|
|
|
|
|
|
|
|
deps = append(deps, gendeps...)
|
2016-01-06 23:41:07 +01:00
|
|
|
deps = append(deps, flags.CFlagsDeps...)
|
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...)
|
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...)
|
|
|
|
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
|
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
if !ctx.sdk() && ctx.ModuleName() != "libcompiler_rt-extras" {
|
2016-01-04 23:34:37 +01:00
|
|
|
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() {
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs,
|
2016-07-08 06:40:39 +02:00
|
|
|
"libc",
|
|
|
|
"libm",
|
2016-01-04 23:34:37 +01:00
|
|
|
)
|
|
|
|
}
|
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
|
|
|
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() {
|
2016-05-25 23:47:21 +02:00
|
|
|
CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-25 23:47:21 +02:00
|
|
|
CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags)
|
|
|
|
|
2016-05-11 02:31:21 +02:00
|
|
|
flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...)
|
|
|
|
|
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-06 23:41:07 +01:00
|
|
|
func (linker *baseLinker) isDependencyRoot() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
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
|
2016-01-06 23:41:07 +01:00
|
|
|
|
|
|
|
// Returns true for dependency roots (binaries)
|
|
|
|
// TODO(ccross): also handle dlopenable libraries
|
|
|
|
isDependencyRoot() bool
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type baseInstaller struct {
|
|
|
|
Properties InstallerProperties
|
|
|
|
|
|
|
|
dir string
|
|
|
|
dir64 string
|
|
|
|
data bool
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
path android.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-05-19 00:37:25 +02:00
|
|
|
func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
|
2016-01-04 23:34:37 +01:00
|
|
|
subDir := installer.dir
|
|
|
|
if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
|
|
|
|
subDir = installer.dir64
|
|
|
|
}
|
2016-06-01 01:27:00 +02:00
|
|
|
if !ctx.Host() && !ctx.Arch().Native {
|
|
|
|
subDir = filepath.Join(subDir, ctx.Arch().ArchType.String())
|
|
|
|
}
|
2016-05-19 00:37:25 +02:00
|
|
|
dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path)
|
2016-01-04 23:34:37 +01:00
|
|
|
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-04-06 01:42:05 +02:00
|
|
|
type flagExporter struct {
|
|
|
|
Properties FlagExporterProperties
|
|
|
|
|
|
|
|
flags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) {
|
2016-05-19 00:37:25 +02:00
|
|
|
includeDirs := android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
|
|
|
|
f.flags = append(f.flags, android.JoinWithPrefix(includeDirs.Strings(), inc))
|
2016-04-06 01:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) reexportFlags(flags []string) {
|
|
|
|
f.flags = append(f.flags, flags...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) exportedFlags() []string {
|
|
|
|
return f.flags
|
|
|
|
}
|
|
|
|
|
|
|
|
type exportedFlagsProducer interface {
|
|
|
|
exportedFlags() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ exportedFlagsProducer = (*flagExporter)(nil)
|
|
|
|
|
2016-01-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
|
2016-05-19 00:37:25 +02:00
|
|
|
reuseObjFiles android.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.
|
2016-06-02 02:09:44 +02:00
|
|
|
if ctx.Os() != android.Windows {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths {
|
|
|
|
var objFiles android.Paths
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-20 23:21:14 +02:00
|
|
|
objFiles = library.baseCompiler.compile(ctx, flags, deps)
|
2016-04-12 00:06:20 +02:00
|
|
|
library.reuseObjFiles = objFiles
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if library.linker.static() {
|
2016-05-19 00:37:25 +02:00
|
|
|
objFiles = append(objFiles, library.compileObjs(ctx, flags, android.DeviceStaticLibrary,
|
2016-04-20 23:21:14 +02:00
|
|
|
library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs,
|
|
|
|
nil, deps.GeneratedHeaders)...)
|
2016-01-04 23:34:37 +01:00
|
|
|
} else {
|
2016-05-19 00:37:25 +02:00
|
|
|
objFiles = append(objFiles, library.compileObjs(ctx, flags, android.DeviceSharedLibrary,
|
2016-04-20 23:21:14 +02:00
|
|
|
library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs,
|
|
|
|
nil, deps.GeneratedHeaders)...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
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
|
2016-04-06 01:42:05 +02:00
|
|
|
flagExporter
|
2016-04-28 23:50:03 +02:00
|
|
|
stripper
|
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
|
|
|
// 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
|
2016-05-19 00:37:25 +02:00
|
|
|
objFiles android.Paths
|
2016-03-11 03:14:25 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
var _ linker = (*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()
|
2016-04-06 01:42:05 +02:00
|
|
|
return append(props,
|
|
|
|
&library.Properties,
|
|
|
|
&library.dynamicProperties,
|
2016-04-28 23:50:03 +02:00
|
|
|
&library.flagExporter.Properties,
|
|
|
|
&library.stripper.StripProperties)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
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() {
|
2016-05-04 03:02:42 +02:00
|
|
|
libName := ctx.ModuleName() + library.Properties.VariantName
|
2015-01-31 02:27:36 +01:00
|
|
|
// 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) linkStatic(ctx ModuleContext,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
library.objFiles = append(android.Paths{}, deps.WholeStaticLibObjFiles...)
|
2016-05-12 02:25:48 +02:00
|
|
|
library.objFiles = append(library.objFiles, objFiles...)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx,
|
2016-01-06 23:41:07 +01:00
|
|
|
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
if ctx.Darwin() {
|
2016-05-12 02:25:48 +02:00
|
|
|
TransformDarwinObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile)
|
2015-05-01 01:36:18 +02:00
|
|
|
} else {
|
2016-05-12 02:25:48 +02:00
|
|
|
TransformObjToStaticLib(ctx, library.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,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var linkerDeps android.Paths
|
2015-07-07 02:48:31 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script)
|
|
|
|
unexportedSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Unexported_symbols_list)
|
|
|
|
forceNotWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_not_weak_list)
|
|
|
|
forceWeakSymbols := android.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-04-28 23:50:03 +02:00
|
|
|
fileName := ctx.ModuleName() + library.Properties.VariantName + flags.Toolchain.ShlibSuffix()
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
2016-04-28 23:50:03 +02:00
|
|
|
ret := outputFile
|
|
|
|
|
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
|
|
|
if library.stripper.needsStrip(ctx) {
|
|
|
|
strippedOutputFile := outputFile
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
2016-04-28 23:50:03 +02:00
|
|
|
library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
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,
|
2016-04-28 23:50:03 +02:00
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-28 23:50:03 +02:00
|
|
|
return ret
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) link(ctx ModuleContext,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var out android.Path
|
2016-01-04 23:34:37 +01:00
|
|
|
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-04-06 01:42:05 +02:00
|
|
|
library.exportIncludes(ctx, "-I")
|
2016-07-09 09:14:08 +02:00
|
|
|
library.reexportFlags(deps.ReexportedFlags)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
return out
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) buildStatic() bool {
|
2016-07-08 19:41:41 +02:00
|
|
|
return library.dynamicProperties.BuildStatic &&
|
|
|
|
(library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled)
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (library *libraryLinker) buildShared() bool {
|
2016-07-08 19:41:41 +02:00
|
|
|
return library.dynamicProperties.BuildShared &&
|
|
|
|
(library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
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
|
|
|
|
|
2016-05-04 03:02:42 +02:00
|
|
|
linker *libraryLinker
|
|
|
|
sanitize *sanitize
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func (library *libraryInstaller) install(ctx ModuleContext, file android.Path) {
|
2016-01-04 23:34:37 +01:00
|
|
|
if !library.linker.static() {
|
|
|
|
library.baseInstaller.install(ctx, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 03:02:42 +02:00
|
|
|
func (library *libraryInstaller) inData() bool {
|
|
|
|
return library.baseInstaller.inData() || library.sanitize.inData()
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func NewLibrary(hod android.HostOrDeviceSupported, shared, static bool) *Module {
|
|
|
|
module := newModule(hod, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
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",
|
|
|
|
},
|
2016-05-04 03:02:42 +02:00
|
|
|
linker: linker,
|
|
|
|
sanitize: module.sanitize,
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func libraryFactory() (blueprint.Module, []interface{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewLibrary(android.HostAndDeviceSupported, true, true)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
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,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.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
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var outputFile android.Path
|
2015-01-31 02:27:36 +01:00
|
|
|
if len(objFiles) == 1 {
|
|
|
|
outputFile = objFiles[0]
|
|
|
|
} else {
|
2016-05-19 00:37:25 +02:00
|
|
|
output := android.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
|
2016-04-28 23:50:03 +02:00
|
|
|
stripper
|
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-05-19 00:37:25 +02:00
|
|
|
hostToolPath android.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{} {
|
2016-04-28 23:50:03 +02:00
|
|
|
return append(binary.baseLinker.props(),
|
|
|
|
&binary.Properties,
|
|
|
|
&binary.stripper.StripProperties)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) buildStatic() bool {
|
2016-05-18 01:35:02 +02:00
|
|
|
return binary.baseLinker.staticBinary()
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (binary *binaryLinker) buildShared() bool {
|
2016-05-18 01:35:02 +02:00
|
|
|
return !binary.baseLinker.staticBinary()
|
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() {
|
2016-05-18 01:35:02 +02:00
|
|
|
if binary.buildStatic() {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-18 01:35:02 +02:00
|
|
|
if binary.buildStatic() {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-18 01:35:02 +02:00
|
|
|
if binary.buildStatic() {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-18 01:35:02 +02:00
|
|
|
if binary.buildShared() && inList("libc", deps.StaticLibs) {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-06 23:41:07 +01:00
|
|
|
func (binary *binaryLinker) isDependencyRoot() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func NewBinary(hod android.HostOrDeviceSupported) *Module {
|
|
|
|
module := newModule(hod, android.MultilibFirst)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewBinary(android.HostAndDeviceSupported)
|
2016-01-04 23:34:37 +01:00
|
|
|
return module.Init()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-05-18 01:35:02 +02:00
|
|
|
func (binary *binaryLinker) begin(ctx BaseModuleContext) {
|
|
|
|
binary.baseLinker.begin(ctx)
|
|
|
|
|
|
|
|
static := Bool(binary.Properties.Static_executable)
|
|
|
|
if ctx.Host() {
|
2016-06-02 02:09:44 +02:00
|
|
|
if ctx.Os() == android.Linux {
|
2016-05-18 01:35:02 +02:00
|
|
|
if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) {
|
|
|
|
static = true
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Static executables are not supported on Darwin or Windows
|
|
|
|
static = false
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
2016-05-18 01:35:02 +02:00
|
|
|
if static {
|
|
|
|
binary.dynamicProperties.VariantIsStatic = true
|
2016-01-04 23:34:37 +01:00
|
|
|
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
|
|
|
|
2016-05-18 01:35:02 +02:00
|
|
|
if ctx.Host() && !binary.staticBinary() {
|
2015-11-25 02:53:15 +01:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-pie")
|
2016-06-02 02:09:44 +02:00
|
|
|
if ctx.Os() == android.Windows {
|
2015-11-25 02:53:15 +01:00
|
|
|
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.
|
2016-06-02 02:09:44 +02:00
|
|
|
if ctx.Os() != android.Windows {
|
2015-11-25 02:53:15 +01:00
|
|
|
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-05-18 01:35:02 +02:00
|
|
|
if binary.buildStatic() {
|
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 {
|
2016-01-06 23:41:07 +01:00
|
|
|
if flags.DynamicLinker == "" {
|
|
|
|
flags.DynamicLinker = "/system/bin/linker"
|
|
|
|
if flags.Toolchain.Is64Bit() {
|
|
|
|
flags.DynamicLinker += "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",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,-z,nocopyreloc",
|
|
|
|
)
|
|
|
|
}
|
2016-05-18 01:35:02 +02:00
|
|
|
} else {
|
|
|
|
if binary.staticBinary() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-static")
|
|
|
|
}
|
|
|
|
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,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-28 23:50:03 +02:00
|
|
|
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
2016-04-28 23:50:03 +02:00
|
|
|
ret := outputFile
|
2016-06-02 02:09:44 +02:00
|
|
|
if ctx.Os().Class == android.Host {
|
2016-05-19 00:37:25 +02:00
|
|
|
binary.hostToolPath = android.OptionalPathForPath(outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var linkerDeps android.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-06 23:41:07 +01:00
|
|
|
if flags.DynamicLinker != "" {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, " -Wl,-dynamic-linker,"+flags.DynamicLinker)
|
|
|
|
}
|
|
|
|
|
2016-04-28 23:50:03 +02:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
|
|
|
if binary.stripper.needsStrip(ctx) {
|
|
|
|
strippedOutputFile := outputFile
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
2016-04-28 23:50:03 +02:00
|
|
|
binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
|
|
|
if binary.Properties.Prefix_symbols != "" {
|
|
|
|
afterPrefixSymbols := outputFile
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName)
|
2016-04-28 23:50:03 +02:00
|
|
|
TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile,
|
|
|
|
flagsToBuilderFlags(flags), afterPrefixSymbols)
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs,
|
|
|
|
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
|
2016-04-28 23:50:03 +02:00
|
|
|
builderFlags, 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-05-19 00:37:25 +02:00
|
|
|
func (binary *binaryLinker) HostToolPath() android.OptionalPath {
|
2016-01-04 23:34:37 +01:00
|
|
|
return binary.hostToolPath
|
2015-09-17 01:00:08 +02:00
|
|
|
}
|
|
|
|
|
2016-04-28 23:50:03 +02:00
|
|
|
type stripper struct {
|
|
|
|
StripProperties StripProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
func (stripper *stripper) needsStrip(ctx ModuleContext) bool {
|
|
|
|
return !ctx.AConfig().EmbeddedInMake() && !stripper.StripProperties.Strip.None
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func (stripper *stripper) strip(ctx ModuleContext, in, out android.ModuleOutPath,
|
2016-04-28 23:50:03 +02:00
|
|
|
flags builderFlags) {
|
2016-05-04 00:10:29 +02:00
|
|
|
if ctx.Darwin() {
|
|
|
|
TransformDarwinStrip(ctx, in, out)
|
|
|
|
} else {
|
|
|
|
flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols
|
|
|
|
// TODO(ccross): don't add gnu debuglink for user builds
|
|
|
|
flags.stripAddGnuDebuglink = true
|
|
|
|
TransformStrip(ctx, in, out, flags)
|
|
|
|
}
|
2016-04-28 23:50:03 +02:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func testPerSrcMutator(mctx android.BottomUpMutatorContext) {
|
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
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
switch ctx.Os() {
|
2016-05-19 00:37:25 +02:00
|
|
|
case android.Windows:
|
2015-12-22 00:25:58 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
|
2016-05-19 00:37:25 +02:00
|
|
|
case android.Linux:
|
2015-12-22 00:25:58 +01:00
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-lpthread")
|
2016-05-19 00:37:25 +02:00
|
|
|
case android.Darwin:
|
2016-05-13 23:13:01 +02:00
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-lpthread")
|
2015-12-22 00:25:58 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID")
|
2015-03-18 22:01:18 +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 {
|
2016-03-31 06:00:30 +02:00
|
|
|
if ctx.sdk() && ctx.Device() {
|
|
|
|
switch ctx.selectedStl() {
|
|
|
|
case "ndk_libc++_shared", "ndk_libc++_static":
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_libcxx", "libgtest_ndk_libcxx")
|
|
|
|
case "ndk_libgnustl_static":
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_gnustl", "libgtest_ndk_gnustl")
|
|
|
|
default:
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk", "libgtest_ndk")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
func (installer *testInstaller) install(ctx ModuleContext, file android.Path) {
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
func NewTest(hod android.HostOrDeviceSupported) *Module {
|
|
|
|
module := newModule(hod, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewTest(android.HostAndDeviceSupported)
|
2016-01-04 23:34:37 +01:00
|
|
|
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-05-19 00:37:25 +02:00
|
|
|
func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
|
|
|
|
module := newModule(hod, android.MultilibFirst)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewBenchmark(android.HostAndDeviceSupported)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewLibrary(android.HostAndDeviceSupported, false, true)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewLibrary(android.HostAndDeviceSupported, true, false)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewLibrary(android.HostSupported, false, true)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewLibrary(android.HostSupported, true, false)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewBinary(android.HostSupported)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewTest(android.HostSupported)
|
2016-01-04 23:34:37 +01:00
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := NewBenchmark(android.HostSupported)
|
2016-01-04 23:34:37 +01:00
|
|
|
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 {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModule
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
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{},
|
2016-04-06 01:42:05 +02:00
|
|
|
&FlagExporterProperties{},
|
2016-01-04 23:34:37 +01:00
|
|
|
&LibraryLinkerProperties{},
|
|
|
|
&BinaryLinkerProperties{},
|
|
|
|
&TestLinkerProperties{},
|
|
|
|
&UnusedProperties{},
|
|
|
|
&StlProperties{},
|
2016-01-06 23:41:07 +01:00
|
|
|
&SanitizeProperties{},
|
2016-04-28 23:50:03 +02:00
|
|
|
&StripProperties{},
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
_, propertyStructs = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
|
|
|
|
android.MultilibDefault, propertyStructs...)
|
2015-11-03 01:43:11 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
return android.InitDefaultsModule(module, module, propertyStructs...)
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
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,
|
2016-05-19 00:37:25 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
libName := ctx.ModuleName() + staticLibraryExtension
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile := android.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).
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func getNdkLibDir(ctx android.ModuleContext, toolchain Toolchain, version string) android.SourcePath {
|
2016-05-17 22:15:15 +02:00
|
|
|
suffix := ""
|
|
|
|
// Most 64-bit NDK prebuilts store libraries in "lib64", except for arm64 which is not a
|
|
|
|
// multilib toolchain and stores the libraries in "lib".
|
2016-05-19 00:37:25 +02:00
|
|
|
if toolchain.Is64Bit() && ctx.Arch().ArchType != android.Arm64 {
|
2016-05-17 22:15:15 +02:00
|
|
|
suffix = "64"
|
|
|
|
}
|
2016-05-19 00:37:25 +02:00
|
|
|
return android.PathForSource(ctx, fmt.Sprintf("prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib%s",
|
2016-05-17 22:15:15 +02:00
|
|
|
version, toolchain.Name(), suffix))
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func ndkPrebuiltModuleToPath(ctx android.ModuleContext, toolchain Toolchain,
|
|
|
|
ext string, version string) android.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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
module.linker = &ndkPrebuiltObjectLinker{}
|
2016-07-09 08:23:48 +02:00
|
|
|
module.Properties.HideFromMake = true
|
2016-01-04 23:34:37 +01:00
|
|
|
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,
|
2016-05-19 00:37:25 +02:00
|
|
|
deps PathDeps, objFiles android.Paths) android.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
|
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-06 01:42:05 +02:00
|
|
|
return append(ndk.libraryLinker.props(), &ndk.Properties, &ndk.flagExporter.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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
linker := &ndkPrebuiltLibraryLinker{}
|
|
|
|
linker.dynamicProperties.BuildShared = true
|
|
|
|
module.linker = linker
|
2016-07-09 08:23:48 +02:00
|
|
|
module.Properties.HideFromMake = true
|
2016-01-04 23:34:37 +01:00
|
|
|
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,
|
2016-05-19 00:37:25 +02:00
|
|
|
deps PathDeps, objFiles android.Paths) android.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-04-06 01:42:05 +02:00
|
|
|
ndk.exportIncludes(ctx, "-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{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
linker := &ndkPrebuiltStlLinker{}
|
|
|
|
linker.dynamicProperties.BuildShared = true
|
|
|
|
module.linker = linker
|
2016-07-09 08:23:48 +02:00
|
|
|
module.Properties.HideFromMake = true
|
2016-01-04 23:34:37 +01:00
|
|
|
return module.Init()
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func ndkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) {
|
2016-05-19 00:37:25 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-01-04 23:34:37 +01:00
|
|
|
linker := &ndkPrebuiltStlLinker{}
|
|
|
|
linker.dynamicProperties.BuildStatic = true
|
|
|
|
module.linker = linker
|
2016-07-09 08:23:48 +02:00
|
|
|
module.Properties.HideFromMake = true
|
2016-01-04 23:34:37 +01:00
|
|
|
return module.Init()
|
2015-03-19 07:38:50 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func getNdkStlLibDir(ctx android.ModuleContext, toolchain Toolchain, stl string) android.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"
|
2016-05-19 00:37:25 +02:00
|
|
|
return android.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)
|
2016-05-19 00:37:25 +02:00
|
|
|
return android.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,
|
2016-05-19 00:37:25 +02:00
|
|
|
deps PathDeps, objFiles android.Paths) android.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-04-06 01:42:05 +02:00
|
|
|
ndk.exportIncludes(ctx, "-I")
|
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
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func linkageMutator(mctx android.BottomUpMutatorContext) {
|
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
|