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 (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2016-07-29 22:44:28 +02:00
|
|
|
"android/soong/cc/config"
|
2016-07-29 21:48:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-10-12 23:28:16 +02:00
|
|
|
android.RegisterModuleType("ndk_prebuilt_library", ndkPrebuiltLibraryFactory)
|
|
|
|
android.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory)
|
|
|
|
android.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory)
|
|
|
|
android.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory)
|
2016-07-29 21:48:20 +02: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-07-29 22:44:28 +02:00
|
|
|
func getNdkLibDir(ctx android.ModuleContext, toolchain config.Toolchain, version string) android.SourcePath {
|
2016-07-29 21:48:20 +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".
|
|
|
|
if toolchain.Is64Bit() && ctx.Arch().ArchType != android.Arm64 {
|
|
|
|
suffix = "64"
|
|
|
|
}
|
|
|
|
return android.PathForSource(ctx, fmt.Sprintf("prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib%s",
|
|
|
|
version, toolchain.Name(), suffix))
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func ndkPrebuiltModuleToPath(ctx android.ModuleContext, toolchain config.Toolchain,
|
2016-07-29 21:48:20 +02:00
|
|
|
ext string, version string) android.Path {
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
return dir.Join(ctx, name+ext)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ndkPrebuiltObjectLinker struct {
|
|
|
|
objectLinker
|
|
|
|
}
|
|
|
|
|
2016-12-14 02:06:13 +01:00
|
|
|
func (*ndkPrebuiltObjectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-29 21:48:20 +02:00
|
|
|
// NDK objects can't have any dependencies
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func ndkPrebuiltObjectFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2016-07-30 02:28:03 +02:00
|
|
|
module.linker = &ndkPrebuiltObjectLinker{
|
|
|
|
objectLinker: objectLinker{
|
|
|
|
baseLinker: NewBaseLinker(),
|
|
|
|
},
|
|
|
|
}
|
2016-07-29 21:48:20 +02:00
|
|
|
module.Properties.HideFromMake = true
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
|
2016-09-27 02:33:01 +02:00
|
|
|
deps PathDeps, objs Objects) android.Path {
|
2016-07-29 21:48:20 +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")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion())
|
|
|
|
}
|
|
|
|
|
|
|
|
type ndkPrebuiltLibraryLinker struct {
|
2016-07-30 02:28:03 +02:00
|
|
|
*libraryDecorator
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 22:20:05 +02:00
|
|
|
func (ndk *ndkPrebuiltLibraryLinker) linkerProps() []interface{} {
|
2016-07-30 02:28:03 +02:00
|
|
|
return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-12-14 02:06:13 +01:00
|
|
|
func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-29 21:48:20 +02:00
|
|
|
// NDK libraries can't have any dependencies
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func ndkPrebuiltLibraryFactory() android.Module {
|
2016-12-09 23:46:15 +01:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
2016-07-30 02:28:03 +02:00
|
|
|
linker := &ndkPrebuiltLibraryLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
|
|
|
module.compiler = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.linker = linker
|
2016-07-30 02:28:03 +02:00
|
|
|
module.installer = nil
|
|
|
|
module.stl = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.Properties.HideFromMake = true
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags,
|
2016-09-27 02:33:01 +02:00
|
|
|
deps PathDeps, objs Objects) android.Path {
|
2016-07-29 21:48:20 +02:00
|
|
|
// A null build step, but it sets up the output path.
|
|
|
|
ndk.exportIncludes(ctx, "-isystem")
|
|
|
|
|
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(),
|
|
|
|
ctx.sdkVersion())
|
|
|
|
}
|
|
|
|
|
|
|
|
// The NDK STLs are slightly different from the prebuilt system libraries:
|
|
|
|
// * Are not specific to each platform version.
|
|
|
|
// * The libraries are not in a predictable location for each STL.
|
|
|
|
|
|
|
|
type ndkPrebuiltStlLinker struct {
|
|
|
|
ndkPrebuiltLibraryLinker
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func ndkPrebuiltSharedStlFactory() android.Module {
|
2016-12-09 23:46:15 +01:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.BuildOnlyShared()
|
2016-07-30 02:28:03 +02:00
|
|
|
linker := &ndkPrebuiltStlLinker{
|
|
|
|
ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
module.compiler = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.linker = linker
|
2016-07-30 02:28:03 +02:00
|
|
|
module.installer = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.Properties.HideFromMake = true
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
func ndkPrebuiltStaticStlFactory() android.Module {
|
2016-12-09 23:46:15 +01:00
|
|
|
module, library := NewLibrary(android.DeviceSupported)
|
|
|
|
library.BuildOnlyStatic()
|
2016-07-30 02:28:03 +02:00
|
|
|
linker := &ndkPrebuiltStlLinker{
|
|
|
|
ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
module.compiler = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.linker = linker
|
2016-07-30 02:28:03 +02:00
|
|
|
module.installer = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.Properties.HideFromMake = true
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func getNdkStlLibDir(ctx android.ModuleContext, toolchain config.Toolchain, stl string) android.SourcePath {
|
2016-07-29 21:48:20 +02: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 != "" {
|
|
|
|
ndkSrcRoot := "prebuilts/ndk/current/sources"
|
|
|
|
return android.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleErrorf("Unknown NDK STL: %s", stl)
|
|
|
|
return android.PathForSource(ctx, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
2016-09-27 02:33:01 +02:00
|
|
|
deps PathDeps, objs Objects) android.Path {
|
2016-07-29 21:48:20 +02: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")
|
|
|
|
}
|
|
|
|
|
2017-05-05 22:37:59 +02:00
|
|
|
ndk.exportIncludes(ctx, "-isystem")
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
|
|
|
libExt := flags.Toolchain.ShlibSuffix()
|
2017-02-15 00:28:44 +01:00
|
|
|
if ndk.static() {
|
2016-07-29 21:48:20 +02:00
|
|
|
libExt = staticLibraryExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
stlName := strings.TrimSuffix(libName, "_shared")
|
|
|
|
stlName = strings.TrimSuffix(stlName, "_static")
|
|
|
|
libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName)
|
|
|
|
return libDir.Join(ctx, libName+libExt)
|
|
|
|
}
|