blob: 82a44e615b6c7c955fa2d9573813ce553d2f7e5d [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
37 // COMMON_RELEASE_CFLAGS
38 "-DNDEBUG",
39 "-UDEBUG",
40 }
41
Colin Cross6f6a4282016-10-17 14:19:06 -070042 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -070043
Colin Cross4d9c2d12016-07-29 12:48:20 -070044 deviceGlobalCflags = []string{
45 "-fdiagnostics-color",
46
47 // TARGET_ERROR_FLAGS
48 "-Werror=return-type",
49 "-Werror=non-virtual-dtor",
50 "-Werror=address",
51 "-Werror=sequence-point",
52 "-Werror=date-time",
53 }
54
55 hostGlobalCflags = []string{}
56
57 commonGlobalCppflags = []string{
58 "-Wsign-promo",
59 }
60
61 noOverrideGlobalCflags = []string{
62 "-Werror=int-to-pointer-cast",
63 "-Werror=pointer-to-int-cast",
64 }
65
Colin Crossb98c8b02016-07-29 13:44:28 -070066 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -070067 "-w",
68 }
Colin Cross6f6a4282016-10-17 14:19:06 -070069
Dan Albert043833c2017-02-03 16:13:38 -080070 CStdVersion = "gnu99"
71 CppStdVersion = "gnu++14"
72 GccCppStdVersion = "gnu++11"
73 ExperimentalCStdVersion = "gnu11"
74 ExperimentalCppStdVersion = "gnu++1z"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -070075
76 NdkMaxPrebuiltVersionInt = 24
Leo Lie748f5d2017-05-22 16:11:34 -070077
78 // prebuilts/clang default settings.
79 ClangDefaultBase = "prebuilts/clang/host"
Yi Kongdadff1b2017-05-01 15:04:48 -070080 ClangDefaultVersion = "clang-4053586"
81 ClangDefaultShortVersion = "5.0"
Colin Cross4d9c2d12016-07-29 12:48:20 -070082)
83
Colin Crossb98c8b02016-07-29 13:44:28 -070084var pctx = android.NewPackageContext("android/soong/cc/config")
85
Colin Cross4d9c2d12016-07-29 12:48:20 -070086func init() {
87 if android.BuildOs == android.Linux {
88 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
89 }
90
Colin Crossb98c8b02016-07-29 13:44:28 -070091 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070092 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070093 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
94 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
95 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070096
Colin Crossb98c8b02016-07-29 13:44:28 -070097 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070098
Colin Crossb98c8b02016-07-29 13:44:28 -070099 pctx.StaticVariable("CommonClangGlobalCflags",
100 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
101 pctx.StaticVariable("DeviceClangGlobalCflags",
102 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
103 pctx.StaticVariable("HostClangGlobalCflags",
104 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
105 pctx.StaticVariable("NoOverrideClangGlobalCflags",
106 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700107
Colin Crossb98c8b02016-07-29 13:44:28 -0700108 pctx.StaticVariable("CommonClangGlobalCppflags",
109 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700110
Colin Cross1cfd89a2016-09-15 09:30:46 -0700111 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700112 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700113 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700114 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000115 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700116 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700117 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700118 "hardware/libhardware_legacy/include",
119 "hardware/ril/include",
120 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700121 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800122 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700123 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700124 })
125 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
126 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700127 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Steven Moreland3cf63062017-07-18 13:29:35 -0700128 []string{"libnativehelper/include_deprecated"})
Colin Cross4d9c2d12016-07-29 12:48:20 -0700129
Leo Lie748f5d2017-05-22 16:11:34 -0700130 pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700132 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
133 return override, nil
134 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700136 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700138 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
139 return override, nil
140 }
Leo Lie748f5d2017-05-22 16:11:34 -0700141 return ClangDefaultVersion, nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700142 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700143 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
144 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
145
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800146 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
147 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
148 return override, nil
149 }
Leo Lie748f5d2017-05-22 16:11:34 -0700150 return ClangDefaultShortVersion, nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800151 })
152 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Stephen Craneba090d12017-05-09 15:44:35 -0700153 if runtime.GOOS == "darwin" {
154 pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.dylib")
155 } else {
156 pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.so")
157 }
Alistair Strachan777475c2016-08-26 12:55:49 -0700158
Jayant Chowdharye622d202017-02-01 19:19:52 -0800159 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
160 // being used for the rest of the build process.
161 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
162 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
163 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
164 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
165 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
166
Jeff Gaston734e3802017-04-10 15:47:24 -0700167 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700168 []string{
169 "external/clang/lib/Headers",
170 "frameworks/rs/script_api/include",
171 })
172
Alistair Strachan777475c2016-08-26 12:55:49 -0700173 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
174 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
175 return override + " ", nil
176 }
177 return "", nil
178 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700179}
180
181var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
182
183func bionicHeaders(bionicArch, kernelArch string) string {
184 return strings.Join([]string{
185 "-isystem bionic/libc/arch-" + bionicArch + "/include",
186 "-isystem bionic/libc/include",
187 "-isystem bionic/libc/kernel/uapi",
188 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
Elliott Hughes98418a02017-05-25 17:16:10 -0700189 "-isystem bionic/libc/kernel/android/scsi",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700190 "-isystem bionic/libc/kernel/android/uapi",
191 }, " ")
192}
Dan Willemsend2ede872016-11-18 14:54:24 -0800193
Alex Naidis5df73d02017-04-05 20:08:41 +0200194func replaceFirst(slice []string, from, to string) {
195 if slice[0] != from {
196 panic(fmt.Errorf("Expected %q, found %q", from, to))
197 }
198 slice[0] = to
199}