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 (
|
|
|
|
"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",
|
|
|
|
|
2017-11-03 13:38:32 +08:00
|
|
|
// Make paths in deps files relative
|
|
|
|
"-no-canonical-prefixes",
|
2017-11-07 04:53:30 +08:00
|
|
|
"-fno-canonical-system-headers",
|
2017-11-03 13:38:32 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
2017-11-03 13:38:32 +08:00
|
|
|
|
|
|
|
"-fno-exceptions",
|
|
|
|
"-Wno-multichar",
|
|
|
|
|
|
|
|
"-O2",
|
|
|
|
"-g",
|
|
|
|
|
|
|
|
"-fno-strict-aliasing",
|
2019-08-28 10:37:10 +08:00
|
|
|
|
|
|
|
"-Werror=date-time",
|
2019-12-04 10:13:00 +08:00
|
|
|
"-Werror=pragma-pack",
|
|
|
|
"-Werror=pragma-pack-suspicious-include",
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
|
2017-11-03 13:55:19 +08:00
|
|
|
"-ffunction-sections",
|
2017-11-07 06:02:02 +08:00
|
|
|
"-fdata-sections",
|
|
|
|
"-fno-short-enums",
|
2017-11-03 13:55:19 +08:00
|
|
|
"-funwind-tables",
|
|
|
|
"-fstack-protector-strong",
|
|
|
|
"-Wa,--noexecstack",
|
|
|
|
"-D_FORTIFY_SOURCE=2",
|
|
|
|
|
|
|
|
"-Wstrict-aliasing=2",
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
2017-11-03 13:55:19 +08:00
|
|
|
"-Werror=format-security",
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2017-11-07 05:59:48 +08:00
|
|
|
deviceGlobalCppflags = []string{
|
|
|
|
"-fvisibility-inlines-hidden",
|
|
|
|
}
|
|
|
|
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 14:09:41 +08:00
|
|
|
deviceGlobalLdflags = []string{
|
|
|
|
"-Wl,-z,noexecstack",
|
|
|
|
"-Wl,-z,relro",
|
|
|
|
"-Wl,-z,now",
|
|
|
|
"-Wl,--build-id=md5",
|
|
|
|
"-Wl,--warn-shared-textrel",
|
|
|
|
"-Wl,--fatal-warnings",
|
|
|
|
"-Wl,--no-undefined-version",
|
2019-04-11 08:57:50 +08:00
|
|
|
"-Wl,--exclude-libs,libgcc.a",
|
2019-05-07 07:18:33 +08:00
|
|
|
"-Wl,--exclude-libs,libgcc_stripped.a",
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2018-04-04 02:33:34 +08:00
|
|
|
deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
|
|
|
|
[]string{
|
|
|
|
"-fuse-ld=lld",
|
|
|
|
}...)
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
2017-11-07 05:59:48 +08:00
|
|
|
hostGlobalCppflags = []string{}
|
|
|
|
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 14:09:41 +08:00
|
|
|
hostGlobalLdflags = []string{}
|
|
|
|
|
2018-04-18 05:16:05 +08:00
|
|
|
hostGlobalLldflags = []string{"-fuse-ld=lld"}
|
2018-04-04 02:33:34 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
|
|
|
}
|
|
|
|
|
|
|
|
noOverrideGlobalCflags = []string{
|
|
|
|
"-Werror=int-to-pointer-cast",
|
|
|
|
"-Werror=pointer-to-int-cast",
|
2019-09-19 08:52:05 +08:00
|
|
|
"-Werror=fortify-source",
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
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"
|
2018-12-01 00:03:06 +08:00
|
|
|
CppStdVersion = "gnu++17"
|
2017-02-04 08:13:38 +08:00
|
|
|
ExperimentalCStdVersion = "gnu11"
|
2018-11-29 06:16:39 +08:00
|
|
|
ExperimentalCppStdVersion = "gnu++2a"
|
2017-05-10 01:21:52 +08:00
|
|
|
|
2018-01-17 08:21:06 +08:00
|
|
|
NdkMaxPrebuiltVersionInt = 27
|
2017-05-23 07:11:34 +08:00
|
|
|
|
|
|
|
// prebuilts/clang default settings.
|
|
|
|
ClangDefaultBase = "prebuilts/clang/host"
|
2019-12-13 02:15:42 +08:00
|
|
|
ClangDefaultVersion = "clang-r370808"
|
|
|
|
ClangDefaultShortVersion = "10.0.1"
|
2017-11-15 06:09:14 +08:00
|
|
|
|
2017-12-25 14:24:47 +08:00
|
|
|
// Directories with warnings from Android.bp files.
|
2017-11-15 06:09:14 +08:00
|
|
|
WarningAllowedProjects = []string{
|
|
|
|
"device/",
|
|
|
|
"vendor/",
|
|
|
|
}
|
|
|
|
|
2017-12-25 14:24:47 +08:00
|
|
|
// Directories with warnings from Android.mk files.
|
|
|
|
WarningAllowedOldProjects = []string{}
|
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-10-08 04:12:58 +08:00
|
|
|
pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
|
2017-11-07 05:59:48 +08:00
|
|
|
pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 14:09:41 +08:00
|
|
|
pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
|
2018-04-04 02:33:34 +08:00
|
|
|
pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
|
2017-11-07 05:59:48 +08:00
|
|
|
pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 14:09:41 +08:00
|
|
|
pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
|
2018-04-04 02:33:34 +08:00
|
|
|
pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2019-06-11 08:40:12 +08:00
|
|
|
pctx.VariableFunc("CommonClangGlobalCflags", func(ctx android.PackageVarContext) string {
|
|
|
|
flags := ClangFilterUnknownCflags(commonGlobalCflags)
|
|
|
|
flags = append(flags, "${ClangExtraCflags}")
|
|
|
|
|
|
|
|
// http://b/131390872
|
|
|
|
// Automatically initialize any uninitialized stack variables.
|
|
|
|
// Prefer zero-init if both options are set.
|
|
|
|
if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
|
|
|
|
flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
|
|
|
|
} else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
|
|
|
|
flags = append(flags, "-ftrivial-auto-var-init=pattern")
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(flags, " ")
|
|
|
|
})
|
|
|
|
|
2019-01-18 06:44:05 +08:00
|
|
|
pctx.VariableFunc("DeviceClangGlobalCflags", func(ctx android.PackageVarContext) string {
|
|
|
|
if ctx.Config().Fuchsia() {
|
|
|
|
return strings.Join(ClangFilterUnknownCflags(deviceGlobalCflags), " ")
|
|
|
|
} else {
|
|
|
|
return strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")
|
|
|
|
}
|
|
|
|
})
|
2016-07-30 04:44:28 +08:00
|
|
|
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
|
|
|
|
2018-06-07 05:42:44 +08:00
|
|
|
pctx.StaticVariable("ClangExternalCflags", "${ClangExtraExternalCflags}")
|
|
|
|
|
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",
|
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-09-26 02:22:02 +08:00
|
|
|
[]string{"libnativehelper/include_jni"})
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2017-05-23 07:11:34 +08:00
|
|
|
pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
|
|
|
return override
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2018-03-13 04:24:09 +08:00
|
|
|
return "${ClangDefaultBase}"
|
2016-07-30 03:48:20 +08:00
|
|
|
})
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
|
|
|
return override
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2018-03-13 04:24:09 +08:00
|
|
|
return ClangDefaultVersion
|
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")
|
|
|
|
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
|
|
|
|
return override
|
2016-11-19 09:12:38 +08:00
|
|
|
}
|
2018-03-13 04:24:09 +08:00
|
|
|
return ClangDefaultShortVersion
|
2016-11-19 09:12:38 +08:00
|
|
|
})
|
2018-01-25 11:58:36 +08:00
|
|
|
pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
|
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",
|
|
|
|
})
|
|
|
|
|
2018-03-13 04:24:09 +08:00
|
|
|
pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
|
|
|
|
return override + " "
|
2016-08-27 03:55:49 +08:00
|
|
|
}
|
2018-03-13 04:24:09 +08:00
|
|
|
return ""
|
2016-08-27 03:55:49 +08:00
|
|
|
})
|
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",
|
|
|
|
}, " ")
|
|
|
|
}
|