blob: 5587eae86aca5879baaa2a70be2b80a0f872cebe [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"
Stephen Craneba090d12017-05-09 15:44:35 -070019 "runtime"
Colin Cross4d9c2d12016-07-29 12:48:20 -070020 "strings"
21
22 "android/soong/android"
23)
24
Colin Cross4d9c2d12016-07-29 12:48:20 -070025var (
Leo Lie748f5d2017-05-22 16:11:34 -070026 // Flags used by lots of devices. Putting them in package static variables
27 // will save bytes in build.ninja so they aren't repeated for every file
Colin Cross4d9c2d12016-07-29 12:48:20 -070028 commonGlobalCflags = []string{
29 "-DANDROID",
30 "-fmessage-length=0",
31 "-W",
32 "-Wall",
33 "-Wno-unused",
34 "-Winit-self",
35 "-Wpointer-arith",
36
Colin Cross7278afc2017-11-02 22:38:32 -070037 // Make paths in deps files relative
38 "-no-canonical-prefixes",
39
Colin Cross4d9c2d12016-07-29 12:48:20 -070040 "-DNDEBUG",
41 "-UDEBUG",
Colin Cross7278afc2017-11-02 22:38:32 -070042
43 "-fno-exceptions",
44 "-Wno-multichar",
45
46 "-O2",
47 "-g",
48
49 "-fno-strict-aliasing",
Colin Cross4d9c2d12016-07-29 12:48:20 -070050 }
51
Colin Cross6f6a4282016-10-17 14:19:06 -070052 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -070053
Colin Cross4d9c2d12016-07-29 12:48:20 -070054 deviceGlobalCflags = []string{
55 "-fdiagnostics-color",
56
57 // TARGET_ERROR_FLAGS
58 "-Werror=return-type",
59 "-Werror=non-virtual-dtor",
60 "-Werror=address",
61 "-Werror=sequence-point",
62 "-Werror=date-time",
63 }
64
65 hostGlobalCflags = []string{}
66
67 commonGlobalCppflags = []string{
68 "-Wsign-promo",
69 }
70
71 noOverrideGlobalCflags = []string{
72 "-Werror=int-to-pointer-cast",
73 "-Werror=pointer-to-int-cast",
74 }
75
Colin Crossb98c8b02016-07-29 13:44:28 -070076 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -070077 "-w",
78 }
Colin Cross6f6a4282016-10-17 14:19:06 -070079
Dan Albert043833c2017-02-03 16:13:38 -080080 CStdVersion = "gnu99"
81 CppStdVersion = "gnu++14"
82 GccCppStdVersion = "gnu++11"
83 ExperimentalCStdVersion = "gnu11"
84 ExperimentalCppStdVersion = "gnu++1z"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -070085
86 NdkMaxPrebuiltVersionInt = 24
Leo Lie748f5d2017-05-22 16:11:34 -070087
88 // prebuilts/clang default settings.
89 ClangDefaultBase = "prebuilts/clang/host"
Stephen Hines0ed7d242017-10-04 16:12:37 -070090 ClangDefaultVersion = "clang-4393122"
91 ClangDefaultShortVersion = "5.0.1"
Colin Cross4d9c2d12016-07-29 12:48:20 -070092)
93
Colin Crossb98c8b02016-07-29 13:44:28 -070094var pctx = android.NewPackageContext("android/soong/cc/config")
95
Colin Cross4d9c2d12016-07-29 12:48:20 -070096func init() {
97 if android.BuildOs == android.Linux {
98 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
99 }
100
Colin Crossb98c8b02016-07-29 13:44:28 -0700101 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700102 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700103 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
104 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
105 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700106
Colin Crossb98c8b02016-07-29 13:44:28 -0700107 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700108
Colin Crossb98c8b02016-07-29 13:44:28 -0700109 pctx.StaticVariable("CommonClangGlobalCflags",
110 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
111 pctx.StaticVariable("DeviceClangGlobalCflags",
112 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
113 pctx.StaticVariable("HostClangGlobalCflags",
114 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
115 pctx.StaticVariable("NoOverrideClangGlobalCflags",
116 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700117
Colin Crossb98c8b02016-07-29 13:44:28 -0700118 pctx.StaticVariable("CommonClangGlobalCppflags",
119 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700120
Colin Cross1cfd89a2016-09-15 09:30:46 -0700121 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700122 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700123 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700124 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000125 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700126 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700127 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700128 "hardware/libhardware_legacy/include",
129 "hardware/ril/include",
130 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700131 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800132 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700133 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700134 })
135 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
136 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700137 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Steven Moreland3cf63062017-07-18 13:29:35 -0700138 []string{"libnativehelper/include_deprecated"})
Colin Cross4d9c2d12016-07-29 12:48:20 -0700139
Leo Lie748f5d2017-05-22 16:11:34 -0700140 pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
Colin Crossb98c8b02016-07-29 13:44:28 -0700141 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700142 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
143 return override, nil
144 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700145 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700146 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700147 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700148 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
149 return override, nil
150 }
Leo Lie748f5d2017-05-22 16:11:34 -0700151 return ClangDefaultVersion, nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700152 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700153 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
154 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
155
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800156 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
157 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
158 return override, nil
159 }
Leo Lie748f5d2017-05-22 16:11:34 -0700160 return ClangDefaultShortVersion, nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800161 })
162 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Stephen Craneba090d12017-05-09 15:44:35 -0700163 if runtime.GOOS == "darwin" {
164 pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.dylib")
165 } else {
166 pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.so")
167 }
Alistair Strachan777475c2016-08-26 12:55:49 -0700168
Jayant Chowdharye622d202017-02-01 19:19:52 -0800169 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
170 // being used for the rest of the build process.
171 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
172 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
173 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
174 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
175 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
176
Jeff Gaston734e3802017-04-10 15:47:24 -0700177 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700178 []string{
179 "external/clang/lib/Headers",
180 "frameworks/rs/script_api/include",
181 })
182
Alistair Strachan777475c2016-08-26 12:55:49 -0700183 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
184 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
185 return override + " ", nil
186 }
187 return "", nil
188 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700189}
190
191var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
192
Elliott Hughesde28deb2017-10-12 09:07:53 -0700193func bionicHeaders(kernelArch string) string {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700194 return strings.Join([]string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700195 "-isystem bionic/libc/include",
196 "-isystem bionic/libc/kernel/uapi",
197 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
Elliott Hughes98418a02017-05-25 17:16:10 -0700198 "-isystem bionic/libc/kernel/android/scsi",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700199 "-isystem bionic/libc/kernel/android/uapi",
200 }, " ")
201}
Dan Willemsend2ede872016-11-18 14:54:24 -0800202
Alex Naidis5df73d02017-04-05 20:08:41 +0200203func replaceFirst(slice []string, from, to string) {
204 if slice[0] != from {
205 panic(fmt.Errorf("Expected %q, found %q", from, to))
206 }
207 slice[0] = to
208}