From 97704edd5d9dcaa9874ab6b1cb9976eebc6eede8 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Thu, 7 Jul 2016 21:40:39 -0700 Subject: [PATCH] Support linking against NDK prebuilt libraries When sdk_version is specified, we need to use the prebuilt ndk versions of these libraries instead of the platform versions. Change-Id: I4ff33a234a985041ebe11ab148d64d0f8df66fc4 --- cc/cc.go | 41 ++++++++++++++++++++++++++++++++++++++--- cc/makevars.go | 1 + 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index dd9a83184..15b8cb721 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -115,6 +115,26 @@ var ( illegalFlags = []string{ "-w", } + + 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") ) func init() { @@ -800,6 +820,22 @@ func (c *Module) deps(ctx BaseModuleContext) Deps { deps.SharedLibs = lastUniqueElements(deps.SharedLibs) deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs) + 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) + } + for _, lib := range deps.ReexportSharedLibHeaders { if !inList(lib, deps.SharedLibs) { ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) @@ -1320,10 +1356,9 @@ func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps { } if ctx.sdk() { - version := ctx.sdkVersion() deps.SharedLibs = append(deps.SharedLibs, - "ndk_libc."+version, - "ndk_libm."+version, + "libc", + "libm", ) } } diff --git a/cc/makevars.go b/cc/makevars.go index f2214a27b..a4fe0770e 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -40,6 +40,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${clangExtraNoOverrideCflags}") ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") + ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " ")) hostTargets := ctx.Config().Targets[android.Host] makeVarsToolchain(ctx, "", hostTargets[0])