blob: 56de35139265bc7753639402453f8ba24f8cce4d [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
Colin Cross4d9c2d12016-07-29 12:48:20 -070024var (
Leo Lie748f5d2017-05-22 16:11:34 -070025 // Flags used by lots of devices. Putting them in package static variables
26 // will save bytes in build.ninja so they aren't repeated for every file
Colin Cross4d9c2d12016-07-29 12:48:20 -070027 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
Leo Lie748f5d2017-05-22 16:11:34 -070076
77 // prebuilts/clang default settings.
78 ClangDefaultBase = "prebuilts/clang/host"
Yi Kongdadff1b2017-05-01 15:04:48 -070079 ClangDefaultVersion = "clang-4053586"
80 ClangDefaultShortVersion = "5.0"
Colin Cross4d9c2d12016-07-29 12:48:20 -070081)
82
Colin Crossb98c8b02016-07-29 13:44:28 -070083var pctx = android.NewPackageContext("android/soong/cc/config")
84
Colin Cross4d9c2d12016-07-29 12:48:20 -070085func init() {
86 if android.BuildOs == android.Linux {
87 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
88 }
89
Colin Crossb98c8b02016-07-29 13:44:28 -070090 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070091 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070092 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
93 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
94 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070095
Colin Crossb98c8b02016-07-29 13:44:28 -070096 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070097
Colin Crossb98c8b02016-07-29 13:44:28 -070098 pctx.StaticVariable("CommonClangGlobalCflags",
99 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
100 pctx.StaticVariable("DeviceClangGlobalCflags",
101 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
102 pctx.StaticVariable("HostClangGlobalCflags",
103 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
104 pctx.StaticVariable("NoOverrideClangGlobalCflags",
105 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700106
Colin Crossb98c8b02016-07-29 13:44:28 -0700107 pctx.StaticVariable("CommonClangGlobalCppflags",
108 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700109
Colin Cross1cfd89a2016-09-15 09:30:46 -0700110 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700111 // Do not add anything to this list.
Jeff Gaston734e3802017-04-10 15:47:24 -0700112 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700113 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000114 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700115 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700116 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700117 "hardware/libhardware_legacy/include",
118 "hardware/ril/include",
119 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700120 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800121 "frameworks/native/opengl/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700122 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700123 })
124 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
125 // with this, since there is no associated library.
Jeff Gaston734e3802017-04-10 15:47:24 -0700126 pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
Steven Moreland3cf63062017-07-18 13:29:35 -0700127 []string{"libnativehelper/include_deprecated"})
Colin Cross4d9c2d12016-07-29 12:48:20 -0700128
Leo Lie748f5d2017-05-22 16:11:34 -0700129 pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
Colin Crossb98c8b02016-07-29 13:44:28 -0700130 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700131 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
132 return override, nil
133 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700134 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700135 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700136 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700137 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
138 return override, nil
139 }
Leo Lie748f5d2017-05-22 16:11:34 -0700140 return ClangDefaultVersion, nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700141 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700142 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
143 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
144
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800145 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
146 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
147 return override, nil
148 }
Leo Lie748f5d2017-05-22 16:11:34 -0700149 return ClangDefaultShortVersion, nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800150 })
151 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700152
Jayant Chowdharye622d202017-02-01 19:19:52 -0800153 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
154 // being used for the rest of the build process.
155 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
156 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
157 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
158 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
159 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
160
Jeff Gaston734e3802017-04-10 15:47:24 -0700161 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700162 []string{
163 "external/clang/lib/Headers",
164 "frameworks/rs/script_api/include",
165 })
166
Alistair Strachan777475c2016-08-26 12:55:49 -0700167 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
168 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
169 return override + " ", nil
170 }
171 return "", nil
172 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700173}
174
175var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
176
177func bionicHeaders(bionicArch, kernelArch string) string {
178 return strings.Join([]string{
179 "-isystem bionic/libc/arch-" + bionicArch + "/include",
180 "-isystem bionic/libc/include",
181 "-isystem bionic/libc/kernel/uapi",
182 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
Elliott Hughes98418a02017-05-25 17:16:10 -0700183 "-isystem bionic/libc/kernel/android/scsi",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700184 "-isystem bionic/libc/kernel/android/uapi",
185 }, " ")
186}
Dan Willemsend2ede872016-11-18 14:54:24 -0800187
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}