2016-01-13 15:20:28 +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 (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2016-01-13 15:20:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-05-19 06:37:25 +08:00
|
|
|
android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
|
2016-01-13 15:20:28 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func makeVarsProvider(ctx android.MakeVarsContext) {
|
2016-01-13 15:20:28 +08:00
|
|
|
ctx.Strict("LLVM_PREBUILTS_VERSION", "${clangVersion}")
|
|
|
|
ctx.Strict("LLVM_PREBUILTS_BASE", "${clangBase}")
|
2016-05-17 05:22:56 +08:00
|
|
|
ctx.Strict("LLVM_PREBUILTS_PATH", "${clangBin}")
|
|
|
|
ctx.Strict("CLANG", "${clangBin}/clang")
|
|
|
|
ctx.Strict("CLANG_CXX", "${clangBin}/clang++")
|
|
|
|
ctx.Strict("LLVM_AS", "${clangBin}/llvm-as")
|
|
|
|
ctx.Strict("LLVM_LINK", "${clangBin}/llvm-link")
|
2016-05-20 07:57:11 +08:00
|
|
|
ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(clangUnknownCflags, " "))
|
2016-01-13 15:20:28 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
hostType := android.CurrentHostType()
|
2016-01-13 15:20:28 +08:00
|
|
|
arches := ctx.Config().HostArches[hostType]
|
2016-05-19 06:37:25 +08:00
|
|
|
makeVarsToolchain(ctx, "", android.Host, hostType, arches[0])
|
2016-01-13 15:20:28 +08:00
|
|
|
if len(arches) > 1 {
|
2016-05-19 06:37:25 +08:00
|
|
|
makeVarsToolchain(ctx, "2ND_", android.Host, hostType, arches[1])
|
2016-01-13 15:20:28 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
if winArches, ok := ctx.Config().HostArches[android.Windows]; ok {
|
|
|
|
makeVarsToolchain(ctx, "", android.Host, android.Windows, winArches[0])
|
2016-01-13 15:20:28 +08:00
|
|
|
if len(winArches) > 1 {
|
2016-05-19 06:37:25 +08:00
|
|
|
makeVarsToolchain(ctx, "2ND_", android.Host, android.Windows, winArches[1])
|
2016-01-13 15:20:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
arches = ctx.Config().DeviceArches
|
2016-05-19 06:37:25 +08:00
|
|
|
makeVarsToolchain(ctx, "", android.Device, android.NoHostType, arches[0])
|
2016-01-13 15:20:28 +08:00
|
|
|
if len(arches) > 1 {
|
2016-05-19 06:37:25 +08:00
|
|
|
makeVarsToolchain(ctx, "2ND_", android.Device, android.NoHostType, arches[1])
|
2016-01-13 15:20:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
|
|
|
|
hod android.HostOrDevice, ht android.HostType, arch android.Arch) {
|
2016-01-13 15:20:28 +08:00
|
|
|
var typePrefix string
|
|
|
|
if hod.Host() {
|
2016-05-19 06:37:25 +08:00
|
|
|
if ht == android.Windows {
|
2016-01-13 15:20:28 +08:00
|
|
|
typePrefix = "HOST_CROSS_"
|
|
|
|
} else {
|
|
|
|
typePrefix = "HOST_"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
typePrefix = "TARGET_"
|
|
|
|
}
|
|
|
|
makePrefix := secondPrefix + typePrefix
|
|
|
|
|
|
|
|
toolchain := toolchainFactories[hod][ht][arch.ArchType](arch)
|
|
|
|
|
2016-05-18 07:35:02 +08:00
|
|
|
var productExtraCflags string
|
|
|
|
var productExtraLdflags string
|
2016-05-17 10:32:33 +08:00
|
|
|
if hod.Device() && Bool(ctx.Config().ProductVariables.Brillo) {
|
2016-05-18 07:35:02 +08:00
|
|
|
productExtraCflags += "-D__BRILLO__"
|
|
|
|
}
|
|
|
|
if hod.Host() && Bool(ctx.Config().ProductVariables.HostStaticBinaries) {
|
|
|
|
productExtraLdflags += "-static"
|
2016-05-17 10:32:33 +08:00
|
|
|
}
|
|
|
|
|
2016-05-20 07:59:04 +08:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_CFLAGS", strings.Join([]string{
|
2016-05-19 14:00:57 +08:00
|
|
|
toolchain.Cflags(),
|
2016-05-18 07:35:02 +08:00
|
|
|
"${commonGlobalCflags}",
|
|
|
|
fmt.Sprintf("${%sGlobalCflags}", hod),
|
2016-05-19 14:00:57 +08:00
|
|
|
toolchain.ToolchainCflags(),
|
2016-05-18 07:35:02 +08:00
|
|
|
productExtraCflags,
|
2016-01-13 15:20:28 +08:00
|
|
|
}, " "))
|
2016-05-20 07:59:04 +08:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_CONLYFLAGS", "")
|
|
|
|
ctx.Strict(makePrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
|
2016-05-17 14:56:53 +08:00
|
|
|
"${commonGlobalCppflags}",
|
|
|
|
toolchain.Cppflags(),
|
|
|
|
}, " "))
|
2016-05-20 07:59:04 +08:00
|
|
|
ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
|
2016-05-19 14:00:57 +08:00
|
|
|
toolchain.Ldflags(),
|
2016-01-13 15:20:28 +08:00
|
|
|
toolchain.ToolchainLdflags(),
|
2016-05-18 07:35:02 +08:00
|
|
|
productExtraLdflags,
|
2016-01-13 15:20:28 +08:00
|
|
|
}, " "))
|
2016-05-20 07:58:46 +08:00
|
|
|
ctx.Strict(makePrefix+"SYSTEMCPP_CPPFLAGS", toolchain.SystemCppCppflags())
|
|
|
|
ctx.Strict(makePrefix+"SYSTEMCPP_LDFLAGS", toolchain.SystemCppLdflags())
|
|
|
|
|
|
|
|
includeFlags, err := ctx.Eval(toolchain.IncludeFlags())
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Replace(includeFlags, "-isystem ", "", -1))
|
|
|
|
|
|
|
|
if arch.ArchType == android.Arm {
|
|
|
|
flags, err := toolchain.InstructionSetFlags("arm")
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
ctx.Strict(makePrefix+"arm_CFLAGS", flags)
|
|
|
|
|
|
|
|
flags, err = toolchain.InstructionSetFlags("thumb")
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
ctx.Strict(makePrefix+"thumb_CFLAGS", flags)
|
|
|
|
}
|
2016-01-13 15:20:28 +08:00
|
|
|
|
|
|
|
if toolchain.ClangSupported() {
|
|
|
|
clangPrefix := secondPrefix + "CLANG_" + typePrefix
|
2016-05-17 09:01:46 +08:00
|
|
|
clangExtras := "-target " + toolchain.ClangTriple()
|
2016-05-19 06:37:25 +08:00
|
|
|
if ht != android.Darwin {
|
2016-05-17 09:01:46 +08:00
|
|
|
clangExtras += " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
|
|
|
|
}
|
2016-01-13 15:20:28 +08:00
|
|
|
|
2016-05-20 07:59:04 +08:00
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
|
2016-05-19 14:00:57 +08:00
|
|
|
toolchain.ClangCflags(),
|
2016-05-18 07:35:02 +08:00
|
|
|
"${commonClangGlobalCflags}",
|
|
|
|
fmt.Sprintf("${%sClangGlobalCflags}", hod),
|
2016-05-19 14:00:57 +08:00
|
|
|
toolchain.ToolchainClangCflags(),
|
2016-01-13 15:20:28 +08:00
|
|
|
clangExtras,
|
2016-05-19 14:00:57 +08:00
|
|
|
productExtraCflags,
|
2016-01-13 15:20:28 +08:00
|
|
|
}, " "))
|
2016-05-20 07:59:04 +08:00
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_CONLYFLAGS", "${clangExtraConlyflags}")
|
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_CPPFLAGS", strings.Join([]string{
|
2016-05-17 14:56:53 +08:00
|
|
|
"${commonClangGlobalCppflags}",
|
|
|
|
toolchain.ClangCppflags(),
|
|
|
|
}, " "))
|
2016-05-20 07:59:04 +08:00
|
|
|
ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
|
2016-05-19 14:00:57 +08:00
|
|
|
toolchain.ClangLdflags(),
|
2016-01-13 15:20:28 +08:00
|
|
|
toolchain.ToolchainClangLdflags(),
|
2016-05-18 07:35:02 +08:00
|
|
|
productExtraLdflags,
|
2016-01-13 15:20:28 +08:00
|
|
|
clangExtras,
|
|
|
|
}, " "))
|
2016-05-20 07:58:46 +08:00
|
|
|
|
|
|
|
if hod.Device() {
|
|
|
|
ctx.Strict(secondPrefix + "ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(toolchain.AddressSanitizerRuntimeLibrary(), ".so"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is used by external/gentoo/...
|
|
|
|
ctx.Strict("CLANG_CONFIG_" + arch.ArchType.Name + "_" + typePrefix + "TRIPLE",
|
|
|
|
toolchain.ClangTriple())
|
2016-01-13 15:20:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
|
|
|
|
ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
if ht == android.Darwin {
|
2016-01-13 15:20:28 +08:00
|
|
|
ctx.Strict(makePrefix+"AR", "${macArPath}")
|
|
|
|
} else {
|
|
|
|
ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar"))
|
|
|
|
ctx.Strict(makePrefix+"READELF", gccCmd(toolchain, "readelf"))
|
|
|
|
ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
|
|
|
|
}
|
2016-05-17 05:22:56 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
if ht == android.Windows {
|
2016-05-17 05:22:56 +08:00
|
|
|
ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if hod.Device() {
|
|
|
|
ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
|
|
|
|
ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
|
|
|
|
ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))
|
2016-05-20 07:58:46 +08:00
|
|
|
ctx.Strict(makePrefix+"GCC_VERSION", toolchain.GccVersion())
|
|
|
|
ctx.Strict(makePrefix+"NDK_GCC_VERSION", toolchain.GccVersion())
|
2016-05-17 05:22:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
|
2016-05-20 07:58:46 +08:00
|
|
|
ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
|
|
|
|
ctx.Strict(makePrefix+"EXECUTABLE_SUFFIX", toolchain.ExecutableSuffix())
|
2016-01-13 15:20:28 +08:00
|
|
|
}
|