blob: 43ff9755d54afa1afff70cca4ec62f88dbd33822 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Cross4d9c2d12016-07-29 12:48:20 -070016
17import (
Alex Naidis5df73d02017-04-05 20:08:41 +020018 "fmt"
Colin Cross4d9c2d12016-07-29 12:48:20 -070019 "strings"
20
21 "android/soong/android"
22)
23
24// Flags used by lots of devices. Putting them in package static variables will save bytes in
25// build.ninja so they aren't repeated for every file
26var (
27 commonGlobalCflags = []string{
28 "-DANDROID",
29 "-fmessage-length=0",
30 "-W",
31 "-Wall",
32 "-Wno-unused",
33 "-Winit-self",
34 "-Wpointer-arith",
35
36 // COMMON_RELEASE_CFLAGS
37 "-DNDEBUG",
38 "-UDEBUG",
39 }
40
Colin Cross6f6a4282016-10-17 14:19:06 -070041 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -070042
Colin Cross4d9c2d12016-07-29 12:48:20 -070043 deviceGlobalCflags = []string{
44 "-fdiagnostics-color",
45
46 // TARGET_ERROR_FLAGS
47 "-Werror=return-type",
48 "-Werror=non-virtual-dtor",
49 "-Werror=address",
50 "-Werror=sequence-point",
51 "-Werror=date-time",
52 }
53
54 hostGlobalCflags = []string{}
55
56 commonGlobalCppflags = []string{
57 "-Wsign-promo",
58 }
59
60 noOverrideGlobalCflags = []string{
61 "-Werror=int-to-pointer-cast",
62 "-Werror=pointer-to-int-cast",
63 }
64
Colin Crossb98c8b02016-07-29 13:44:28 -070065 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -070066 "-w",
67 }
Colin Cross6f6a4282016-10-17 14:19:06 -070068
Dan Albert043833c2017-02-03 16:13:38 -080069 CStdVersion = "gnu99"
70 CppStdVersion = "gnu++14"
71 GccCppStdVersion = "gnu++11"
72 ExperimentalCStdVersion = "gnu11"
73 ExperimentalCppStdVersion = "gnu++1z"
Colin Cross4d9c2d12016-07-29 12:48:20 -070074)
75
Colin Crossb98c8b02016-07-29 13:44:28 -070076var pctx = android.NewPackageContext("android/soong/cc/config")
77
Colin Cross4d9c2d12016-07-29 12:48:20 -070078func init() {
79 if android.BuildOs == android.Linux {
80 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
81 }
82
Colin Crossb98c8b02016-07-29 13:44:28 -070083 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070084 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070085 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
86 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
87 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070088
Colin Crossb98c8b02016-07-29 13:44:28 -070089 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070090
Colin Crossb98c8b02016-07-29 13:44:28 -070091 pctx.StaticVariable("CommonClangGlobalCflags",
92 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
93 pctx.StaticVariable("DeviceClangGlobalCflags",
94 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
95 pctx.StaticVariable("HostClangGlobalCflags",
96 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
97 pctx.StaticVariable("NoOverrideClangGlobalCflags",
98 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070099
Colin Crossb98c8b02016-07-29 13:44:28 -0700100 pctx.StaticVariable("CommonClangGlobalCppflags",
101 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700102
Colin Cross1cfd89a2016-09-15 09:30:46 -0700103 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700104 // Do not add anything to this list.
Colin Cross1cfd89a2016-09-15 09:30:46 -0700105 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700106 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000107 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700108 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700109 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700110 "hardware/libhardware_legacy/include",
111 "hardware/ril/include",
112 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700113 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800114 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700115 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700116 })
117 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
118 // with this, since there is no associated library.
Colin Crossb98c8b02016-07-29 13:44:28 -0700119 pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700120 []string{"libnativehelper/include/nativehelper"})
121
Colin Crossb98c8b02016-07-29 13:44:28 -0700122 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
123 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700124 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
125 return override, nil
126 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700127 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700128 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700129 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700130 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
131 return override, nil
132 }
Stephen Hines4442c2f2017-03-28 22:10:38 -0700133 return "clang-3859424", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700134 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
136 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
137
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800138 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
139 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
140 return override, nil
141 }
Stephen Hinesd19f58a2017-01-26 00:49:41 -0800142 return "4.0", nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800143 })
144 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700145
Jayant Chowdharye622d202017-02-01 19:19:52 -0800146 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
147 // being used for the rest of the build process.
148 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
149 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
150 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
151 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
152 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
153
Colin Cross2a252be2017-05-01 17:37:24 -0700154 pctx.PrefixedPathsForOptionalSourceVariable("RsGlobalIncludes", "-I",
155 []string{
156 "external/clang/lib/Headers",
157 "frameworks/rs/script_api/include",
158 })
159
Alistair Strachan777475c2016-08-26 12:55:49 -0700160 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
161 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
162 return override + " ", nil
163 }
164 return "", nil
165 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700166}
167
168var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
169
170func bionicHeaders(bionicArch, kernelArch string) string {
171 return strings.Join([]string{
172 "-isystem bionic/libc/arch-" + bionicArch + "/include",
173 "-isystem bionic/libc/include",
174 "-isystem bionic/libc/kernel/uapi",
175 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
176 "-isystem bionic/libc/kernel/android/uapi",
177 }, " ")
178}
Dan Willemsend2ede872016-11-18 14:54:24 -0800179
180func VndkLibraries() []string {
181 return []string{}
182}
Alex Naidis5df73d02017-04-05 20:08:41 +0200183
Dan Willemsenb916b802017-03-19 13:44:32 -0700184// This needs to be kept up to date with the list in system/core/rootdir/etc/ld.config.txt:
185// [vendor]
186// namespace.default.link.system.shared_libs
187func LLndkLibraries() []string {
188 return []string{"libc", "libm", "libdl", "liblog", "ld-android"}
189}
190
Alex Naidis5df73d02017-04-05 20:08:41 +0200191func replaceFirst(slice []string, from, to string) {
192 if slice[0] != from {
193 panic(fmt.Errorf("Expected %q, found %q", from, to))
194 }
195 slice[0] = to
196}