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() {
|
2019-12-09 10:21:48 +01:00
|
|
|
android.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
|
|
|
|
android.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
|
2019-06-04 20:53:47 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:29:59 +02:00
|
|
|
// ndk_prebuilt_object exports a precompiled ndk object file for linking
|
|
|
|
// operations. Soong's module name format is ndk_<NAME>.o.<sdk_version> where
|
|
|
|
// the object is located under
|
|
|
|
// ./prebuilts/ndk/current/platforms/android-<sdk_version>/arch-$(HOST_ARCH)/usr/lib/<NAME>.o.
|
2019-12-09 10:21:48 +01:00
|
|
|
func NdkPrebuiltObjectFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
2019-05-09 14:07:34 +02:00
|
|
|
module.ModuleBase.EnableNativeBridgeSupportByDefault()
|
2016-07-30 02:28:03 +02:00
|
|
|
module.linker = &ndkPrebuiltObjectLinker{
|
|
|
|
objectLinker: objectLinker{
|
2018-07-26 23:00:24 +02:00
|
|
|
baseLinker: NewBaseLinker(nil),
|
2016-07-30 02:28:03 +02:00
|
|
|
},
|
|
|
|
}
|
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") {
|
2018-03-27 01:30:31 +02:00
|
|
|
ctx.ModuleErrorf("NDK prebuilt objects must have an ndk_crt prefixed name")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion())
|
|
|
|
}
|
|
|
|
|
2018-03-27 01:30:31 +02:00
|
|
|
type ndkPrebuiltStlLinker struct {
|
2016-07-30 02:28:03 +02:00
|
|
|
*libraryDecorator
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2018-03-27 01:30:31 +02:00
|
|
|
func (ndk *ndkPrebuiltStlLinker) 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
|
|
|
}
|
|
|
|
|
2018-03-27 01:30:31 +02:00
|
|
|
func (*ndkPrebuiltStlLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-29 21:48:20 +02:00
|
|
|
// NDK libraries can't have any dependencies
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:29:59 +02:00
|
|
|
// ndk_prebuilt_shared_stl exports a precompiled ndk shared standard template
|
|
|
|
// library (stl) library for linking operation. The soong's module name format
|
|
|
|
// is ndk_<NAME>.so where the library is located under
|
|
|
|
// ./prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/$(HOST_ARCH)/<NAME>.so.
|
2019-06-04 20:53:47 +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
|
|
|
module.compiler = nil
|
2018-03-27 01:30:31 +02:00
|
|
|
module.linker = &ndkPrebuiltStlLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
2016-07-30 02:28:03 +02:00
|
|
|
module.installer = nil
|
2017-12-14 22:23:15 +01:00
|
|
|
minVersionString := "minimum"
|
|
|
|
noStlString := "none"
|
|
|
|
module.Properties.Sdk_version = &minVersionString
|
|
|
|
module.stl.Properties.Stl = &noStlString
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:29:59 +02:00
|
|
|
// ndk_prebuilt_static_stl exports a precompiled ndk static standard template
|
|
|
|
// library (stl) library for linking operation. The soong's module name format
|
|
|
|
// is ndk_<NAME>.a where the library is located under
|
|
|
|
// ./prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/$(HOST_ARCH)/<NAME>.a.
|
2019-12-09 10:21:48 +01: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
|
|
|
module.compiler = nil
|
2018-03-27 01:30:31 +02:00
|
|
|
module.linker = &ndkPrebuiltStlLinker{
|
|
|
|
libraryDecorator: library,
|
|
|
|
}
|
2016-07-30 02:28:03 +02:00
|
|
|
module.installer = nil
|
2016-07-29 21:48:20 +02:00
|
|
|
module.Properties.HideFromMake = true
|
2019-05-09 14:07:34 +02:00
|
|
|
module.ModuleBase.EnableNativeBridgeSupportByDefault()
|
2016-07-29 21:48:20 +02:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2018-03-27 01:30:31 +02:00
|
|
|
func getNdkStlLibDir(ctx android.ModuleContext) android.SourcePath {
|
|
|
|
libDir := "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs"
|
|
|
|
return android.PathForSource(ctx, libDir).Join(ctx, ctx.Arch().Abi[0])
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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") {
|
2018-03-27 01:30:31 +02:00
|
|
|
ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 12:10:47 +02:00
|
|
|
ndk.exportIncludesAsSystem(ctx)
|
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
|
|
|
|
}
|
|
|
|
|
2018-03-27 01:30:31 +02:00
|
|
|
libDir := getNdkStlLibDir(ctx)
|
2016-07-29 21:48:20 +02:00
|
|
|
return libDir.Join(ctx, libName+libExt)
|
|
|
|
}
|