Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // 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 Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
Alex Naidis | 5df73d0 | 2017-04-05 20:08:41 +0200 | [diff] [blame] | 18 | "fmt" |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 19 | "runtime" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 25 | var ( |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 26 | // 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 Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 28 | commonGlobalCflags = []string{ |
| 29 | "-DANDROID", |
| 30 | "-fmessage-length=0", |
| 31 | "-W", |
| 32 | "-Wall", |
| 33 | "-Wno-unused", |
| 34 | "-Winit-self", |
| 35 | "-Wpointer-arith", |
| 36 | |
Colin Cross | 7278afc | 2017-11-02 22:38:32 -0700 | [diff] [blame] | 37 | // Make paths in deps files relative |
| 38 | "-no-canonical-prefixes", |
| 39 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 40 | "-DNDEBUG", |
| 41 | "-UDEBUG", |
Colin Cross | 7278afc | 2017-11-02 22:38:32 -0700 | [diff] [blame] | 42 | |
| 43 | "-fno-exceptions", |
| 44 | "-Wno-multichar", |
| 45 | |
| 46 | "-O2", |
| 47 | "-g", |
| 48 | |
| 49 | "-fno-strict-aliasing", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 52 | commonGlobalConlyflags = []string{} |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 53 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 54 | deviceGlobalCflags = []string{ |
| 55 | "-fdiagnostics-color", |
| 56 | |
Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 57 | "-fno-canonical-system-headers", |
| 58 | "-ffunction-sections", |
| 59 | "-funwind-tables", |
| 60 | "-fstack-protector-strong", |
| 61 | "-Wa,--noexecstack", |
| 62 | "-D_FORTIFY_SOURCE=2", |
| 63 | |
| 64 | "-Wstrict-aliasing=2", |
| 65 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 66 | "-Werror=return-type", |
| 67 | "-Werror=non-virtual-dtor", |
| 68 | "-Werror=address", |
| 69 | "-Werror=sequence-point", |
| 70 | "-Werror=date-time", |
Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 71 | "-Werror=format-security", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame^] | 74 | deviceGlobalLdflags = []string{ |
| 75 | "-Wl,-z,noexecstack", |
| 76 | "-Wl,-z,relro", |
| 77 | "-Wl,-z,now", |
| 78 | "-Wl,--build-id=md5", |
| 79 | "-Wl,--warn-shared-textrel", |
| 80 | "-Wl,--fatal-warnings", |
| 81 | "-Wl,--no-undefined-version", |
| 82 | } |
| 83 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 84 | hostGlobalCflags = []string{} |
| 85 | |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame^] | 86 | hostGlobalLdflags = []string{} |
| 87 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 88 | commonGlobalCppflags = []string{ |
| 89 | "-Wsign-promo", |
| 90 | } |
| 91 | |
| 92 | noOverrideGlobalCflags = []string{ |
| 93 | "-Werror=int-to-pointer-cast", |
| 94 | "-Werror=pointer-to-int-cast", |
| 95 | } |
| 96 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 97 | IllegalFlags = []string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 98 | "-w", |
| 99 | } |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 100 | |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 101 | CStdVersion = "gnu99" |
| 102 | CppStdVersion = "gnu++14" |
| 103 | GccCppStdVersion = "gnu++11" |
| 104 | ExperimentalCStdVersion = "gnu11" |
| 105 | ExperimentalCppStdVersion = "gnu++1z" |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 106 | |
| 107 | NdkMaxPrebuiltVersionInt = 24 |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 108 | |
| 109 | // prebuilts/clang default settings. |
| 110 | ClangDefaultBase = "prebuilts/clang/host" |
Stephen Hines | 0ed7d24 | 2017-10-04 16:12:37 -0700 | [diff] [blame] | 111 | ClangDefaultVersion = "clang-4393122" |
| 112 | ClangDefaultShortVersion = "5.0.1" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 113 | ) |
| 114 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 115 | var pctx = android.NewPackageContext("android/soong/cc/config") |
| 116 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 117 | func init() { |
| 118 | if android.BuildOs == android.Linux { |
| 119 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") |
| 120 | } |
| 121 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 122 | pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 123 | pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 124 | pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame^] | 125 | pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 126 | pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame^] | 127 | pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 128 | pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 129 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 130 | pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 131 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 132 | pctx.StaticVariable("CommonClangGlobalCflags", |
| 133 | strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " ")) |
| 134 | pctx.StaticVariable("DeviceClangGlobalCflags", |
| 135 | strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")) |
| 136 | pctx.StaticVariable("HostClangGlobalCflags", |
| 137 | strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " ")) |
| 138 | pctx.StaticVariable("NoOverrideClangGlobalCflags", |
| 139 | strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 140 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 141 | pctx.StaticVariable("CommonClangGlobalCppflags", |
| 142 | strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 143 | |
Colin Cross | 1cfd89a | 2016-09-15 09:30:46 -0700 | [diff] [blame] | 144 | // Everything in these lists is a crime against abstraction and dependency tracking. |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 145 | // Do not add anything to this list. |
Jeff Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 146 | pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", |
Colin Cross | e4bba1e | 2016-09-22 15:29:50 -0700 | [diff] [blame] | 147 | []string{ |
Colin Cross | 763a26c | 2016-09-23 15:48:51 +0000 | [diff] [blame] | 148 | "system/core/include", |
Colin Cross | 1928093 | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 149 | "system/media/audio/include", |
Colin Cross | 2d44c2c | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 150 | "hardware/libhardware/include", |
Colin Cross | 328f04e | 2016-11-03 15:45:34 -0700 | [diff] [blame] | 151 | "hardware/libhardware_legacy/include", |
| 152 | "hardware/ril/include", |
| 153 | "libnativehelper/include", |
Colin Cross | 315a6ff | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 154 | "frameworks/native/include", |
Colin Cross | 14e8dd7 | 2016-12-14 11:13:16 -0800 | [diff] [blame] | 155 | "frameworks/native/opengl/include", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 156 | "frameworks/av/include", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 157 | }) |
| 158 | // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help |
| 159 | // with this, since there is no associated library. |
Jeff Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 160 | pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I", |
Steven Moreland | 3cf6306 | 2017-07-18 13:29:35 -0700 | [diff] [blame] | 161 | []string{"libnativehelper/include_deprecated"}) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 162 | |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 163 | pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 164 | pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 165 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" { |
| 166 | return override, nil |
| 167 | } |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 168 | return "${ClangDefaultBase}", nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 169 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 170 | pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 171 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" { |
| 172 | return override, nil |
| 173 | } |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 174 | return ClangDefaultVersion, nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 175 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 176 | pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}") |
| 177 | pctx.StaticVariable("ClangBin", "${ClangPath}/bin") |
| 178 | |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame] | 179 | pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) { |
| 180 | if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" { |
| 181 | return override, nil |
| 182 | } |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 183 | return ClangDefaultShortVersion, nil |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame] | 184 | }) |
| 185 | pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux") |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 186 | if runtime.GOOS == "darwin" { |
| 187 | pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.dylib") |
| 188 | } else { |
| 189 | pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.so") |
| 190 | } |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 191 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 192 | // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts |
| 193 | // being used for the rest of the build process. |
| 194 | pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host") |
| 195 | pctx.SourcePathVariable("RSClangVersion", "clang-3289846") |
| 196 | pctx.SourcePathVariable("RSReleaseVersion", "3.8") |
| 197 | pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin") |
| 198 | pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include") |
| 199 | |
Jeff Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 200 | pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I", |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 201 | []string{ |
| 202 | "external/clang/lib/Headers", |
| 203 | "frameworks/rs/script_api/include", |
| 204 | }) |
| 205 | |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 206 | pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) { |
| 207 | if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" { |
| 208 | return override + " ", nil |
| 209 | } |
| 210 | return "", nil |
| 211 | }) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
| 215 | |
Elliott Hughes | de28deb | 2017-10-12 09:07:53 -0700 | [diff] [blame] | 216 | func bionicHeaders(kernelArch string) string { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 217 | return strings.Join([]string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 218 | "-isystem bionic/libc/include", |
| 219 | "-isystem bionic/libc/kernel/uapi", |
| 220 | "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch, |
Elliott Hughes | 98418a0 | 2017-05-25 17:16:10 -0700 | [diff] [blame] | 221 | "-isystem bionic/libc/kernel/android/scsi", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 222 | "-isystem bionic/libc/kernel/android/uapi", |
| 223 | }, " ") |
| 224 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 225 | |
Alex Naidis | 5df73d0 | 2017-04-05 20:08:41 +0200 | [diff] [blame] | 226 | func replaceFirst(slice []string, from, to string) { |
| 227 | if slice[0] != from { |
| 228 | panic(fmt.Errorf("Expected %q, found %q", from, to)) |
| 229 | } |
| 230 | slice[0] = to |
| 231 | } |