blob: e454c16af7e53b107509de44ca74d8da85657f0d [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 (
18 "strings"
19
20 "android/soong/android"
21)
22
23// Flags used by lots of devices. Putting them in package static variables will save bytes in
24// build.ninja so they aren't repeated for every file
25var (
26 commonGlobalCflags = []string{
27 "-DANDROID",
28 "-fmessage-length=0",
29 "-W",
30 "-Wall",
31 "-Wno-unused",
32 "-Winit-self",
33 "-Wpointer-arith",
34
35 // COMMON_RELEASE_CFLAGS
36 "-DNDEBUG",
37 "-UDEBUG",
38 }
39
Colin Cross6f6a4282016-10-17 14:19:06 -070040 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -070041
Colin Cross4d9c2d12016-07-29 12:48:20 -070042 deviceGlobalCflags = []string{
43 "-fdiagnostics-color",
44
45 // TARGET_ERROR_FLAGS
46 "-Werror=return-type",
47 "-Werror=non-virtual-dtor",
48 "-Werror=address",
49 "-Werror=sequence-point",
50 "-Werror=date-time",
51 }
52
53 hostGlobalCflags = []string{}
54
55 commonGlobalCppflags = []string{
56 "-Wsign-promo",
57 }
58
59 noOverrideGlobalCflags = []string{
60 "-Werror=int-to-pointer-cast",
61 "-Werror=pointer-to-int-cast",
62 }
63
Colin Crossb98c8b02016-07-29 13:44:28 -070064 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -070065 "-w",
66 }
Colin Cross6f6a4282016-10-17 14:19:06 -070067
68 CStdVersion = "gnu99"
69 CppStdVersion = "gnu++14"
70 GccCppStdVersion = "gnu++11"
Colin Cross4d9c2d12016-07-29 12:48:20 -070071)
72
Colin Crossb98c8b02016-07-29 13:44:28 -070073var pctx = android.NewPackageContext("android/soong/cc/config")
74
Colin Cross4d9c2d12016-07-29 12:48:20 -070075func init() {
76 if android.BuildOs == android.Linux {
77 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
78 }
79
Colin Crossb98c8b02016-07-29 13:44:28 -070080 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070081 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070082 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
83 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
84 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070085
Colin Crossb98c8b02016-07-29 13:44:28 -070086 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070087
Colin Crossb98c8b02016-07-29 13:44:28 -070088 pctx.StaticVariable("CommonClangGlobalCflags",
89 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
90 pctx.StaticVariable("DeviceClangGlobalCflags",
91 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
92 pctx.StaticVariable("HostClangGlobalCflags",
93 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
94 pctx.StaticVariable("NoOverrideClangGlobalCflags",
95 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070096
Colin Crossb98c8b02016-07-29 13:44:28 -070097 pctx.StaticVariable("CommonClangGlobalCppflags",
98 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070099
Colin Cross1cfd89a2016-09-15 09:30:46 -0700100 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700101 // Do not add anything to this list.
Colin Cross1cfd89a2016-09-15 09:30:46 -0700102 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700103 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000104 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700105 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700106 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700107 "hardware/libhardware_legacy/include",
108 "hardware/ril/include",
109 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700110 "frameworks/native/include",
Colin Cross81b4ca62016-09-23 19:20:54 +0000111 })
112 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalSystemIncludes", "-isystem ",
113 []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700114 "frameworks/native/opengl/include",
115 "frameworks/av/include",
116 "frameworks/base/include",
117 })
118 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
119 // with this, since there is no associated library.
Colin Crossb98c8b02016-07-29 13:44:28 -0700120 pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700121 []string{"libnativehelper/include/nativehelper"})
122
Colin Crossb98c8b02016-07-29 13:44:28 -0700123 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
124 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700125 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
126 return override, nil
127 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700128 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700129 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700130 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700131 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
132 return override, nil
133 }
Stephen Hinesfdab9962016-09-28 08:52:48 -0700134 return "clang-3289846", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700135 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700136 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
137 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
138
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800139 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
140 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
141 return override, nil
142 }
143 return "3.8", nil
144 })
145 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700146
147 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
148 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
149 return override + " ", nil
150 }
151 return "", nil
152 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700153}
154
155var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
156
157func bionicHeaders(bionicArch, kernelArch string) string {
158 return strings.Join([]string{
159 "-isystem bionic/libc/arch-" + bionicArch + "/include",
160 "-isystem bionic/libc/include",
161 "-isystem bionic/libc/kernel/uapi",
162 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
163 "-isystem bionic/libc/kernel/android/uapi",
164 }, " ")
165}