blob: e254a1c894a16b39d2d2d037c8a688ead8f6bb30 [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
Dan Albert043833c2017-02-03 16:13:38 -080068 CStdVersion = "gnu99"
69 CppStdVersion = "gnu++14"
70 GccCppStdVersion = "gnu++11"
71 ExperimentalCStdVersion = "gnu11"
72 ExperimentalCppStdVersion = "gnu++1z"
Colin Cross4d9c2d12016-07-29 12:48:20 -070073)
74
Colin Crossb98c8b02016-07-29 13:44:28 -070075var pctx = android.NewPackageContext("android/soong/cc/config")
76
Colin Cross4d9c2d12016-07-29 12:48:20 -070077func init() {
78 if android.BuildOs == android.Linux {
79 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
80 }
81
Colin Crossb98c8b02016-07-29 13:44:28 -070082 pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
Elliott Hughes5a0401a2016-10-07 13:12:58 -070083 pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
Colin Crossb98c8b02016-07-29 13:44:28 -070084 pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
85 pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
86 pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070087
Colin Crossb98c8b02016-07-29 13:44:28 -070088 pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070089
Colin Crossb98c8b02016-07-29 13:44:28 -070090 pctx.StaticVariable("CommonClangGlobalCflags",
91 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " "))
92 pctx.StaticVariable("DeviceClangGlobalCflags",
93 strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " "))
94 pctx.StaticVariable("HostClangGlobalCflags",
95 strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
96 pctx.StaticVariable("NoOverrideClangGlobalCflags",
97 strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -070098
Colin Crossb98c8b02016-07-29 13:44:28 -070099 pctx.StaticVariable("CommonClangGlobalCppflags",
100 strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
Colin Cross4d9c2d12016-07-29 12:48:20 -0700101
Colin Cross1cfd89a2016-09-15 09:30:46 -0700102 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700103 // Do not add anything to this list.
Colin Cross1cfd89a2016-09-15 09:30:46 -0700104 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I",
Colin Crosse4bba1e2016-09-22 15:29:50 -0700105 []string{
Colin Cross763a26c2016-09-23 15:48:51 +0000106 "system/core/include",
Colin Cross19280932016-10-05 12:36:42 -0700107 "system/media/audio/include",
Colin Cross2d44c2c2016-10-05 12:36:42 -0700108 "hardware/libhardware/include",
Colin Cross328f04e2016-11-03 15:45:34 -0700109 "hardware/libhardware_legacy/include",
110 "hardware/ril/include",
111 "libnativehelper/include",
Colin Cross315a6ff2016-10-05 12:36:42 -0700112 "frameworks/native/include",
Colin Cross14e8dd72016-12-14 11:13:16 -0800113 "frameworks/native/opengl/include",
Colin Cross81b4ca62016-09-23 19:20:54 +0000114 })
115 pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalSystemIncludes", "-isystem ",
116 []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700117 "frameworks/av/include",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700118 })
119 // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
120 // with this, since there is no associated library.
Colin Crossb98c8b02016-07-29 13:44:28 -0700121 pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700122 []string{"libnativehelper/include/nativehelper"})
123
Colin Crossb98c8b02016-07-29 13:44:28 -0700124 pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host")
125 pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700126 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
127 return override, nil
128 }
Colin Crossb98c8b02016-07-29 13:44:28 -0700129 return "${ClangDefaultBase}", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700130 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700132 if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
133 return override, nil
134 }
Stephen Hinesd19f58a2017-01-26 00:49:41 -0800135 return "clang-3688880", nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700136 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
138 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
139
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800140 pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
141 if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
142 return override, nil
143 }
Stephen Hinesd19f58a2017-01-26 00:49:41 -0800144 return "4.0", nil
Stephen Hinese55a4cc2016-11-18 17:12:38 -0800145 })
146 pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700147
148 pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
149 if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
150 return override + " ", nil
151 }
152 return "", nil
153 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700154}
155
156var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
157
158func bionicHeaders(bionicArch, kernelArch string) string {
159 return strings.Join([]string{
160 "-isystem bionic/libc/arch-" + bionicArch + "/include",
161 "-isystem bionic/libc/include",
162 "-isystem bionic/libc/kernel/uapi",
163 "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
164 "-isystem bionic/libc/kernel/android/uapi",
165 }, " ")
166}
Dan Willemsend2ede872016-11-18 14:54:24 -0800167
168func VndkLibraries() []string {
169 return []string{}
170}