blob: 997256efef49c10a9522c9fa7448f266c5ddad37 [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"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -070074
75 NdkMaxPrebuiltVersionInt = 24
Colin Cross4d9c2d12016-07-29 12:48:20 -070076)
77
Colin Crossb98c8b02016-07-29 13:44:28 -070078var pctx = android.NewPackageContext("android/soong/cc/config")
79
Colin Cross4d9c2d12016-07-29 12:48:20 -070080func init() {
81 if android.BuildOs == android.Linux {
82 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
83 }
84
Colin Crossb98c8b02016-07-29 13:44:28 -070085 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070086 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070087 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
88 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
89 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070090
Colin Crossb98c8b02016-07-29 13:44:28 -070091 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070092
Colin Crossb98c8b02016-07-29 13:44:28 -070093 pctx.StaticVariable("CommonClangGlobalCflags",
94 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
95 pctx.StaticVariable("DeviceClangGlobalCflags",
96 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
97 pctx.StaticVariable("HostClangGlobalCflags",
98 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
99 pctx.StaticVariable("NoOverrideClangGlobalCflags",
100 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700101
Colin Crossb98c8b02016-07-29 13:44:28 -0700102 pctx.StaticVariable("CommonClangGlobalCppflags",
103 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700104
Colin Cross1cfd89a2016-09-15 09:30:46 -0700105 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700106 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700107 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700108 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000109 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700110 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700111 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700112 "hardware/libhardware_legacy/include",
113 "hardware/ril/include",
114 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700115 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800116 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700117 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700118 })
119 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
120 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700121 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700122 []string{"libnativehelper/include/nativehelper"})
123
Colin Crossb98c8b02016-07-29 13:44:28 -0700124 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
125 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700126 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
127 return override, nil
128 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700129 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700130 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700132 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
133 return override, nil
134 }
Stephen Hines4442c2f2017-03-28 22:10:38 -0700135 return "clang-3859424", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700136 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
138 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
139
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800140 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
141 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
142 return override, nil
143 }
Stephen Hinesd19f58a2017-01-26 00:49:41 -0800144 return "4.0", nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800145 })
146 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700147
Jayant Chowdharye622d202017-02-01 19:19:52 -0800148 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
149 // being used for the rest of the build process.
150 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
151 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
152 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
153 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
154 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
155
Jeff Gaston734e3802017-04-10 15:47:24 -0700156 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700157 []string{
158 "external/clang/lib/Headers",
159 "frameworks/rs/script_api/include",
160 })
161
Alistair Strachan777475c2016-08-26 12:55:49 -0700162 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
163 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
164 return override + " ", nil
165 }
166 return "", nil
167 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700168}
169
170var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
171
172func bionicHeaders(bionicArch, kernelArch string) string {
173 return strings.Join([]string{
174 "-isystem bionic/libc/arch-" + bionicArch + "/include",
175 "-isystem bionic/libc/include",
176 "-isystem bionic/libc/kernel/uapi",
177 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
178 "-isystem bionic/libc/kernel/android/uapi",
179 }, " ")
180}
Dan Willemsend2ede872016-11-18 14:54:24 -0800181
182func VndkLibraries() []string {
183 return []string{}
184}
Alex Naidis5df73d02017-04-05 20:08:41 +0200185
Dan Willemsenb916b802017-03-19 13:44:32 -0700186// This needs to be kept up to date with the list in system/core/rootdir/etc/ld.config.txt:
187// [vendor]
188// namespace.default.link.system.shared_libs
189func LLndkLibraries() []string {
190 return []string{"libc", "libm", "libdl", "liblog", "ld-android"}
191}
192
Alex Naidis5df73d02017-04-05 20:08:41 +0200193func replaceFirst(slice []string, from, to string) {
194 if slice[0] != from {
195 panic(fmt.Errorf("Expected %q, found %q", from, to))
196 }
197 slice[0] = to
198}