2016-01-05 06:34:37 +08: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 (
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2016-01-05 06:34:37 +08:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StlProperties struct {
|
|
|
|
// select the STL library to use. Possible values are "libc++", "libc++_static",
|
|
|
|
// "stlport", "stlport_static", "ndk", "libstdc++", or "none". Leave blank to select the
|
|
|
|
// default
|
2016-07-13 04:12:33 +08:00
|
|
|
Stl *string
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
SelectedStl string `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
type stl struct {
|
2016-01-05 06:34:37 +08:00
|
|
|
Properties StlProperties
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) props() []interface{} {
|
2016-01-05 06:34:37 +08:00
|
|
|
return []interface{}{&stl.Properties}
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) begin(ctx BaseModuleContext) {
|
2016-01-05 06:34:37 +08:00
|
|
|
stl.Properties.SelectedStl = func() string {
|
2016-07-13 04:12:33 +08:00
|
|
|
s := ""
|
|
|
|
if stl.Properties.Stl != nil {
|
|
|
|
s = *stl.Properties.Stl
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.sdk() && ctx.Device() {
|
2016-07-13 04:12:33 +08:00
|
|
|
switch s {
|
2016-01-05 06:34:37 +08:00
|
|
|
case "":
|
|
|
|
return "ndk_system"
|
|
|
|
case "c++_shared", "c++_static",
|
|
|
|
"stlport_shared", "stlport_static",
|
|
|
|
"gnustl_static":
|
2016-07-13 04:12:33 +08:00
|
|
|
return "ndk_lib" + s
|
2016-04-22 06:53:42 +08:00
|
|
|
case "none":
|
|
|
|
return ""
|
2016-01-05 06:34:37 +08:00
|
|
|
default:
|
2016-07-13 04:12:33 +08:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", s)
|
2016-01-05 06:34:37 +08:00
|
|
|
return ""
|
|
|
|
}
|
2016-06-02 08:09:44 +08:00
|
|
|
} else if ctx.Os() == android.Windows {
|
2016-07-13 04:12:33 +08:00
|
|
|
switch s {
|
2016-01-05 06:34:37 +08:00
|
|
|
case "libc++", "libc++_static", "libstdc++", "":
|
|
|
|
// libc++ is not supported on mingw
|
|
|
|
return "libstdc++"
|
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
default:
|
2016-07-13 04:12:33 +08:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL for windows", s)
|
2016-01-05 06:34:37 +08:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
} else {
|
2016-07-13 04:12:33 +08:00
|
|
|
switch s {
|
2016-06-16 04:47:51 +08:00
|
|
|
case "libc++", "libc++_static":
|
2016-07-13 04:12:33 +08:00
|
|
|
return s
|
2016-01-05 06:34:37 +08:00
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
case "":
|
|
|
|
if ctx.static() {
|
|
|
|
return "libc++_static"
|
|
|
|
} else {
|
|
|
|
return "libc++"
|
|
|
|
}
|
|
|
|
default:
|
2016-07-13 04:12:33 +08:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL", s)
|
2016-01-05 06:34:37 +08:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-01-05 06:34:37 +08:00
|
|
|
switch stl.Properties.SelectedStl {
|
|
|
|
case "libstdc++":
|
2016-06-16 04:47:51 +08:00
|
|
|
// Nothing
|
2016-01-05 06:34:37 +08:00
|
|
|
case "libc++", "libc++_static":
|
|
|
|
if stl.Properties.SelectedStl == "libc++" {
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl)
|
|
|
|
} else {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl)
|
|
|
|
}
|
|
|
|
if ctx.Device() {
|
2016-05-19 06:37:25 +08:00
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libunwind_llvm")
|
|
|
|
}
|
|
|
|
if ctx.staticBinary() {
|
2016-07-15 06:59:32 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
|
2016-01-05 06:34:37 +08:00
|
|
|
} else {
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, "libdl")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "":
|
|
|
|
// None or error.
|
|
|
|
case "ndk_system":
|
|
|
|
// TODO: Make a system STL prebuilt for the NDK.
|
|
|
|
// The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have
|
|
|
|
// its own includes. The includes are handled in CCBase.Flags().
|
|
|
|
deps.SharedLibs = append([]string{"libstdc++"}, deps.SharedLibs...)
|
2016-09-15 07:50:48 +08:00
|
|
|
case "ndk_libc++_shared":
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl,
|
|
|
|
"libdl")
|
|
|
|
case "ndk_libc++_static":
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, "libdl")
|
|
|
|
case "ndk_libstlport_shared":
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl)
|
2016-09-15 07:50:48 +08:00
|
|
|
case "ndk_libstlport_static", "ndk_libgnustl_static":
|
2016-01-05 06:34:37 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl)
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
|
2016-01-05 06:34:37 +08:00
|
|
|
switch stl.Properties.SelectedStl {
|
|
|
|
case "libc++", "libc++_static":
|
|
|
|
flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm")
|
|
|
|
if ctx.staticBinary() {
|
2016-06-02 08:09:44 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
|
2016-01-05 06:34:37 +08:00
|
|
|
} else {
|
2016-06-02 08:09:44 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
} else {
|
2016-05-19 06:37:25 +08:00
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,libunwind_llvm.a")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "libstdc++":
|
2016-06-16 04:47:51 +08:00
|
|
|
// Nothing
|
2016-01-05 06:34:37 +08:00
|
|
|
case "ndk_system":
|
2016-05-19 06:37:25 +08:00
|
|
|
ndkSrcRoot := android.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include")
|
2016-01-05 06:34:37 +08:00
|
|
|
flags.CFlags = append(flags.CFlags, "-isystem "+ndkSrcRoot.String())
|
|
|
|
case "ndk_libc++_shared", "ndk_libc++_static":
|
|
|
|
// TODO(danalbert): This really shouldn't be here...
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-std=c++11")
|
|
|
|
case "ndk_libstlport_shared", "ndk_libstlport_static", "ndk_libgnustl_static":
|
|
|
|
// Nothing
|
|
|
|
case "":
|
|
|
|
// None or error.
|
|
|
|
if ctx.Host() {
|
|
|
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
|
|
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
|
|
|
if ctx.staticBinary() {
|
2016-06-02 08:09:44 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
|
2016-01-05 06:34:37 +08:00
|
|
|
} else {
|
2016-06-02 08:09:44 +08:00
|
|
|
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-06-02 08:09:44 +08:00
|
|
|
var hostDynamicGccLibs, hostStaticGccLibs map[android.OsType][]string
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
func init() {
|
2016-06-02 08:09:44 +08:00
|
|
|
hostDynamicGccLibs = map[android.OsType][]string{
|
2016-05-19 06:37:25 +08:00
|
|
|
android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"},
|
|
|
|
android.Darwin: []string{"-lc", "-lSystem"},
|
|
|
|
android.Windows: []string{"-lmsvcr110", "-lmingw32", "-lgcc", "-lmoldname",
|
2016-01-05 06:34:37 +08:00
|
|
|
"-lmingwex", "-lmsvcrt", "-ladvapi32", "-lshell32", "-luser32",
|
|
|
|
"-lkernel32", "-lmingw32", "-lgcc", "-lmoldname", "-lmingwex",
|
|
|
|
"-lmsvcrt"},
|
|
|
|
}
|
2016-06-02 08:09:44 +08:00
|
|
|
hostStaticGccLibs = map[android.OsType][]string{
|
2016-05-19 06:37:25 +08:00
|
|
|
android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"},
|
|
|
|
android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"},
|
|
|
|
android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"},
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
}
|