2016-07-30 03:48:20 +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.
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
package config
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
import (
|
2017-04-06 02:08:41 +08:00
|
|
|
"fmt"
|
2017-05-10 06:44:35 +08:00
|
|
|
"runtime"
|
2016-07-30 03:48:20 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-05-23 07:11:34 +08:00
|
|
|
// Flags used by lots of devices. Putting them in package static variables
|
|
|
|
// will save bytes in build.ninja so they aren't repeated for every file
|
2016-07-30 03:48:20 +08:00
|
|
|
commonGlobalCflags = []string{
|
|
|
|
"-DANDROID",
|
|
|
|
"-fmessage-length=0",
|
|
|
|
"-W",
|
|
|
|
"-Wall",
|
|
|
|
"-Wno-unused",
|
|
|
|
"-Winit-self",
|
|
|
|
"-Wpointer-arith",
|
|
|
|
|
|
|
|
// COMMON_RELEASE_CFLAGS
|
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
|
|
|
}
|
|
|
|
|
2016-10-18 05:19:06 +08:00
|
|
|
commonGlobalConlyflags = []string{}
|
2016-10-08 04:12:58 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
deviceGlobalCflags = []string{
|
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
|
|
|
// TARGET_ERROR_FLAGS
|
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
|
|
|
"-Werror=date-time",
|
|
|
|
}
|
|
|
|
|
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
|
|
|
}
|
|
|
|
|
|
|
|
noOverrideGlobalCflags = []string{
|
|
|
|
"-Werror=int-to-pointer-cast",
|
|
|
|
"-Werror=pointer-to-int-cast",
|
|
|
|
}
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
IllegalFlags = []string{
|
2016-07-30 03:48:20 +08:00
|
|
|
"-w",
|
|
|
|
}
|
2016-10-18 05:19:06 +08:00
|
|
|
|
2017-02-04 08:13:38 +08:00
|
|
|
CStdVersion = "gnu99"
|
|
|
|
CppStdVersion = "gnu++14"
|
|
|
|
GccCppStdVersion = "gnu++11"
|
|
|
|
ExperimentalCStdVersion = "gnu11"
|
|
|
|
ExperimentalCppStdVersion = "gnu++1z"
|
2017-05-10 01:21:52 +08:00
|
|
|
|
|
|
|
NdkMaxPrebuiltVersionInt = 24
|
2017-05-23 07:11:34 +08:00
|
|
|
|
|
|
|
// prebuilts/clang default settings.
|
|
|
|
ClangDefaultBase = "prebuilts/clang/host"
|
2017-10-05 07:12:37 +08:00
|
|
|
ClangDefaultVersion = "clang-4393122"
|
|
|
|
ClangDefaultShortVersion = "5.0.1"
|
2016-07-30 03:48:20 +08:00
|
|
|
)
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
var pctx = android.NewPackageContext("android/soong/cc/config")
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
func init() {
|
|
|
|
if android.BuildOs == android.Linux {
|
|
|
|
commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
|
|
|
|
}
|
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
|
2016-10-08 04:12:58 +08:00
|
|
|
pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
|
|
|
|
pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("CommonClangGlobalCflags",
|
|
|
|
strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
|
|
|
|
pctx.StaticVariable("DeviceClangGlobalCflags",
|
|
|
|
strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
|
|
|
|
pctx.StaticVariable("HostClangGlobalCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
|
|
|
|
pctx.StaticVariable("NoOverrideClangGlobalCflags",
|
|
|
|
strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("CommonClangGlobalCppflags",
|
|
|
|
strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-09-16 00:30:46 +08:00
|
|
|
// Everything in these lists is a crime against abstraction and dependency tracking.
|
2016-07-30 03:48:20 +08:00
|
|
|
// Do not add anything to this list.
|
2017-04-11 06:47:24 +08:00
|
|
|
pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
|
2016-09-23 06:29:50 +08:00
|
|
|
[]string{
|
2016-09-23 23:48:51 +08:00
|
|
|
"system/core/include",
|
2016-10-06 03:36:42 +08:00
|
|
|
"system/media/audio/include",
|
2016-10-06 03:36:42 +08:00
|
|
|
"hardware/libhardware/include",
|
2016-11-04 06:45:34 +08:00
|
|
|
"hardware/libhardware_legacy/include",
|
|
|
|
"hardware/ril/include",
|
|
|
|
"libnativehelper/include",
|
2016-10-06 03:36:42 +08:00
|
|
|
"frameworks/native/include",
|
2016-12-15 03:13:16 +08:00
|
|
|
"frameworks/native/opengl/include",
|
2016-07-30 03:48:20 +08:00
|
|
|
"frameworks/av/include",
|
|
|
|
})
|
|
|
|
// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
|
|
|
|
// with this, since there is no associated library.
|
2017-04-11 06:47:24 +08:00
|
|
|
pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
|
2017-07-19 04:29:35 +08:00
|
|
|
[]string{"libnativehelper/include_deprecated"})
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2017-05-23 07:11:34 +08:00
|
|
|
pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
|
2016-07-30 03:48:20 +08:00
|
|
|
if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
|
|
|
return override, nil
|
|
|
|
}
|
2016-07-30 04:44:28 +08:00
|
|
|
return "${ClangDefaultBase}", nil
|
2016-07-30 03:48:20 +08:00
|
|
|
})
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
|
2016-07-30 03:48:20 +08:00
|
|
|
if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
|
|
|
return override, nil
|
|
|
|
}
|
2017-05-23 07:11:34 +08:00
|
|
|
return ClangDefaultVersion, nil
|
2016-07-30 03:48:20 +08:00
|
|
|
})
|
2016-07-30 04:44:28 +08:00
|
|
|
pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
|
|
|
|
pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
|
|
|
|
|
2016-11-19 09:12:38 +08:00
|
|
|
pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
|
|
|
|
if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
|
|
|
|
return override, nil
|
|
|
|
}
|
2017-05-23 07:11:34 +08:00
|
|
|
return ClangDefaultShortVersion, nil
|
2016-11-19 09:12:38 +08:00
|
|
|
})
|
|
|
|
pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
|
2017-05-10 06:44:35 +08:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.dylib")
|
|
|
|
} else {
|
|
|
|
pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.so")
|
|
|
|
}
|
2016-08-27 03:55:49 +08:00
|
|
|
|
2017-02-02 11:19:52 +08:00
|
|
|
// These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
|
|
|
|
// being used for the rest of the build process.
|
|
|
|
pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
|
|
|
|
pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
|
|
|
|
pctx.SourcePathVariable("RSReleaseVersion", "3.8")
|
|
|
|
pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
|
|
|
|
pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
|
|
|
|
|
2017-04-11 06:47:24 +08:00
|
|
|
pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
|
2017-05-02 08:37:24 +08:00
|
|
|
[]string{
|
|
|
|
"external/clang/lib/Headers",
|
|
|
|
"frameworks/rs/script_api/include",
|
|
|
|
})
|
|
|
|
|
2016-08-27 03:55:49 +08:00
|
|
|
pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
|
|
|
|
if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
|
|
|
|
return override + " ", nil
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
})
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
|
|
|
|
|
2017-10-13 00:07:53 +08:00
|
|
|
func bionicHeaders(kernelArch string) string {
|
2016-07-30 03:48:20 +08:00
|
|
|
return strings.Join([]string{
|
|
|
|
"-isystem bionic/libc/include",
|
|
|
|
"-isystem bionic/libc/kernel/uapi",
|
|
|
|
"-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
|
2017-05-26 08:16:10 +08:00
|
|
|
"-isystem bionic/libc/kernel/android/scsi",
|
2016-07-30 03:48:20 +08:00
|
|
|
"-isystem bionic/libc/kernel/android/uapi",
|
|
|
|
}, " ")
|
|
|
|
}
|
2016-11-19 06:54:24 +08:00
|
|
|
|
2017-04-06 02:08:41 +08:00
|
|
|
func replaceFirst(slice []string, from, to string) {
|
|
|
|
if slice[0] != from {
|
|
|
|
panic(fmt.Errorf("Expected %q, found %q", from, to))
|
|
|
|
}
|
|
|
|
slice[0] = to
|
|
|
|
}
|