2016-01-13 08:20:28 +01: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"
|
|
|
|
"path/filepath"
|
2016-09-15 05:29:05 +02:00
|
|
|
"sort"
|
2016-01-13 08:20:28 +01:00
|
|
|
"strings"
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2016-07-29 22:44:28 +02:00
|
|
|
"android/soong/cc/config"
|
2016-01-13 08:20:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
|
2016-01-13 08:20:28 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func makeVarsProvider(ctx android.MakeVarsContext) {
|
2016-12-15 00:50:54 +01:00
|
|
|
ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
|
2016-07-29 22:44:28 +02:00
|
|
|
ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
|
|
|
|
ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}")
|
|
|
|
ctx.Strict("LLVM_PREBUILTS_PATH", "${config.ClangBin}")
|
|
|
|
ctx.Strict("CLANG", "${config.ClangBin}/clang")
|
|
|
|
ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++")
|
|
|
|
ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as")
|
|
|
|
ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link")
|
2016-09-27 00:45:04 +02:00
|
|
|
ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
|
2016-07-29 22:44:28 +02:00
|
|
|
ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
|
|
|
|
|
|
|
|
ctx.Strict("GLOBAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}")
|
|
|
|
ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.ClangExtraNoOverrideCflags}")
|
2016-05-28 00:23:38 +02:00
|
|
|
ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "")
|
|
|
|
ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
|
2016-07-08 06:40:39 +02:00
|
|
|
ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " "))
|
2016-05-28 00:23:38 +02:00
|
|
|
|
2016-11-18 23:54:24 +01:00
|
|
|
if ctx.Config().ProductVariables.DeviceVndkVersion != nil {
|
|
|
|
ctx.Strict("BOARD_VNDK_VERSION", *ctx.Config().ProductVariables.DeviceVndkVersion)
|
|
|
|
} else {
|
|
|
|
ctx.Strict("BOARD_VNDK_VERSION", "")
|
|
|
|
}
|
|
|
|
ctx.Strict("VNDK_LIBRARIES", strings.Join(config.VndkLibraries(), " "))
|
|
|
|
|
2016-10-14 01:44:07 +02:00
|
|
|
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", asanCflags)
|
|
|
|
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", asanLdflags)
|
|
|
|
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", asanLibs)
|
|
|
|
|
2016-10-17 23:19:06 +02:00
|
|
|
ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion)
|
|
|
|
ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion)
|
|
|
|
ctx.Strict("DEFAULT_GCC_CPP_STD_VERSION", config.GccCppStdVersion)
|
|
|
|
|
2016-09-27 00:45:04 +02:00
|
|
|
ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}")
|
|
|
|
ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks))
|
|
|
|
ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}")
|
|
|
|
|
2016-11-03 22:28:51 +01:00
|
|
|
ctx.Strict("AIDL_CPP", "${aidlCmd}")
|
|
|
|
|
2016-09-15 18:30:46 +02:00
|
|
|
includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes} ${config.CommonGlobalSystemIncludes}")
|
2016-07-20 21:14:19 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
|
|
|
|
ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " "))
|
|
|
|
ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " "))
|
|
|
|
|
2016-09-15 05:29:05 +02:00
|
|
|
sort.Strings(ndkMigratedLibs)
|
2016-06-18 01:45:24 +02:00
|
|
|
ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " "))
|
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
hostTargets := ctx.Config().Targets[android.Host]
|
|
|
|
makeVarsToolchain(ctx, "", hostTargets[0])
|
|
|
|
if len(hostTargets) > 1 {
|
|
|
|
makeVarsToolchain(ctx, "2ND_", hostTargets[1])
|
2016-01-13 08:20:28 +01:00
|
|
|
}
|
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
crossTargets := ctx.Config().Targets[android.HostCross]
|
|
|
|
if len(crossTargets) > 0 {
|
|
|
|
makeVarsToolchain(ctx, "", crossTargets[0])
|
|
|
|
if len(crossTargets) > 1 {
|
|
|
|
makeVarsToolchain(ctx, "2ND_", crossTargets[1])
|
2016-01-13 08:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
deviceTargets := ctx.Config().Targets[android.Device]
|
|
|
|
makeVarsToolchain(ctx, "", deviceTargets[0])
|
|
|
|
if len(deviceTargets) > 1 {
|
|
|
|
makeVarsToolchain(ctx, "2ND_", deviceTargets[1])
|
2016-01-13 08:20:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
|
2016-06-02 02:09:44 +02:00
|
|
|
target android.Target) {
|
2016-01-13 08:20:28 +01:00
|
|
|
var typePrefix string
|
2016-06-02 02:09:44 +02:00
|
|
|
switch target.Os.Class {
|
|
|
|
case android.Host:
|
|
|
|
typePrefix = "HOST_"
|
|
|
|
case android.HostCross:
|
|
|
|
typePrefix = "HOST_CROSS_"
|
|
|
|
case android.Device:
|
2016-01-13 08:20:28 +01:00
|
|
|
typePrefix = "TARGET_"
|
|
|
|
}
|
|
|
|
makePrefix := secondPrefix + typePrefix
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
toolchain := config.FindToolchain(target.Os, target.Arch)
|
2016-01-13 08:20:28 +01:00
|
|
|
|
2016-05-18 01:35:02 +02:00
|
|
|
var productExtraCflags string
|
|
|
|
var productExtraLdflags string
|
2016-06-02 02:09:44 +02:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
hod := "Host"
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os.Class == android.Device {
|
2016-07-29 22:44:28 +02:00
|
|
|
hod = "Device"
|
2016-06-02 02:09:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if target.Os.Class == android.Device && Bool(ctx.Config().ProductVariables.Brillo) {
|
2016-05-18 01:35:02 +02:00
|
|
|
productExtraCflags += "-D__BRILLO__"
|
|
|
|
}
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) {
|
2016-05-18 01:35:02 +02:00
|
|
|
productExtraLdflags += "-static"
|
2016-05-17 04:32:33 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 01:59:04 +02:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{
|
2016-05-19 08:00:57 +02:00
|
|
|
toolchain.Cflags(),
|
2016-07-29 22:44:28 +02:00
|
|
|
"${config.CommonGlobalCflags}",
|
|
|
|
fmt.Sprintf("${config.%sGlobalCflags}", hod),
|
2016-05-19 08:00:57 +02:00
|
|
|
toolchain.ToolchainCflags(),
|
2016-05-18 01:35:02 +02:00
|
|
|
productExtraCflags,
|
2016-01-13 08:20:28 +01:00
|
|
|
}, " "))
|
2016-10-07 22:12:58 +02:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_CONLYFLAGS", strings.Join([]string{
|
|
|
|
"${config.CommonGlobalConlyflags}",
|
|
|
|
}, " "))
|
2016-05-20 01:59:04 +02:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
|
2016-07-29 22:44:28 +02:00
|
|
|
"${config.CommonGlobalCppflags}",
|
2016-05-17 08:56:53 +02:00
|
|
|
toolchain.Cppflags(),
|
|
|
|
}, " "))
|
2016-05-20 01:59:04 +02:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
|
2016-05-19 08:00:57 +02:00
|
|
|
toolchain.Ldflags(),
|
2016-01-13 08:20:28 +01:00
|
|
|
toolchain.ToolchainLdflags(),
|
2016-05-18 01:35:02 +02:00
|
|
|
productExtraLdflags,
|
2016-01-13 08:20:28 +01:00
|
|
|
}, " "))
|
2016-05-20 01:58:46 +02:00
|
|
|
|
|
|
|
includeFlags, err := ctx.Eval(toolchain.IncludeFlags())
|
2016-06-02 02:09:44 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-07-20 21:14:19 +02:00
|
|
|
includes, systemIncludes := splitSystemIncludes(ctx, includeFlags)
|
|
|
|
ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Join(includes, " "))
|
|
|
|
ctx.StrictRaw(makePrefix+"C_SYSTEM_INCLUDES", strings.Join(systemIncludes, " "))
|
2016-05-20 01:58:46 +02:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Arch.ArchType == android.Arm {
|
2016-05-20 01:58:46 +02:00
|
|
|
flags, err := toolchain.InstructionSetFlags("arm")
|
2016-06-02 02:09:44 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-05-20 01:58:46 +02:00
|
|
|
ctx.Strict(makePrefix+"arm_CFLAGS", flags)
|
|
|
|
|
|
|
|
flags, err = toolchain.InstructionSetFlags("thumb")
|
2016-06-02 02:09:44 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-05-20 01:58:46 +02:00
|
|
|
ctx.Strict(makePrefix+"thumb_CFLAGS", flags)
|
|
|
|
}
|
2016-01-13 08:20:28 +01:00
|
|
|
|
|
|
|
if toolchain.ClangSupported() {
|
|
|
|
clangPrefix := secondPrefix + "CLANG_" + typePrefix
|
2016-05-17 03:01:46 +02:00
|
|
|
clangExtras := "-target " + toolchain.ClangTriple()
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os != android.Darwin {
|
2016-05-17 03:01:46 +02:00
|
|
|
clangExtras += " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
|
|
|
|
}
|
2016-01-13 08:20:28 +01:00
|
|
|
|
2016-05-20 01:59:04 +02:00
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
|
2016-05-19 08:00:57 +02:00
|
|
|
toolchain.ClangCflags(),
|
2016-07-29 22:44:28 +02:00
|
|
|
"${config.CommonClangGlobalCflags}",
|
|
|
|
fmt.Sprintf("${config.%sClangGlobalCflags}", hod),
|
2016-05-19 08:00:57 +02:00
|
|
|
toolchain.ToolchainClangCflags(),
|
2016-01-13 08:20:28 +01:00
|
|
|
clangExtras,
|
2016-05-19 08:00:57 +02:00
|
|
|
productExtraCflags,
|
2016-01-13 08:20:28 +01:00
|
|
|
}, " "))
|
2016-05-20 01:59:04 +02:00
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
|
2016-07-29 22:44:28 +02:00
|
|
|
"${config.CommonClangGlobalCppflags}",
|
2016-05-17 08:56:53 +02:00
|
|
|
toolchain.ClangCppflags(),
|
|
|
|
}, " "))
|
2016-05-20 01:59:04 +02:00
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
|
2016-05-19 08:00:57 +02:00
|
|
|
toolchain.ClangLdflags(),
|
2016-01-13 08:20:28 +01:00
|
|
|
toolchain.ToolchainClangLdflags(),
|
2016-05-18 01:35:02 +02:00
|
|
|
productExtraLdflags,
|
2016-01-13 08:20:28 +01:00
|
|
|
clangExtras,
|
|
|
|
}, " "))
|
2016-05-20 01:58:46 +02:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os.Class == android.Device {
|
2016-08-15 23:18:24 +02:00
|
|
|
ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so"))
|
|
|
|
ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so"))
|
2016-05-20 01:58:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is used by external/gentoo/...
|
2016-06-02 02:09:44 +02:00
|
|
|
ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE",
|
2016-05-20 01:58:46 +02:00
|
|
|
toolchain.ClangTriple())
|
2016-01-13 08:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
|
|
|
|
ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
|
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os == android.Darwin {
|
2016-07-29 22:44:28 +02:00
|
|
|
ctx.Strict(makePrefix+"AR", "${config.MacArPath}")
|
2016-01-13 08:20:28 +01:00
|
|
|
} else {
|
|
|
|
ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar"))
|
|
|
|
ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
|
|
|
|
ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
|
|
|
|
}
|
2016-05-16 23:22:56 +02:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os == android.Windows {
|
2016-05-16 23:22:56 +02:00
|
|
|
ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
|
|
|
|
}
|
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
if target.Os.Class == android.Device {
|
2016-05-16 23:22:56 +02:00
|
|
|
ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
|
|
|
|
ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
|
|
|
|
ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))
|
2016-05-20 01:58:46 +02:00
|
|
|
ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion())
|
|
|
|
ctx.Strict(makePrefix+"NDK_GCC_VERSION", toolchain.GccVersion())
|
2016-06-18 01:45:24 +02:00
|
|
|
ctx.Strict(makePrefix+"NDK_TRIPLE", toolchain.ClangTriple())
|
2016-05-16 23:22:56 +02:00
|
|
|
}
|
|
|
|
|
2016-05-27 00:23:07 +02:00
|
|
|
ctx.Strict(makePrefix+"TOOLCHAIN_ROOT", toolchain.GccRoot())
|
2016-05-16 23:22:56 +02:00
|
|
|
ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
|
2016-05-20 01:58:46 +02:00
|
|
|
ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
|
|
|
|
ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix())
|
2016-01-13 08:20:28 +01:00
|
|
|
}
|
2016-07-20 21:14:19 +02:00
|
|
|
|
|
|
|
func splitSystemIncludes(ctx android.MakeVarsContext, val string) (includes, systemIncludes []string) {
|
|
|
|
flags, err := ctx.Eval(val)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
extract := func(flags string, dirs []string, prefix string) (string, []string, bool) {
|
|
|
|
if strings.HasPrefix(flags, prefix) {
|
|
|
|
flags = strings.TrimPrefix(flags, prefix)
|
|
|
|
flags = strings.TrimLeft(flags, " ")
|
|
|
|
s := strings.SplitN(flags, " ", 2)
|
|
|
|
dirs = append(dirs, s[0])
|
|
|
|
if len(s) > 1 {
|
|
|
|
return strings.TrimLeft(s[1], " "), dirs, true
|
|
|
|
}
|
|
|
|
return "", dirs, true
|
|
|
|
} else {
|
|
|
|
return flags, dirs, false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = strings.TrimLeft(flags, " ")
|
|
|
|
for flags != "" {
|
|
|
|
found := false
|
|
|
|
flags, includes, found = extract(flags, includes, "-I")
|
|
|
|
if !found {
|
|
|
|
flags, systemIncludes, found = extract(flags, systemIncludes, "-isystem ")
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
panic(fmt.Errorf("Unexpected flag in %q", flags))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return includes, systemIncludes
|
|
|
|
}
|
2016-09-27 00:45:04 +02:00
|
|
|
|
|
|
|
func joinLocalTidyChecks(checks []config.PathBasedTidyCheck) string {
|
|
|
|
rets := make([]string, len(checks))
|
|
|
|
for i, check := range config.DefaultLocalTidyChecks {
|
|
|
|
rets[i] = check.PathPrefix + ":" + check.Checks
|
|
|
|
}
|
|
|
|
return strings.Join(rets, " ")
|
|
|
|
}
|