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 | |
| 40 | deviceGlobalCflags = []string{ |
| 41 | "-fdiagnostics-color", |
| 42 | |
| 43 | // TARGET_ERROR_FLAGS |
| 44 | "-Werror=return-type", |
| 45 | "-Werror=non-virtual-dtor", |
| 46 | "-Werror=address", |
| 47 | "-Werror=sequence-point", |
| 48 | "-Werror=date-time", |
| 49 | } |
| 50 | |
| 51 | hostGlobalCflags = []string{} |
| 52 | |
| 53 | commonGlobalCppflags = []string{ |
| 54 | "-Wsign-promo", |
| 55 | } |
| 56 | |
| 57 | noOverrideGlobalCflags = []string{ |
| 58 | "-Werror=int-to-pointer-cast", |
| 59 | "-Werror=pointer-to-int-cast", |
| 60 | } |
| 61 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 62 | IllegalFlags = []string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 63 | "-w", |
| 64 | } |
| 65 | ) |
| 66 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 67 | var pctx = android.NewPackageContext("android/soong/cc/config") |
| 68 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 69 | func init() { |
| 70 | if android.BuildOs == android.Linux { |
| 71 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") |
| 72 | } |
| 73 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 74 | pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
| 75 | pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
| 76 | pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
| 77 | pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 78 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 79 | pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 80 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 81 | pctx.StaticVariable("CommonClangGlobalCflags", |
| 82 | strings.Join(append(ClangFilterUnknownCflags(commonGlobalCflags), "${ClangExtraCflags}"), " ")) |
| 83 | pctx.StaticVariable("DeviceClangGlobalCflags", |
| 84 | strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")) |
| 85 | pctx.StaticVariable("HostClangGlobalCflags", |
| 86 | strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " ")) |
| 87 | pctx.StaticVariable("NoOverrideClangGlobalCflags", |
| 88 | strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 89 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 90 | pctx.StaticVariable("CommonClangGlobalCppflags", |
| 91 | strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " ")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 92 | |
| 93 | // Everything in this list is a crime against abstraction and dependency tracking. |
| 94 | // Do not add anything to this list. |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 95 | pctx.PrefixedPathsForOptionalSourceVariable("CommonGlobalIncludes", "-isystem ", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 96 | []string{ |
| 97 | "system/core/include", |
| 98 | "system/media/audio/include", |
| 99 | "hardware/libhardware/include", |
| 100 | "hardware/libhardware_legacy/include", |
| 101 | "hardware/ril/include", |
| 102 | "libnativehelper/include", |
| 103 | "frameworks/native/include", |
| 104 | "frameworks/native/opengl/include", |
| 105 | "frameworks/av/include", |
| 106 | "frameworks/base/include", |
| 107 | }) |
| 108 | // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help |
| 109 | // with this, since there is no associated library. |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 110 | pctx.PrefixedPathsForOptionalSourceVariable("CommonNativehelperInclude", "-I", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 111 | []string{"libnativehelper/include/nativehelper"}) |
| 112 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 113 | pctx.SourcePathVariable("ClangDefaultBase", "prebuilts/clang/host") |
| 114 | pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 115 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" { |
| 116 | return override, nil |
| 117 | } |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 118 | return "${ClangDefaultBase}", nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 119 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 120 | pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 121 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" { |
| 122 | return override, nil |
| 123 | } |
Pirama Arumuga Nainar | 15690c0 | 2016-08-24 09:44:55 -0700 | [diff] [blame] | 124 | return "clang-3217047", nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 125 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 126 | pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}") |
| 127 | pctx.StaticVariable("ClangBin", "${ClangPath}/bin") |
| 128 | |
| 129 | pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/3.8/lib/linux") |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame^] | 130 | |
| 131 | pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) { |
| 132 | if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" { |
| 133 | return override + " ", nil |
| 134 | } |
| 135 | return "", nil |
| 136 | }) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
| 140 | |
| 141 | func bionicHeaders(bionicArch, kernelArch string) string { |
| 142 | return strings.Join([]string{ |
| 143 | "-isystem bionic/libc/arch-" + bionicArch + "/include", |
| 144 | "-isystem bionic/libc/include", |
| 145 | "-isystem bionic/libc/kernel/uapi", |
| 146 | "-isystem bionic/libc/kernel/uapi/asm-" + kernelArch, |
| 147 | "-isystem bionic/libc/kernel/android/uapi", |
| 148 | }, " ") |
| 149 | } |