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 | |
| 37 | // COMMON_RELEASE_CFLAGS |
| 38 | "-DNDEBUG", |
| 39 | "-UDEBUG", |
| 40 | } |
| 41 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 42 | commonGlobalConlyflags = []string{} |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 43 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 44 | 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 Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 66 | IllegalFlags = []string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 67 | "-w", |
| 68 | } |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 69 | |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 70 | CStdVersion = "gnu99" |
| 71 | CppStdVersion = "gnu++14" |
| 72 | GccCppStdVersion = "gnu++11" |
| 73 | ExperimentalCStdVersion = "gnu11" |
| 74 | ExperimentalCppStdVersion = "gnu++1z" |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 75 | |
| 76 | NdkMaxPrebuiltVersionInt = 24 |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 77 | |
| 78 | // prebuilts/clang default settings. |
| 79 | ClangDefaultBase = "prebuilts/clang/host" |
Yi Kong | dadff1b | 2017-05-01 15:04:48 -0700 | [diff] [blame] | 80 | ClangDefaultVersion = "clang-4053586" |
| 81 | ClangDefaultShortVersion = "5.0" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 82 | ) |
| 83 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 84 | var pctx = android.NewPackageContext("android/soong/cc/config") |
| 85 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 86 | func init() { |
| 87 | if android.BuildOs == android.Linux { |
| 88 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") |
| 89 | } |
| 90 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 91 | pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 92 | pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 93 | pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
| 94 | pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
| 95 | pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 96 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 97 | pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 98 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 99 | 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 Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 107 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 108 | pctx.StaticVariable("CommonClangGlobalCppflags", |
| 109 | strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 110 | |
Colin Cross | 1cfd89a | 2016-09-15 09:30:46 -0700 | [diff] [blame] | 111 | // Everything in these lists is a crime against abstraction and dependency tracking. |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 112 | // Do not add anything to this list. |
Jeff Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 113 | pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", |
Colin Cross | e4bba1e | 2016-09-22 15:29:50 -0700 | [diff] [blame] | 114 | []string{ |
Colin Cross | 763a26c | 2016-09-23 15:48:51 +0000 | [diff] [blame] | 115 | "system/core/include", |
Colin Cross | 1928093 | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 116 | "system/media/audio/include", |
Colin Cross | 2d44c2c | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 117 | "hardware/libhardware/include", |
Colin Cross | 328f04e | 2016-11-03 15:45:34 -0700 | [diff] [blame] | 118 | "hardware/libhardware_legacy/include", |
| 119 | "hardware/ril/include", |
| 120 | "libnativehelper/include", |
Colin Cross | 315a6ff | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 121 | "frameworks/native/include", |
Colin Cross | 14e8dd7 | 2016-12-14 11:13:16 -0800 | [diff] [blame] | 122 | "frameworks/native/opengl/include", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 123 | "frameworks/av/include", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 124 | }) |
| 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 Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 127 | pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I", |
Steven Moreland | 3cf6306 | 2017-07-18 13:29:35 -0700 | [diff] [blame] | 128 | []string{"libnativehelper/include_deprecated"}) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 129 | |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 130 | pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 131 | pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 132 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" { |
| 133 | return override, nil |
| 134 | } |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 135 | return "${ClangDefaultBase}", nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 136 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 137 | pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 138 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" { |
| 139 | return override, nil |
| 140 | } |
Leo Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 141 | return ClangDefaultVersion, nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 142 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 143 | pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}") |
| 144 | pctx.StaticVariable("ClangBin", "${ClangPath}/bin") |
| 145 | |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame] | 146 | 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 Li | e748f5d | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 150 | return ClangDefaultShortVersion, nil |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame] | 151 | }) |
| 152 | pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/${ClangShortVersion}/lib/linux") |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame^] | 153 | if runtime.GOOS == "darwin" { |
| 154 | pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.dylib") |
| 155 | } else { |
| 156 | pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.so") |
| 157 | } |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 158 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 159 | // 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 Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 167 | pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I", |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 168 | []string{ |
| 169 | "external/clang/lib/Headers", |
| 170 | "frameworks/rs/script_api/include", |
| 171 | }) |
| 172 | |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 173 | 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 Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
| 182 | |
| 183 | func 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 Hughes | 98418a0 | 2017-05-25 17:16:10 -0700 | [diff] [blame] | 189 | "-isystem bionic/libc/kernel/android/scsi", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 190 | "-isystem bionic/libc/kernel/android/uapi", |
| 191 | }, " ") |
| 192 | } |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 193 | |
Alex Naidis | 5df73d0 | 2017-04-05 20:08:41 +0200 | [diff] [blame] | 194 | func 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 | } |