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 ( |
| 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 |
| 25 | var ( |
| 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 Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 40 | commonGlobalConlyflags = []string{} |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 41 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 42 | 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 Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 64 | IllegalFlags = []string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 65 | "-w", |
| 66 | } |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 67 | |
| 68 | CStdVersion = "gnu99" |
| 69 | CppStdVersion = "gnu++14" |
| 70 | GccCppStdVersion = "gnu++11" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 71 | ) |
| 72 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 73 | var pctx = android.NewPackageContext("android/soong/cc/config") |
| 74 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 75 | func init() { |
| 76 | if android.BuildOs == android.Linux { |
| 77 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") |
| 78 | } |
| 79 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 80 | pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 81 | pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 82 | pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
| 83 | pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
| 84 | pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 85 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 86 | pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 87 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 88 | 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 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("CommonClangGlobalCppflags", |
| 98 | strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 99 | |
Colin Cross | 1cfd89a | 2016-09-15 09:30:46 -0700 | [diff] [blame] | 100 | // Everything in these lists is a crime against abstraction and dependency tracking. |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 101 | // Do not add anything to this list. |
Colin Cross | 1cfd89a | 2016-09-15 09:30:46 -0700 | [diff] [blame] | 102 | pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-I", |
Colin Cross | e4bba1e | 2016-09-22 15:29:50 -0700 | [diff] [blame] | 103 | []string{ |
Colin Cross | 763a26c | 2016-09-23 15:48:51 +0000 | [diff] [blame] | 104 | "system/core/include", |
Colin Cross | 1928093 | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 105 | "system/media/audio/include", |
Colin Cross | 2d44c2c | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 106 | "hardware/libhardware/include", |
Colin Cross | 328f04e | 2016-11-03 15:45:34 -0700 | [diff] [blame] | 107 | "hardware/libhardware_legacy/include", |
| 108 | "hardware/ril/include", |
| 109 | "libnativehelper/include", |
Colin Cross | 315a6ff | 2016-10-05 12:36:42 -0700 | [diff] [blame] | 110 | "frameworks/native/include", |
Colin Cross | 81b4ca6 | 2016-09-23 19:20:54 +0000 | [diff] [blame] | 111 | }) |
| 112 | pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalSystemIncludes", "-isystem ", |
| 113 | []string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 114 | "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 Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 120 | pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 121 | []string{"libnativehelper/include/nativehelper"}) |
| 122 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 123 | pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host") |
| 124 | pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 125 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" { |
| 126 | return override, nil |
| 127 | } |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 128 | return "${ClangDefaultBase}", nil |
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.VariableFunc("ClangVersion", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 131 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" { |
| 132 | return override, nil |
| 133 | } |
Stephen Hines | fdab996 | 2016-09-28 08:52:48 -0700 | [diff] [blame] | 134 | return "clang-3289846", nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 135 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 136 | pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}") |
| 137 | pctx.StaticVariable("ClangBin", "${ClangPath}/bin") |
| 138 | |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame^] | 139 | 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 Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 146 | |
| 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 Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
| 156 | |
| 157 | func 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 | } |