blob: 774f3f7eaa4267e171553a918f4963711adee8a4 [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 Cross81b4ca62016-09-23 19:20:54 +0000115 })
116 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalSystemIncludes", "-isystem ",
117 []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700118 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700119 })
120 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
121 // with this, since there is no associated library.
Colin Crossb98c8b02016-07-29 13:44:28 -0700122 pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700123 []string{"libnativehelper/include/nativehelper"})
124
Colin Crossb98c8b02016-07-29 13:44:28 -0700125 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
126 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700127 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
128 return override, nil
129 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700130 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700131 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700132 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700133 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
134 return override, nil
135 }
Stephen Hines4442c2f2017-03-28 22:10:38 -0700136 return "clang-3859424", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700137 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700138 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
139 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
140
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800141 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
142 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
143 return override, nil
144 }
Stephen Hinesd19f58a2017-01-26 00:49:41 -0800145 return "4.0", nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800146 })
147 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700148
Jayant Chowdharye622d202017-02-01 19:19:52 -0800149 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
150 // being used for the rest of the build process.
151 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
152 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
153 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
154 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
155 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
156
Alistair Strachan777475c2016-08-26 12:55:49 -0700157 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
158 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
159 return override + " ", nil
160 }
161 return "", nil
162 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700163}
164
165var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
166
167func bionicHeaders(bionicArch, kernelArch string) string {
168 return strings.Join([]string{
169 "-isystem bionic/libc/arch-" + bionicArch + "/include",
170 "-isystem bionic/libc/include",
171 "-isystem bionic/libc/kernel/uapi",
172 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
173 "-isystem bionic/libc/kernel/android/uapi",
174 }, " ")
175}
Dan Willemsend2ede872016-11-18 14:54:24 -0800176
177func VndkLibraries() []string {
178 return []string{}
179}
Alex Naidis5df73d02017-04-05 20:08:41 +0200180
Dan Willemsenb916b802017-03-19 13:44:32 -0700181// This needs to be kept up to date with the list in system/core/rootdir/etc/ld.config.txt:
182// [vendor]
183// namespace.default.link.system.shared_libs
184func LLndkLibraries() []string {
185 return []string{"libc", "libm", "libdl", "liblog", "ld-android"}
186}
187
Alex Naidis5df73d02017-04-05 20:08:41 +0200188func replaceFirst(slice []string, from, to string) {
189 if slice[0] != from {
190 panic(fmt.Errorf("Expected %q, found %q", from, to))
191 }
192 slice[0] = to
193}