2016-07-29 21:48:20 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
|
|
|
"android/soong"
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type LibraryProperties struct {
|
2016-07-29 21:48:20 +02:00
|
|
|
Static struct {
|
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
Shared struct {
|
2016-07-30 02:28:03 +02:00
|
|
|
Srcs []string `android:"arch_variant"`
|
|
|
|
Exclude_srcs []string `android:"arch_variant"`
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
Whole_static_libs []string `android:"arch_variant"`
|
|
|
|
Static_libs []string `android:"arch_variant"`
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
|
|
|
|
// rename host libraries to prevent overlap with system installed libraries
|
|
|
|
Unique_host_soname *bool
|
|
|
|
|
|
|
|
VariantName string `blueprint:"mutated"`
|
2016-07-30 02:28:03 +02:00
|
|
|
|
|
|
|
// Build a static variant
|
|
|
|
BuildStatic bool `blueprint:"mutated"`
|
|
|
|
// Build a shared variant
|
|
|
|
BuildShared bool `blueprint:"mutated"`
|
|
|
|
// This variant is shared
|
|
|
|
VariantIsShared bool `blueprint:"mutated"`
|
|
|
|
// This variant is static
|
|
|
|
VariantIsStatic bool `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
soong.RegisterModuleType("cc_library_static", libraryStaticFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_shared", librarySharedFactory)
|
|
|
|
soong.RegisterModuleType("cc_library", libraryFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory)
|
|
|
|
soong.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for combined static + shared libraries, device by default but with possible host
|
|
|
|
// support
|
|
|
|
func libraryFactory() (blueprint.Module, []interface{}) {
|
2016-07-30 02:28:03 +02:00
|
|
|
module, _ := NewLibrary(android.HostAndDeviceSupported, true, true)
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for static libraries
|
|
|
|
func libraryStaticFactory() (blueprint.Module, []interface{}) {
|
2016-07-30 02:28:03 +02:00
|
|
|
module, _ := NewLibrary(android.HostAndDeviceSupported, false, true)
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for shared libraries
|
|
|
|
func librarySharedFactory() (blueprint.Module, []interface{}) {
|
2016-07-30 02:28:03 +02:00
|
|
|
module, _ := NewLibrary(android.HostAndDeviceSupported, true, false)
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for host static libraries
|
|
|
|
func libraryHostStaticFactory() (blueprint.Module, []interface{}) {
|
2016-07-30 02:28:03 +02:00
|
|
|
module, _ := NewLibrary(android.HostSupported, false, true)
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module factory for host shared libraries
|
|
|
|
func libraryHostSharedFactory() (blueprint.Module, []interface{}) {
|
2016-07-30 02:28:03 +02:00
|
|
|
module, _ := NewLibrary(android.HostSupported, true, false)
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
type flagExporter struct {
|
|
|
|
Properties FlagExporterProperties
|
|
|
|
|
|
|
|
flags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) {
|
|
|
|
includeDirs := android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
|
|
|
|
for _, dir := range includeDirs.Strings() {
|
|
|
|
f.flags = append(f.flags, inc+dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-30 02:28:03 +02:00
|
|
|
// libraryDecorator wraps baseCompiler, baseLinker and baseInstaller to provide library-specific
|
|
|
|
// functionality: static vs. shared linkage, reusing object files for shared libraries
|
|
|
|
type libraryDecorator struct {
|
|
|
|
Properties LibraryProperties
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// For reusing static library objects for shared library
|
|
|
|
reuseObjFiles android.Paths
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
flagExporter
|
|
|
|
stripper
|
|
|
|
|
|
|
|
// If we're used as a whole_static_lib, our missing dependencies need
|
|
|
|
// to be given
|
|
|
|
wholeStaticMissingDeps []string
|
|
|
|
|
|
|
|
// For whole_static_libs
|
|
|
|
objFiles android.Paths
|
|
|
|
|
|
|
|
// Uses the module's name if empty, but can be overridden. Does not include
|
|
|
|
// shlib suffix.
|
|
|
|
libName string
|
|
|
|
|
|
|
|
sanitize *sanitize
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
// Decorated interafaces
|
|
|
|
*baseCompiler
|
|
|
|
*baseLinker
|
|
|
|
*baseInstaller
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) linkerProps() []interface{} {
|
|
|
|
var props []interface{}
|
|
|
|
props = append(props, library.baseLinker.linkerProps()...)
|
|
|
|
return append(props,
|
|
|
|
&library.Properties,
|
|
|
|
&library.flagExporter.Properties,
|
|
|
|
&library.stripper.StripProperties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = library.baseLinker.linkerFlags(ctx, flags)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
|
|
|
|
// all code is position independent, and then those warnings get promoted to
|
|
|
|
// errors.
|
|
|
|
if ctx.Os() != android.Windows {
|
|
|
|
flags.CFlags = append(flags.CFlags, "-fPIC")
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
if library.static() {
|
2016-07-29 21:48:20 +02:00
|
|
|
flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
|
|
|
|
} else {
|
|
|
|
flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
if !library.static() {
|
|
|
|
libName := library.getLibName(ctx)
|
|
|
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
|
|
|
sharedFlag := "-Wl,-shared"
|
|
|
|
if flags.Clang || ctx.Host() {
|
|
|
|
sharedFlag = "-shared"
|
|
|
|
}
|
|
|
|
var f []string
|
|
|
|
if ctx.Device() {
|
|
|
|
f = append(f,
|
|
|
|
"-nostdlib",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Darwin() {
|
|
|
|
f = append(f,
|
|
|
|
"-dynamiclib",
|
|
|
|
"-single_module",
|
|
|
|
//"-read_only_relocs suppress",
|
|
|
|
"-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
f = append(f,
|
|
|
|
sharedFlag,
|
|
|
|
"-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix())
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.LdFlags = append(f, flags.LdFlags...)
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths {
|
2016-07-29 21:48:20 +02:00
|
|
|
var objFiles android.Paths
|
|
|
|
|
|
|
|
objFiles = library.baseCompiler.compile(ctx, flags, deps)
|
|
|
|
library.reuseObjFiles = objFiles
|
|
|
|
|
|
|
|
pathDeps := deps.GeneratedHeaders
|
|
|
|
pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
if library.static() {
|
|
|
|
objFiles = append(objFiles, compileObjs(ctx, flags, android.DeviceStaticLibrary,
|
2016-07-29 21:48:20 +02:00
|
|
|
library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs,
|
|
|
|
nil, pathDeps)...)
|
|
|
|
} else {
|
2016-07-30 02:28:03 +02:00
|
|
|
objFiles = append(objFiles, compileObjs(ctx, flags, android.DeviceSharedLibrary,
|
2016-07-29 21:48:20 +02:00
|
|
|
library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs,
|
|
|
|
nil, pathDeps)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return objFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
type libraryInterface interface {
|
|
|
|
getWholeStaticMissingDeps() []string
|
|
|
|
static() bool
|
|
|
|
objs() android.Paths
|
2016-07-30 02:28:03 +02:00
|
|
|
reuseObjs() android.Paths
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-30 02:28:03 +02: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
|
|
|
|
setStatic(bool)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
2016-07-29 21:48:20 +02:00
|
|
|
name := library.libName
|
|
|
|
if name == "" {
|
|
|
|
name = ctx.ModuleName()
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Host() && Bool(library.Properties.Unique_host_soname) {
|
|
|
|
if !strings.HasSuffix(name, "-host") {
|
|
|
|
name = name + "-host"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return name + library.Properties.VariantName
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
|
|
|
location := InstallInSystem
|
|
|
|
if library.sanitize.inData() {
|
|
|
|
location = InstallInData
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2016-07-30 02:28:03 +02:00
|
|
|
library.baseInstaller.location = location
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
library.baseLinker.linkerInit(ctx)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-08-01 22:20:05 +02:00
|
|
|
deps = library.baseLinker.linkerDeps(ctx, deps)
|
2016-07-30 02:28:03 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
if library.static() {
|
2016-07-30 02:28:03 +02:00
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs,
|
|
|
|
library.Properties.Static.Whole_static_libs...)
|
2016-07-29 21:48:20 +02:00
|
|
|
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.baseLinker.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
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) linkStatic(ctx ModuleContext,
|
2016-07-29 21:48:20 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
|
|
|
|
|
|
|
library.objFiles = append(android.Paths{}, deps.WholeStaticLibObjFiles...)
|
|
|
|
library.objFiles = append(library.objFiles, objFiles...)
|
|
|
|
|
|
|
|
outputFile := android.PathForModuleOut(ctx,
|
|
|
|
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
|
|
|
|
|
|
|
if ctx.Darwin() {
|
|
|
|
TransformDarwinObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile)
|
|
|
|
} else {
|
|
|
|
TransformObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
2016-07-29 21:48:20 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
|
|
|
|
|
|
|
var linkerDeps android.Paths
|
|
|
|
|
|
|
|
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)
|
|
|
|
if !ctx.Darwin() {
|
|
|
|
if versionScript.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
|
|
|
linkerDeps = append(linkerDeps, versionScript.Path())
|
|
|
|
}
|
|
|
|
if unexportedSymbols.Valid() {
|
|
|
|
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
if forceNotWeakSymbols.Valid() {
|
|
|
|
ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
if forceWeakSymbols.Valid() {
|
|
|
|
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if versionScript.Valid() {
|
|
|
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
|
|
}
|
|
|
|
if unexportedSymbols.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
|
|
|
}
|
|
|
|
if forceNotWeakSymbols.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
|
|
|
|
}
|
|
|
|
if forceWeakSymbols.Valid() {
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
|
|
|
|
linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
|
|
|
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
|
|
|
ret := outputFile
|
|
|
|
|
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
|
|
|
if library.stripper.needsStrip(ctx) {
|
|
|
|
strippedOutputFile := outputFile
|
|
|
|
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
|
|
|
library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
|
|
|
|
}
|
|
|
|
|
|
|
|
sharedLibs := deps.SharedLibs
|
|
|
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
|
|
|
|
|
|
|
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs,
|
|
|
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
|
|
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) link(ctx ModuleContext,
|
2016-07-29 21:48:20 +02:00
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
|
|
|
|
|
|
|
objFiles = append(objFiles, deps.ObjFiles...)
|
|
|
|
|
|
|
|
var out android.Path
|
|
|
|
if library.static() {
|
|
|
|
out = library.linkStatic(ctx, flags, deps, objFiles)
|
|
|
|
} else {
|
|
|
|
out = library.linkShared(ctx, flags, deps, objFiles)
|
|
|
|
}
|
|
|
|
|
|
|
|
library.exportIncludes(ctx, "-I")
|
|
|
|
library.reexportFlags(deps.ReexportedFlags)
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) buildStatic() bool {
|
|
|
|
return library.Properties.BuildStatic &&
|
2016-07-29 21:48:20 +02:00
|
|
|
(library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled)
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) buildShared() bool {
|
|
|
|
return library.Properties.BuildShared &&
|
2016-07-29 21:48:20 +02:00
|
|
|
(library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled)
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) getWholeStaticMissingDeps() []string {
|
2016-07-29 21:48:20 +02:00
|
|
|
return library.wholeStaticMissingDeps
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) objs() android.Paths {
|
2016-07-29 21:48:20 +02:00
|
|
|
return library.objFiles
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) reuseObjs() android.Paths {
|
|
|
|
return library.reuseObjFiles
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
|
|
|
|
if !ctx.static() {
|
2016-07-29 21:48:20 +02:00
|
|
|
library.baseInstaller.install(ctx, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) static() bool {
|
|
|
|
return library.Properties.VariantIsStatic
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (library *libraryDecorator) setStatic(static bool) {
|
|
|
|
library.Properties.VariantIsStatic = static
|
|
|
|
}
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func NewLibrary(hod android.HostOrDeviceSupported, shared, static bool) (*Module, *libraryDecorator) {
|
|
|
|
module := newModule(hod, android.MultilibBoth)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
library := &libraryDecorator{
|
|
|
|
Properties: LibraryProperties{
|
|
|
|
BuildShared: shared,
|
|
|
|
BuildStatic: static,
|
2016-07-29 21:48:20 +02:00
|
|
|
},
|
2016-07-30 02:28:03 +02:00
|
|
|
baseCompiler: NewBaseCompiler(),
|
|
|
|
baseLinker: NewBaseLinker(),
|
|
|
|
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
|
|
|
|
sanitize: module.sanitize,
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
module.compiler = library
|
|
|
|
module.linker = library
|
|
|
|
module.installer = library
|
|
|
|
|
|
|
|
return module, library
|
|
|
|
}
|
|
|
|
|
|
|
|
func linkageMutator(mctx android.BottomUpMutatorContext) {
|
|
|
|
if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
|
|
|
|
if library, ok := m.linker.(libraryInterface); ok {
|
|
|
|
var modules []blueprint.Module
|
|
|
|
if library.buildStatic() && library.buildShared() {
|
|
|
|
modules = mctx.CreateLocalVariations("static", "shared")
|
|
|
|
static := modules[0].(*Module)
|
|
|
|
shared := modules[1].(*Module)
|
|
|
|
|
|
|
|
static.linker.(libraryInterface).setStatic(true)
|
|
|
|
shared.linker.(libraryInterface).setStatic(false)
|
|
|
|
|
|
|
|
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
|
|
|
sharedCompiler := shared.compiler.(*libraryDecorator)
|
|
|
|
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
|
|
|
|
sharedCompiler.baseCompiler.Properties.Generated_sources = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if library.buildStatic() {
|
|
|
|
modules = mctx.CreateLocalVariations("static")
|
|
|
|
modules[0].(*Module).linker.(libraryInterface).setStatic(true)
|
|
|
|
} else if library.buildShared() {
|
|
|
|
modules = mctx.CreateLocalVariations("shared")
|
|
|
|
modules[0].(*Module).linker.(libraryInterface).setStatic(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|