Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | // This file contains the module types for compiling C/C++ for Android, and converts the properties |
| 18 | // into the flags and filenames necessary to pass to the compiler. The final creation of the rules |
| 19 | // is handled in builder.go |
| 20 | |
| 21 | import ( |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | "fmt" |
| 23 | "path/filepath" |
| 24 | "strings" |
| 25 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 28 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 29 | "android/soong" |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 30 | "android/soong/android" |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 31 | "android/soong/genrule" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 32 | ) |
| 33 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 34 | func init() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 35 | soong.RegisterModuleType("cc_library_static", libraryStaticFactory) |
| 36 | soong.RegisterModuleType("cc_library_shared", librarySharedFactory) |
| 37 | soong.RegisterModuleType("cc_library", libraryFactory) |
| 38 | soong.RegisterModuleType("cc_object", objectFactory) |
| 39 | soong.RegisterModuleType("cc_binary", binaryFactory) |
| 40 | soong.RegisterModuleType("cc_test", testFactory) |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 41 | soong.RegisterModuleType("cc_test_library", testLibraryFactory) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 42 | soong.RegisterModuleType("cc_benchmark", benchmarkFactory) |
| 43 | soong.RegisterModuleType("cc_defaults", defaultsFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 44 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 45 | soong.RegisterModuleType("toolchain_library", toolchainLibraryFactory) |
| 46 | soong.RegisterModuleType("ndk_prebuilt_library", ndkPrebuiltLibraryFactory) |
| 47 | soong.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory) |
| 48 | soong.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory) |
| 49 | soong.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 50 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 51 | soong.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory) |
| 52 | soong.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory) |
| 53 | soong.RegisterModuleType("cc_binary_host", binaryHostFactory) |
| 54 | soong.RegisterModuleType("cc_test_host", testHostFactory) |
| 55 | soong.RegisterModuleType("cc_benchmark_host", benchmarkHostFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 56 | |
| 57 | // LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by |
| 58 | // the Go initialization order because this package depends on common, so common's init |
| 59 | // functions will run first. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 60 | android.RegisterBottomUpMutator("link", linkageMutator) |
| 61 | android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator) |
| 62 | android.RegisterBottomUpMutator("deps", depsMutator) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 63 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 64 | android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan)) |
| 65 | android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 66 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 67 | android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan)) |
| 68 | android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 71 | var ( |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 72 | HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 73 | ) |
| 74 | |
| 75 | // Flags used by lots of devices. Putting them in package static variables will save bytes in |
| 76 | // build.ninja so they aren't repeated for every file |
| 77 | var ( |
| 78 | commonGlobalCflags = []string{ |
| 79 | "-DANDROID", |
| 80 | "-fmessage-length=0", |
| 81 | "-W", |
| 82 | "-Wall", |
| 83 | "-Wno-unused", |
| 84 | "-Winit-self", |
| 85 | "-Wpointer-arith", |
| 86 | |
| 87 | // COMMON_RELEASE_CFLAGS |
| 88 | "-DNDEBUG", |
| 89 | "-UDEBUG", |
| 90 | } |
| 91 | |
| 92 | deviceGlobalCflags = []string{ |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 93 | "-fdiagnostics-color", |
| 94 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 95 | // TARGET_ERROR_FLAGS |
| 96 | "-Werror=return-type", |
| 97 | "-Werror=non-virtual-dtor", |
| 98 | "-Werror=address", |
| 99 | "-Werror=sequence-point", |
Dan Willemsen | a6084a3 | 2016-03-01 15:16:50 -0800 | [diff] [blame] | 100 | "-Werror=date-time", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | hostGlobalCflags = []string{} |
| 104 | |
| 105 | commonGlobalCppflags = []string{ |
| 106 | "-Wsign-promo", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 109 | noOverrideGlobalCflags = []string{ |
| 110 | "-Werror=int-to-pointer-cast", |
| 111 | "-Werror=pointer-to-int-cast", |
| 112 | } |
| 113 | |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 114 | illegalFlags = []string{ |
| 115 | "-w", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 116 | } |
Dan Willemsen | 97704ed | 2016-07-07 21:40:39 -0700 | [diff] [blame] | 117 | |
| 118 | ndkPrebuiltSharedLibs = []string{ |
| 119 | "android", |
| 120 | "c", |
| 121 | "dl", |
| 122 | "EGL", |
| 123 | "GLESv1_CM", |
| 124 | "GLESv2", |
| 125 | "GLESv3", |
| 126 | "jnigraphics", |
| 127 | "log", |
| 128 | "mediandk", |
| 129 | "m", |
| 130 | "OpenMAXAL", |
| 131 | "OpenSLES", |
| 132 | "stdc++", |
| 133 | "vulkan", |
| 134 | "z", |
| 135 | } |
| 136 | ndkPrebuiltSharedLibraries = addPrefix(append([]string(nil), ndkPrebuiltSharedLibs...), "lib") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 137 | ) |
| 138 | |
| 139 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 140 | if android.BuildOs == android.Linux { |
Dan Willemsen | 0c38c5e | 2016-03-29 17:31:57 -0700 | [diff] [blame] | 141 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") |
| 142 | } |
| 143 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 144 | pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
| 145 | pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
| 146 | pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 147 | pctx.StaticVariable("noOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 148 | |
| 149 | pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
| 150 | |
| 151 | pctx.StaticVariable("commonClangGlobalCflags", |
Dan Willemsen | ac5e1cb | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 152 | strings.Join(append(clangFilterUnknownCflags(commonGlobalCflags), "${clangExtraCflags}"), " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 153 | pctx.StaticVariable("deviceClangGlobalCflags", |
Dan Willemsen | ac5e1cb | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 154 | strings.Join(append(clangFilterUnknownCflags(deviceGlobalCflags), "${clangExtraTargetCflags}"), " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 155 | pctx.StaticVariable("hostClangGlobalCflags", |
| 156 | strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " ")) |
Dan Willemsen | be03f34 | 2016-03-03 17:21:04 -0800 | [diff] [blame] | 157 | pctx.StaticVariable("noOverrideClangGlobalCflags", |
| 158 | strings.Join(append(clangFilterUnknownCflags(noOverrideGlobalCflags), "${clangExtraNoOverrideCflags}"), " ")) |
| 159 | |
Tim Kilbourn | f294814 | 2015-03-11 12:03:03 -0700 | [diff] [blame] | 160 | pctx.StaticVariable("commonClangGlobalCppflags", |
Dan Willemsen | ac5e1cb | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 161 | strings.Join(append(clangFilterUnknownCflags(commonGlobalCppflags), "${clangExtraCppflags}"), " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 162 | |
| 163 | // Everything in this list is a crime against abstraction and dependency tracking. |
| 164 | // Do not add anything to this list. |
Dan Willemsen | 7b310ee | 2015-12-18 15:11:17 -0800 | [diff] [blame] | 165 | pctx.PrefixedPathsForOptionalSourceVariable("commonGlobalIncludes", "-isystem ", |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 166 | []string{ |
| 167 | "system/core/include", |
Dan Willemsen | 98f93c7 | 2016-03-01 15:27:03 -0800 | [diff] [blame] | 168 | "system/media/audio/include", |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 169 | "hardware/libhardware/include", |
| 170 | "hardware/libhardware_legacy/include", |
| 171 | "hardware/ril/include", |
| 172 | "libnativehelper/include", |
| 173 | "frameworks/native/include", |
| 174 | "frameworks/native/opengl/include", |
| 175 | "frameworks/av/include", |
| 176 | "frameworks/base/include", |
| 177 | }) |
Dan Willemsen | e0378dd | 2016-01-07 17:42:34 -0800 | [diff] [blame] | 178 | // This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help |
| 179 | // with this, since there is no associated library. |
| 180 | pctx.PrefixedPathsForOptionalSourceVariable("commonNativehelperInclude", "-I", |
| 181 | []string{"libnativehelper/include/nativehelper"}) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 182 | |
Dan Willemsen | dc5d28a | 2016-03-16 11:37:17 -0700 | [diff] [blame] | 183 | pctx.SourcePathVariable("clangDefaultBase", "prebuilts/clang/host") |
| 184 | pctx.VariableFunc("clangBase", func(config interface{}) (string, error) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 185 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" { |
Dan Willemsen | dc5d28a | 2016-03-16 11:37:17 -0700 | [diff] [blame] | 186 | return override, nil |
| 187 | } |
| 188 | return "${clangDefaultBase}", nil |
| 189 | }) |
| 190 | pctx.VariableFunc("clangVersion", func(config interface{}) (string, error) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 191 | if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" { |
Dan Willemsen | dc5d28a | 2016-03-16 11:37:17 -0700 | [diff] [blame] | 192 | return override, nil |
| 193 | } |
Pirama Arumuga Nainar | a17442b | 2016-06-28 11:00:12 -0700 | [diff] [blame] | 194 | return "clang-3016494", nil |
Dan Willemsen | dc5d28a | 2016-03-16 11:37:17 -0700 | [diff] [blame] | 195 | }) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 196 | pctx.StaticVariable("clangPath", "${clangBase}/${HostPrebuiltTag}/${clangVersion}") |
| 197 | pctx.StaticVariable("clangBin", "${clangPath}/bin") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 200 | type Deps struct { |
| 201 | SharedLibs, LateSharedLibs []string |
| 202 | StaticLibs, LateStaticLibs, WholeStaticLibs []string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 203 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 204 | ReexportSharedLibHeaders, ReexportStaticLibHeaders []string |
| 205 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 206 | ObjFiles []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 207 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 208 | GeneratedSources []string |
| 209 | GeneratedHeaders []string |
| 210 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 211 | CrtBegin, CrtEnd string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 214 | type PathDeps struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 215 | SharedLibs, LateSharedLibs android.Paths |
| 216 | StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 217 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 218 | ObjFiles android.Paths |
| 219 | WholeStaticLibObjFiles android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 220 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 221 | GeneratedSources android.Paths |
| 222 | GeneratedHeaders android.Paths |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 223 | |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 224 | Flags, ReexportedFlags []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 225 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 226 | CrtBegin, CrtEnd android.OptionalPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 229 | type Flags struct { |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 230 | GlobalFlags []string // Flags that apply to C, C++, and assembly source files |
| 231 | AsFlags []string // Flags that apply to assembly source files |
| 232 | CFlags []string // Flags that apply to C and C++ source files |
| 233 | ConlyFlags []string // Flags that apply to C source files |
| 234 | CppFlags []string // Flags that apply to C++ source files |
| 235 | YaccFlags []string // Flags that apply to Yacc source files |
| 236 | LdFlags []string // Flags that apply to linker command lines |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 237 | libFlags []string // Flags to add libraries early to the link order |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 238 | |
| 239 | Nocrt bool |
| 240 | Toolchain Toolchain |
| 241 | Clang bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 242 | |
| 243 | RequiredInstructionSet string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 244 | DynamicLinker string |
| 245 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 246 | CFlagsDeps android.Paths // Files depended on by compiler flags |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 249 | type BaseCompilerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 250 | // list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files. |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 251 | Srcs []string `android:"arch_variant"` |
| 252 | |
| 253 | // list of source files that should not be used to build the C/C++ module. |
| 254 | // This is most useful in the arch/multilib variants to remove non-common files |
| 255 | Exclude_srcs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 256 | |
| 257 | // list of module-specific flags that will be used for C and C++ compiles. |
| 258 | Cflags []string `android:"arch_variant"` |
| 259 | |
| 260 | // list of module-specific flags that will be used for C++ compiles |
| 261 | Cppflags []string `android:"arch_variant"` |
| 262 | |
| 263 | // list of module-specific flags that will be used for C compiles |
| 264 | Conlyflags []string `android:"arch_variant"` |
| 265 | |
| 266 | // list of module-specific flags that will be used for .S compiles |
| 267 | Asflags []string `android:"arch_variant"` |
| 268 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 269 | // list of module-specific flags that will be used for C and C++ compiles when |
| 270 | // compiling with clang |
| 271 | Clang_cflags []string `android:"arch_variant"` |
| 272 | |
| 273 | // list of module-specific flags that will be used for .S compiles when |
| 274 | // compiling with clang |
| 275 | Clang_asflags []string `android:"arch_variant"` |
| 276 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 277 | // list of module-specific flags that will be used for .y and .yy compiles |
| 278 | Yaccflags []string |
| 279 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 280 | // the instruction set architecture to use to compile the C/C++ |
| 281 | // module. |
| 282 | Instruction_set string `android:"arch_variant"` |
| 283 | |
| 284 | // list of directories relative to the root of the source tree that will |
| 285 | // be added to the include path using -I. |
| 286 | // If possible, don't use this. If adding paths from the current directory use |
| 287 | // local_include_dirs, if adding paths from other modules use export_include_dirs in |
| 288 | // that module. |
| 289 | Include_dirs []string `android:"arch_variant"` |
| 290 | |
| 291 | // list of directories relative to the Blueprints file that will |
| 292 | // be added to the include path using -I |
| 293 | Local_include_dirs []string `android:"arch_variant"` |
| 294 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 295 | // list of generated sources to compile. These are the names of gensrcs or |
| 296 | // genrule modules. |
| 297 | Generated_sources []string `android:"arch_variant"` |
| 298 | |
| 299 | // list of generated headers to add to the include path. These are the names |
| 300 | // of genrule modules. |
| 301 | Generated_headers []string `android:"arch_variant"` |
| 302 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 303 | // pass -frtti instead of -fno-rtti |
| 304 | Rtti *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 305 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 306 | Debug, Release struct { |
| 307 | // list of module-specific flags that will be used for C and C++ compiles in debug or |
| 308 | // release builds |
| 309 | Cflags []string `android:"arch_variant"` |
| 310 | } `android:"arch_variant"` |
| 311 | } |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 312 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 313 | type BaseLinkerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 314 | // list of modules whose object files should be linked into this module |
| 315 | // in their entirety. For static library modules, all of the .o files from the intermediate |
| 316 | // directory of the dependency will be linked into this modules .a file. For a shared library, |
| 317 | // the dependency's .a file will be linked into this module using -Wl,--whole-archive. |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 318 | Whole_static_libs []string `android:"arch_variant,variant_prepend"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 319 | |
| 320 | // list of modules that should be statically linked into this module. |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 321 | Static_libs []string `android:"arch_variant,variant_prepend"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 322 | |
| 323 | // list of modules that should be dynamically linked into this module. |
| 324 | Shared_libs []string `android:"arch_variant"` |
| 325 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 326 | // list of module-specific flags that will be used for all link steps |
| 327 | Ldflags []string `android:"arch_variant"` |
| 328 | |
| 329 | // don't insert default compiler flags into asflags, cflags, |
| 330 | // cppflags, conlyflags, ldflags, or include_dirs |
| 331 | No_default_compiler_flags *bool |
| 332 | |
| 333 | // list of system libraries that will be dynamically linked to |
| 334 | // shared library and executable modules. If unset, generally defaults to libc |
| 335 | // and libm. Set to [] to prevent linking against libc and libm. |
| 336 | System_shared_libs []string |
| 337 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 338 | // allow the module to contain undefined symbols. By default, |
| 339 | // modules cannot contain undefined symbols that are not satisified by their immediate |
| 340 | // dependencies. Set this flag to true to remove --no-undefined from the linker flags. |
| 341 | // This flag should only be necessary for compiling low-level libraries like libc. |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 342 | Allow_undefined_symbols *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 343 | |
Dan Willemsen | d67be22 | 2015-09-16 15:19:33 -0700 | [diff] [blame] | 344 | // don't link in libgcc.a |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 345 | No_libgcc *bool |
Dan Willemsen | d67be22 | 2015-09-16 15:19:33 -0700 | [diff] [blame] | 346 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 347 | // -l arguments to pass to linker for host-provided shared libraries |
| 348 | Host_ldlibs []string `android:"arch_variant"` |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 349 | |
| 350 | // list of shared libraries to re-export include directories from. Entries must be |
| 351 | // present in shared_libs. |
| 352 | Export_shared_lib_headers []string `android:"arch_variant"` |
| 353 | |
| 354 | // list of static libraries to re-export include directories from. Entries must be |
| 355 | // present in static_libs. |
| 356 | Export_static_lib_headers []string `android:"arch_variant"` |
Colin Cross | a89d2e1 | 2016-01-11 12:48:37 -0800 | [diff] [blame] | 357 | |
| 358 | // don't link in crt_begin and crt_end. This flag should only be necessary for |
| 359 | // compiling crt or libc. |
| 360 | Nocrt *bool `android:"arch_variant"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 361 | } |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 362 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 363 | type LibraryCompilerProperties struct { |
| 364 | Static struct { |
| 365 | Srcs []string `android:"arch_variant"` |
| 366 | Exclude_srcs []string `android:"arch_variant"` |
| 367 | Cflags []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 368 | } `android:"arch_variant"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 369 | Shared struct { |
| 370 | Srcs []string `android:"arch_variant"` |
| 371 | Exclude_srcs []string `android:"arch_variant"` |
| 372 | Cflags []string `android:"arch_variant"` |
| 373 | } `android:"arch_variant"` |
| 374 | } |
| 375 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 376 | type FlagExporterProperties struct { |
| 377 | // list of directories relative to the Blueprints file that will |
| 378 | // be added to the include path using -I for any module that links against this module |
| 379 | Export_include_dirs []string `android:"arch_variant"` |
| 380 | } |
| 381 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 382 | type LibraryLinkerProperties struct { |
| 383 | Static struct { |
Dan Willemsen | fed4d19 | 2016-07-06 21:48:39 -0700 | [diff] [blame] | 384 | Enabled *bool `android:"arch_variant"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 385 | Whole_static_libs []string `android:"arch_variant"` |
| 386 | Static_libs []string `android:"arch_variant"` |
| 387 | Shared_libs []string `android:"arch_variant"` |
| 388 | } `android:"arch_variant"` |
| 389 | Shared struct { |
Dan Willemsen | fed4d19 | 2016-07-06 21:48:39 -0700 | [diff] [blame] | 390 | Enabled *bool `android:"arch_variant"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 391 | Whole_static_libs []string `android:"arch_variant"` |
| 392 | Static_libs []string `android:"arch_variant"` |
| 393 | Shared_libs []string `android:"arch_variant"` |
| 394 | } `android:"arch_variant"` |
| 395 | |
| 396 | // local file name to pass to the linker as --version_script |
| 397 | Version_script *string `android:"arch_variant"` |
| 398 | // local file name to pass to the linker as -unexported_symbols_list |
| 399 | Unexported_symbols_list *string `android:"arch_variant"` |
| 400 | // local file name to pass to the linker as -force_symbols_not_weak_list |
| 401 | Force_symbols_not_weak_list *string `android:"arch_variant"` |
| 402 | // local file name to pass to the linker as -force_symbols_weak_list |
| 403 | Force_symbols_weak_list *string `android:"arch_variant"` |
| 404 | |
Dan Willemsen | 648c8ae | 2016-07-21 16:42:14 -0700 | [diff] [blame] | 405 | // rename host libraries to prevent overlap with system installed libraries |
| 406 | Unique_host_soname *bool |
| 407 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 408 | VariantName string `blueprint:"mutated"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | type BinaryLinkerProperties struct { |
| 412 | // compile executable with -static |
Dan Willemsen | 75ab808 | 2016-07-12 15:36:34 -0700 | [diff] [blame] | 413 | Static_executable *bool `android:"arch_variant"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 414 | |
| 415 | // set the name of the output |
| 416 | Stem string `android:"arch_variant"` |
| 417 | |
| 418 | // append to the name of the output |
| 419 | Suffix string `android:"arch_variant"` |
| 420 | |
| 421 | // if set, add an extra objcopy --prefix-symbols= step |
| 422 | Prefix_symbols string |
| 423 | } |
| 424 | |
| 425 | type TestLinkerProperties struct { |
| 426 | // if set, build against the gtest library. Defaults to true. |
| 427 | Gtest bool |
| 428 | |
| 429 | // Create a separate binary for each source file. Useful when there is |
| 430 | // global state that can not be torn down and reset between each test suite. |
| 431 | Test_per_src *bool |
| 432 | } |
| 433 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 434 | type ObjectLinkerProperties struct { |
| 435 | // names of other cc_object modules to link into this module using partial linking |
| 436 | Objs []string `android:"arch_variant"` |
| 437 | } |
| 438 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 439 | // Properties used to compile all C or C++ modules |
| 440 | type BaseProperties struct { |
| 441 | // compile module with clang instead of gcc |
| 442 | Clang *bool `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 443 | |
| 444 | // Minimum sdk version supported when compiling against the ndk |
| 445 | Sdk_version string |
| 446 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 447 | // don't insert default compiler flags into asflags, cflags, |
| 448 | // cppflags, conlyflags, ldflags, or include_dirs |
| 449 | No_default_compiler_flags *bool |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 450 | |
| 451 | AndroidMkSharedLibs []string `blueprint:"mutated"` |
Colin Cross | bc6fb16 | 2016-05-24 15:39:04 -0700 | [diff] [blame] | 452 | HideFromMake bool `blueprint:"mutated"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | type InstallerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 456 | // install to a subdirectory of the default install path for the module |
| 457 | Relative_install_path string |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 458 | |
| 459 | // install symlinks to the module |
| 460 | Symlinks []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 463 | type StripProperties struct { |
| 464 | Strip struct { |
| 465 | None bool |
| 466 | Keep_symbols bool |
| 467 | } |
| 468 | } |
| 469 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 470 | type UnusedProperties struct { |
Colin Cross | 21b481b | 2016-04-15 16:27:17 -0700 | [diff] [blame] | 471 | Native_coverage *bool |
| 472 | Required []string |
Colin Cross | 21b481b | 2016-04-15 16:27:17 -0700 | [diff] [blame] | 473 | Tags []string |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 476 | type ModuleContextIntf interface { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 477 | static() bool |
| 478 | staticBinary() bool |
| 479 | clang() bool |
| 480 | toolchain() Toolchain |
| 481 | noDefaultCompilerFlags() bool |
| 482 | sdk() bool |
| 483 | sdkVersion() string |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 484 | selectedStl() string |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | type ModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 488 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 489 | ModuleContextIntf |
| 490 | } |
| 491 | |
| 492 | type BaseModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 493 | android.BaseContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 494 | ModuleContextIntf |
| 495 | } |
| 496 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 497 | type CustomizerFlagsContext interface { |
| 498 | BaseModuleContext |
| 499 | AppendCflags(...string) |
| 500 | AppendLdflags(...string) |
| 501 | AppendAsflags(...string) |
| 502 | } |
| 503 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 504 | type Customizer interface { |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 505 | Flags(CustomizerFlagsContext) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 506 | Properties() []interface{} |
| 507 | } |
| 508 | |
| 509 | type feature interface { |
| 510 | begin(ctx BaseModuleContext) |
| 511 | deps(ctx BaseModuleContext, deps Deps) Deps |
| 512 | flags(ctx ModuleContext, flags Flags) Flags |
| 513 | props() []interface{} |
| 514 | } |
| 515 | |
| 516 | type compiler interface { |
| 517 | feature |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 518 | appendCflags([]string) |
| 519 | appendAsflags([]string) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 520 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | type linker interface { |
| 524 | feature |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 525 | link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 526 | appendLdflags([]string) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 527 | installable() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | type installer interface { |
| 531 | props() []interface{} |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 532 | install(ctx ModuleContext, path android.Path) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 533 | inData() bool |
| 534 | } |
| 535 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 536 | type dependencyTag struct { |
| 537 | blueprint.BaseDependencyTag |
| 538 | name string |
| 539 | library bool |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 540 | |
| 541 | reexportFlags bool |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | var ( |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 545 | sharedDepTag = dependencyTag{name: "shared", library: true} |
| 546 | sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true} |
| 547 | lateSharedDepTag = dependencyTag{name: "late shared", library: true} |
| 548 | staticDepTag = dependencyTag{name: "static", library: true} |
| 549 | staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} |
| 550 | lateStaticDepTag = dependencyTag{name: "late static", library: true} |
| 551 | wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} |
| 552 | genSourceDepTag = dependencyTag{name: "gen source"} |
| 553 | genHeaderDepTag = dependencyTag{name: "gen header"} |
| 554 | objDepTag = dependencyTag{name: "obj"} |
| 555 | crtBeginDepTag = dependencyTag{name: "crtbegin"} |
| 556 | crtEndDepTag = dependencyTag{name: "crtend"} |
| 557 | reuseObjTag = dependencyTag{name: "reuse objects"} |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 558 | ) |
| 559 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 560 | // Module contains the properties and members used by all C/C++ module types, and implements |
| 561 | // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces |
| 562 | // to construct the output file. Behavior can be customized with a Customizer interface |
| 563 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 564 | android.ModuleBase |
| 565 | android.DefaultableModule |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 566 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 567 | Properties BaseProperties |
| 568 | unused UnusedProperties |
Colin Cross | fa13879 | 2015-04-24 17:31:52 -0700 | [diff] [blame] | 569 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 570 | // initialize before calling Init |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 571 | hod android.HostOrDeviceSupported |
| 572 | multilib android.Multilib |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 573 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 574 | // delegates, initialize before calling Init |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 575 | Customizer Customizer |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 576 | features []feature |
| 577 | compiler compiler |
| 578 | linker linker |
| 579 | installer installer |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 580 | stl *stl |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 581 | sanitize *sanitize |
| 582 | |
| 583 | androidMkSharedLibDeps []string |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 584 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 585 | outputFile android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 586 | |
| 587 | cachedToolchain Toolchain |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 590 | func (c *Module) Init() (blueprint.Module, []interface{}) { |
| 591 | props := []interface{}{&c.Properties, &c.unused} |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 592 | if c.Customizer != nil { |
| 593 | props = append(props, c.Customizer.Properties()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 594 | } |
| 595 | if c.compiler != nil { |
| 596 | props = append(props, c.compiler.props()...) |
| 597 | } |
| 598 | if c.linker != nil { |
| 599 | props = append(props, c.linker.props()...) |
| 600 | } |
| 601 | if c.installer != nil { |
| 602 | props = append(props, c.installer.props()...) |
| 603 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 604 | if c.stl != nil { |
| 605 | props = append(props, c.stl.props()...) |
| 606 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 607 | if c.sanitize != nil { |
| 608 | props = append(props, c.sanitize.props()...) |
| 609 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 610 | for _, feature := range c.features { |
| 611 | props = append(props, feature.props()...) |
| 612 | } |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 613 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 614 | _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...) |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 615 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 616 | return android.InitDefaultableModule(c, c, props...) |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 619 | type baseModuleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 620 | android.BaseContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 621 | moduleContextImpl |
| 622 | } |
| 623 | |
| 624 | type moduleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 625 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 626 | moduleContextImpl |
| 627 | } |
| 628 | |
| 629 | type moduleContextImpl struct { |
| 630 | mod *Module |
| 631 | ctx BaseModuleContext |
| 632 | } |
| 633 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 634 | func (ctx *moduleContextImpl) AppendCflags(flags ...string) { |
| 635 | CheckBadCompilerFlags(ctx.ctx, "", flags) |
| 636 | ctx.mod.compiler.appendCflags(flags) |
| 637 | } |
| 638 | |
| 639 | func (ctx *moduleContextImpl) AppendAsflags(flags ...string) { |
| 640 | CheckBadCompilerFlags(ctx.ctx, "", flags) |
| 641 | ctx.mod.compiler.appendAsflags(flags) |
| 642 | } |
| 643 | |
| 644 | func (ctx *moduleContextImpl) AppendLdflags(flags ...string) { |
| 645 | CheckBadLinkerFlags(ctx.ctx, "", flags) |
| 646 | ctx.mod.linker.appendLdflags(flags) |
| 647 | } |
| 648 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 649 | func (ctx *moduleContextImpl) clang() bool { |
| 650 | return ctx.mod.clang(ctx.ctx) |
| 651 | } |
| 652 | |
| 653 | func (ctx *moduleContextImpl) toolchain() Toolchain { |
| 654 | return ctx.mod.toolchain(ctx.ctx) |
| 655 | } |
| 656 | |
| 657 | func (ctx *moduleContextImpl) static() bool { |
| 658 | if ctx.mod.linker == nil { |
| 659 | panic(fmt.Errorf("static called on module %q with no linker", ctx.ctx.ModuleName())) |
| 660 | } |
| 661 | if linker, ok := ctx.mod.linker.(baseLinkerInterface); ok { |
| 662 | return linker.static() |
| 663 | } else { |
| 664 | panic(fmt.Errorf("static called on module %q that doesn't use base linker", ctx.ctx.ModuleName())) |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | func (ctx *moduleContextImpl) staticBinary() bool { |
| 669 | if ctx.mod.linker == nil { |
| 670 | panic(fmt.Errorf("staticBinary called on module %q with no linker", ctx.ctx.ModuleName())) |
| 671 | } |
| 672 | if linker, ok := ctx.mod.linker.(baseLinkerInterface); ok { |
| 673 | return linker.staticBinary() |
| 674 | } else { |
| 675 | panic(fmt.Errorf("staticBinary called on module %q that doesn't use base linker", ctx.ctx.ModuleName())) |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool { |
| 680 | return Bool(ctx.mod.Properties.No_default_compiler_flags) |
| 681 | } |
| 682 | |
| 683 | func (ctx *moduleContextImpl) sdk() bool { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 684 | if ctx.ctx.Device() { |
| 685 | return ctx.mod.Properties.Sdk_version != "" |
| 686 | } |
| 687 | return false |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | func (ctx *moduleContextImpl) sdkVersion() string { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 691 | if ctx.ctx.Device() { |
| 692 | return ctx.mod.Properties.Sdk_version |
| 693 | } |
| 694 | return "" |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 695 | } |
| 696 | |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 697 | func (ctx *moduleContextImpl) selectedStl() string { |
| 698 | if stl := ctx.mod.stl; stl != nil { |
| 699 | return stl.Properties.SelectedStl |
| 700 | } |
| 701 | return "" |
| 702 | } |
| 703 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 704 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 705 | return &Module{ |
| 706 | hod: hod, |
| 707 | multilib: multilib, |
| 708 | } |
| 709 | } |
| 710 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 711 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 712 | module := newBaseModule(hod, multilib) |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 713 | module.stl = &stl{} |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 714 | module.sanitize = &sanitize{} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 715 | return module |
| 716 | } |
| 717 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 718 | func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 719 | ctx := &moduleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 720 | ModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 721 | moduleContextImpl: moduleContextImpl{ |
| 722 | mod: c, |
| 723 | }, |
| 724 | } |
| 725 | ctx.ctx = ctx |
| 726 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 727 | if c.Customizer != nil { |
| 728 | c.Customizer.Flags(ctx) |
| 729 | } |
| 730 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 731 | flags := Flags{ |
| 732 | Toolchain: c.toolchain(ctx), |
| 733 | Clang: c.clang(ctx), |
| 734 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 735 | if c.compiler != nil { |
| 736 | flags = c.compiler.flags(ctx, flags) |
| 737 | } |
| 738 | if c.linker != nil { |
| 739 | flags = c.linker.flags(ctx, flags) |
| 740 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 741 | if c.stl != nil { |
| 742 | flags = c.stl.flags(ctx, flags) |
| 743 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 744 | if c.sanitize != nil { |
| 745 | flags = c.sanitize.flags(ctx, flags) |
| 746 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 747 | for _, feature := range c.features { |
| 748 | flags = feature.flags(ctx, flags) |
| 749 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 750 | if ctx.Failed() { |
| 751 | return |
| 752 | } |
| 753 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 754 | flags.CFlags, _ = filterList(flags.CFlags, illegalFlags) |
| 755 | flags.CppFlags, _ = filterList(flags.CppFlags, illegalFlags) |
| 756 | flags.ConlyFlags, _ = filterList(flags.ConlyFlags, illegalFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 757 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 758 | // Optimization to reduce size of build.ninja |
| 759 | // Replace the long list of flags for each file with a module-local variable |
| 760 | ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " ")) |
| 761 | ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " ")) |
| 762 | ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " ")) |
| 763 | flags.CFlags = []string{"$cflags"} |
| 764 | flags.CppFlags = []string{"$cppflags"} |
| 765 | flags.AsFlags = []string{"$asflags"} |
| 766 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 767 | deps := c.depsToPaths(ctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 768 | if ctx.Failed() { |
| 769 | return |
| 770 | } |
| 771 | |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 772 | flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...) |
Colin Cross | ed9f868 | 2015-03-18 17:17:35 -0700 | [diff] [blame] | 773 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 774 | var objFiles android.Paths |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 775 | if c.compiler != nil { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 776 | objFiles = c.compiler.compile(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 777 | if ctx.Failed() { |
| 778 | return |
| 779 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 782 | if c.linker != nil { |
| 783 | outputFile := c.linker.link(ctx, flags, deps, objFiles) |
| 784 | if ctx.Failed() { |
| 785 | return |
| 786 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 787 | c.outputFile = android.OptionalPathForPath(outputFile) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 788 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 789 | if c.installer != nil && c.linker.installable() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 790 | c.installer.install(ctx, outputFile) |
| 791 | if ctx.Failed() { |
| 792 | return |
| 793 | } |
| 794 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 795 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 798 | func (c *Module) toolchain(ctx BaseModuleContext) Toolchain { |
| 799 | if c.cachedToolchain == nil { |
| 800 | arch := ctx.Arch() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 801 | os := ctx.Os() |
| 802 | factory := toolchainFactories[os][arch.ArchType] |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 803 | if factory == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 804 | ctx.ModuleErrorf("Toolchain not found for %s arch %q", os.String(), arch.String()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 805 | return nil |
| 806 | } |
| 807 | c.cachedToolchain = factory(arch) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 808 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 809 | return c.cachedToolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 810 | } |
| 811 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 812 | func (c *Module) begin(ctx BaseModuleContext) { |
| 813 | if c.compiler != nil { |
| 814 | c.compiler.begin(ctx) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 815 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 816 | if c.linker != nil { |
| 817 | c.linker.begin(ctx) |
| 818 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 819 | if c.stl != nil { |
| 820 | c.stl.begin(ctx) |
| 821 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 822 | if c.sanitize != nil { |
| 823 | c.sanitize.begin(ctx) |
| 824 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 825 | for _, feature := range c.features { |
| 826 | feature.begin(ctx) |
| 827 | } |
| 828 | } |
| 829 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 830 | func (c *Module) deps(ctx BaseModuleContext) Deps { |
| 831 | deps := Deps{} |
| 832 | |
| 833 | if c.compiler != nil { |
| 834 | deps = c.compiler.deps(ctx, deps) |
| 835 | } |
| 836 | if c.linker != nil { |
| 837 | deps = c.linker.deps(ctx, deps) |
| 838 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 839 | if c.stl != nil { |
| 840 | deps = c.stl.deps(ctx, deps) |
| 841 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 842 | if c.sanitize != nil { |
| 843 | deps = c.sanitize.deps(ctx, deps) |
| 844 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 845 | for _, feature := range c.features { |
| 846 | deps = feature.deps(ctx, deps) |
| 847 | } |
| 848 | |
| 849 | deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs) |
| 850 | deps.StaticLibs = lastUniqueElements(deps.StaticLibs) |
| 851 | deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs) |
| 852 | deps.SharedLibs = lastUniqueElements(deps.SharedLibs) |
| 853 | deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs) |
| 854 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 855 | for _, lib := range deps.ReexportSharedLibHeaders { |
| 856 | if !inList(lib, deps.SharedLibs) { |
| 857 | ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | for _, lib := range deps.ReexportStaticLibHeaders { |
| 862 | if !inList(lib, deps.StaticLibs) { |
| 863 | ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib) |
| 864 | } |
| 865 | } |
| 866 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 867 | return deps |
| 868 | } |
| 869 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 870 | func (c *Module) depsMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 871 | ctx := &baseModuleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 872 | BaseContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 873 | moduleContextImpl: moduleContextImpl{ |
| 874 | mod: c, |
| 875 | }, |
| 876 | } |
| 877 | ctx.ctx = ctx |
| 878 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 879 | c.begin(ctx) |
| 880 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 881 | deps := c.deps(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 882 | |
Colin Cross | b5bc4b4 | 2016-07-11 16:11:59 -0700 | [diff] [blame] | 883 | c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...) |
| 884 | c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 885 | |
| 886 | if ctx.sdk() { |
| 887 | version := "." + ctx.sdkVersion() |
| 888 | |
| 889 | rewriteNdkLibs := func(list []string) []string { |
| 890 | for i, entry := range list { |
| 891 | if inList(entry, ndkPrebuiltSharedLibraries) { |
| 892 | list[i] = "ndk_" + entry + version |
| 893 | } |
| 894 | } |
| 895 | return list |
| 896 | } |
| 897 | |
| 898 | deps.SharedLibs = rewriteNdkLibs(deps.SharedLibs) |
| 899 | deps.LateSharedLibs = rewriteNdkLibs(deps.LateSharedLibs) |
| 900 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 901 | |
| 902 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag, |
| 903 | deps.WholeStaticLibs...) |
| 904 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 905 | for _, lib := range deps.StaticLibs { |
| 906 | depTag := staticDepTag |
| 907 | if inList(lib, deps.ReexportStaticLibHeaders) { |
| 908 | depTag = staticExportDepTag |
| 909 | } |
Colin Cross | 15a0d46 | 2016-07-14 14:49:58 -0700 | [diff] [blame] | 910 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 911 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 912 | |
| 913 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag, |
| 914 | deps.LateStaticLibs...) |
| 915 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 916 | for _, lib := range deps.SharedLibs { |
| 917 | depTag := sharedDepTag |
| 918 | if inList(lib, deps.ReexportSharedLibHeaders) { |
| 919 | depTag = sharedExportDepTag |
| 920 | } |
Colin Cross | 15a0d46 | 2016-07-14 14:49:58 -0700 | [diff] [blame] | 921 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 922 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 923 | |
| 924 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag, |
| 925 | deps.LateSharedLibs...) |
| 926 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 927 | actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) |
| 928 | actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 929 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 930 | actx.AddDependency(c, objDepTag, deps.ObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 931 | |
| 932 | if deps.CrtBegin != "" { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 933 | actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 934 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 935 | if deps.CrtEnd != "" { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 936 | actx.AddDependency(c, crtEndDepTag, deps.CrtEnd) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 937 | } |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 938 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 939 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 940 | func depsMutator(ctx android.BottomUpMutatorContext) { |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 941 | if c, ok := ctx.Module().(*Module); ok && c.Enabled() { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 942 | c.depsMutator(ctx) |
| 943 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 946 | func (c *Module) clang(ctx BaseModuleContext) bool { |
| 947 | clang := Bool(c.Properties.Clang) |
| 948 | |
| 949 | if c.Properties.Clang == nil { |
| 950 | if ctx.Host() { |
| 951 | clang = true |
| 952 | } |
| 953 | |
| 954 | if ctx.Device() && ctx.AConfig().DeviceUsesClang() { |
| 955 | clang = true |
| 956 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 957 | } |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 958 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 959 | if !c.toolchain(ctx).ClangSupported() { |
| 960 | clang = false |
| 961 | } |
| 962 | |
| 963 | return clang |
| 964 | } |
| 965 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 966 | // Convert dependencies to paths. Returns a PathDeps containing paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 967 | func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 968 | var depPaths PathDeps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 969 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 970 | // Whether a module can link to another module, taking into |
| 971 | // account NDK linking. |
| 972 | linkTypeOk := func(from, to *Module) bool { |
| 973 | if from.Target().Os != android.Android { |
| 974 | // Host code is not restricted |
| 975 | return true |
| 976 | } |
| 977 | if from.Properties.Sdk_version == "" { |
| 978 | // Platform code can link to anything |
| 979 | return true |
| 980 | } |
| 981 | if _, ok := to.linker.(*toolchainLibraryLinker); ok { |
| 982 | // These are always allowed |
| 983 | return true |
| 984 | } |
| 985 | if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok { |
| 986 | // These are allowed, but don't set sdk_version |
| 987 | return true |
| 988 | } |
Dan Willemsen | 3c316bc | 2016-07-07 20:41:36 -0700 | [diff] [blame] | 989 | if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok { |
| 990 | // These are allowed, but don't set sdk_version |
| 991 | return true |
| 992 | } |
| 993 | return to.Properties.Sdk_version != "" |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 996 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 997 | name := ctx.OtherModuleName(m) |
| 998 | tag := ctx.OtherModuleDependencyTag(m) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 999 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1000 | a, _ := m.(android.Module) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1001 | if a == nil { |
| 1002 | ctx.ModuleErrorf("module %q not an android module", name) |
| 1003 | return |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1004 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1005 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1006 | cc, _ := m.(*Module) |
| 1007 | if cc == nil { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1008 | switch tag { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1009 | case android.DefaultsDepTag: |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1010 | case genSourceDepTag: |
| 1011 | if genRule, ok := m.(genrule.SourceFileGenerator); ok { |
| 1012 | depPaths.GeneratedSources = append(depPaths.GeneratedSources, |
| 1013 | genRule.GeneratedSourceFiles()...) |
| 1014 | } else { |
| 1015 | ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name) |
| 1016 | } |
| 1017 | case genHeaderDepTag: |
| 1018 | if genRule, ok := m.(genrule.SourceFileGenerator); ok { |
| 1019 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, |
| 1020 | genRule.GeneratedSourceFiles()...) |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1021 | depPaths.Flags = append(depPaths.Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1022 | includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1023 | } else { |
| 1024 | ctx.ModuleErrorf("module %q is not a genrule", name) |
| 1025 | } |
| 1026 | default: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1027 | ctx.ModuleErrorf("depends on non-cc module %q", name) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1028 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1029 | return |
| 1030 | } |
| 1031 | |
| 1032 | if !a.Enabled() { |
| 1033 | ctx.ModuleErrorf("depends on disabled module %q", name) |
| 1034 | return |
| 1035 | } |
| 1036 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1037 | if a.Target().Os != ctx.Os() { |
| 1038 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name) |
| 1039 | return |
| 1040 | } |
| 1041 | |
| 1042 | if a.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1043 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1044 | return |
| 1045 | } |
| 1046 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1047 | if !cc.outputFile.Valid() { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1048 | ctx.ModuleErrorf("module %q missing output file", name) |
| 1049 | return |
| 1050 | } |
| 1051 | |
| 1052 | if tag == reuseObjTag { |
| 1053 | depPaths.ObjFiles = append(depPaths.ObjFiles, |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1054 | cc.compiler.(*libraryCompiler).reuseObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1055 | return |
| 1056 | } |
| 1057 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1058 | if t, ok := tag.(dependencyTag); ok && t.library { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1059 | if i, ok := cc.linker.(exportedFlagsProducer); ok { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1060 | flags := i.exportedFlags() |
| 1061 | depPaths.Flags = append(depPaths.Flags, flags...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1062 | |
| 1063 | if t.reexportFlags { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1064 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1065 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1066 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1067 | |
| 1068 | if !linkTypeOk(c, cc) { |
| 1069 | ctx.ModuleErrorf("depends on non-NDK-built library %q", name) |
| 1070 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1073 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1074 | |
| 1075 | switch tag { |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1076 | case sharedDepTag, sharedExportDepTag: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1077 | depPtr = &depPaths.SharedLibs |
| 1078 | case lateSharedDepTag: |
| 1079 | depPtr = &depPaths.LateSharedLibs |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1080 | case staticDepTag, staticExportDepTag: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1081 | depPtr = &depPaths.StaticLibs |
| 1082 | case lateStaticDepTag: |
| 1083 | depPtr = &depPaths.LateStaticLibs |
| 1084 | case wholeStaticDepTag: |
| 1085 | depPtr = &depPaths.WholeStaticLibs |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 1086 | staticLib, _ := cc.linker.(libraryInterface) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1087 | if staticLib == nil || !staticLib.static() { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1088 | ctx.ModuleErrorf("module %q not a static library", name) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1089 | return |
| 1090 | } |
| 1091 | |
| 1092 | if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { |
| 1093 | postfix := " (required by " + ctx.OtherModuleName(m) + ")" |
| 1094 | for i := range missingDeps { |
| 1095 | missingDeps[i] += postfix |
| 1096 | } |
| 1097 | ctx.AddMissingDependencies(missingDeps) |
| 1098 | } |
| 1099 | depPaths.WholeStaticLibObjFiles = |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 1100 | append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1101 | case objDepTag: |
| 1102 | depPtr = &depPaths.ObjFiles |
| 1103 | case crtBeginDepTag: |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1104 | depPaths.CrtBegin = cc.outputFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1105 | case crtEndDepTag: |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1106 | depPaths.CrtEnd = cc.outputFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1107 | default: |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1108 | panic(fmt.Errorf("unknown dependency tag: %s", tag)) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | if depPtr != nil { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1112 | *depPtr = append(*depPtr, cc.outputFile.Path()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1113 | } |
| 1114 | }) |
| 1115 | |
| 1116 | return depPaths |
| 1117 | } |
| 1118 | |
| 1119 | func (c *Module) InstallInData() bool { |
| 1120 | if c.installer == nil { |
| 1121 | return false |
| 1122 | } |
| 1123 | return c.installer.inData() |
| 1124 | } |
| 1125 | |
| 1126 | // Compiler |
| 1127 | |
| 1128 | type baseCompiler struct { |
| 1129 | Properties BaseCompilerProperties |
| 1130 | } |
| 1131 | |
| 1132 | var _ compiler = (*baseCompiler)(nil) |
| 1133 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 1134 | func (compiler *baseCompiler) appendCflags(flags []string) { |
| 1135 | compiler.Properties.Cflags = append(compiler.Properties.Cflags, flags...) |
| 1136 | } |
| 1137 | |
| 1138 | func (compiler *baseCompiler) appendAsflags(flags []string) { |
| 1139 | compiler.Properties.Asflags = append(compiler.Properties.Asflags, flags...) |
| 1140 | } |
| 1141 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1142 | func (compiler *baseCompiler) props() []interface{} { |
| 1143 | return []interface{}{&compiler.Properties} |
| 1144 | } |
| 1145 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1146 | func (compiler *baseCompiler) begin(ctx BaseModuleContext) {} |
| 1147 | |
| 1148 | func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1149 | deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...) |
| 1150 | deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...) |
| 1151 | |
| 1152 | return deps |
| 1153 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1154 | |
| 1155 | // Create a Flags struct that collects the compile flags from global values, |
| 1156 | // per-target values, module type values, and per-module Blueprints properties |
| 1157 | func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags { |
| 1158 | toolchain := ctx.toolchain() |
| 1159 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1160 | CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags) |
| 1161 | CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags) |
| 1162 | CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags) |
| 1163 | CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags) |
| 1164 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1165 | flags.CFlags = append(flags.CFlags, compiler.Properties.Cflags...) |
| 1166 | flags.CppFlags = append(flags.CppFlags, compiler.Properties.Cppflags...) |
| 1167 | flags.ConlyFlags = append(flags.ConlyFlags, compiler.Properties.Conlyflags...) |
| 1168 | flags.AsFlags = append(flags.AsFlags, compiler.Properties.Asflags...) |
| 1169 | flags.YaccFlags = append(flags.YaccFlags, compiler.Properties.Yaccflags...) |
| 1170 | |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1171 | // Include dir cflags |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1172 | rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs) |
| 1173 | localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs) |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1174 | flags.GlobalFlags = append(flags.GlobalFlags, |
Dan Willemsen | 1e898b9 | 2015-09-23 15:26:32 -0700 | [diff] [blame] | 1175 | includeDirsToFlags(localIncludeDirs), |
| 1176 | includeDirsToFlags(rootIncludeDirs)) |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1177 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1178 | if !ctx.noDefaultCompilerFlags() { |
| 1179 | if !ctx.sdk() || ctx.Host() { |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1180 | flags.GlobalFlags = append(flags.GlobalFlags, |
| 1181 | "${commonGlobalIncludes}", |
| 1182 | toolchain.IncludeFlags(), |
Dan Willemsen | e0378dd | 2016-01-07 17:42:34 -0800 | [diff] [blame] | 1183 | "${commonNativehelperInclude}") |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | flags.GlobalFlags = append(flags.GlobalFlags, []string{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1187 | "-I" + android.PathForModuleSrc(ctx).String(), |
| 1188 | "-I" + android.PathForModuleOut(ctx).String(), |
| 1189 | "-I" + android.PathForModuleGen(ctx).String(), |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1190 | }...) |
| 1191 | } |
| 1192 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1193 | instructionSet := compiler.Properties.Instruction_set |
| 1194 | if flags.RequiredInstructionSet != "" { |
| 1195 | instructionSet = flags.RequiredInstructionSet |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1196 | } |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 1197 | instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet) |
| 1198 | if flags.Clang { |
| 1199 | instructionSetFlags, err = toolchain.ClangInstructionSetFlags(instructionSet) |
| 1200 | } |
| 1201 | if err != nil { |
| 1202 | ctx.ModuleErrorf("%s", err) |
| 1203 | } |
| 1204 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1205 | CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) |
| 1206 | |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 1207 | // TODO: debug |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1208 | flags.CFlags = append(flags.CFlags, compiler.Properties.Release.Cflags...) |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 1209 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1210 | if flags.Clang { |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1211 | CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags) |
| 1212 | CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags) |
| 1213 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1214 | flags.CFlags = clangFilterUnknownCflags(flags.CFlags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1215 | flags.CFlags = append(flags.CFlags, compiler.Properties.Clang_cflags...) |
| 1216 | flags.AsFlags = append(flags.AsFlags, compiler.Properties.Clang_asflags...) |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1217 | flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags) |
| 1218 | flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags) |
| 1219 | flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1220 | |
| 1221 | target := "-target " + toolchain.ClangTriple() |
Dan Willemsen | 3772da1 | 2016-05-16 18:01:46 -0700 | [diff] [blame] | 1222 | var gccPrefix string |
| 1223 | if !ctx.Darwin() { |
| 1224 | gccPrefix = "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin") |
| 1225 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1226 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1227 | flags.CFlags = append(flags.CFlags, target, gccPrefix) |
| 1228 | flags.AsFlags = append(flags.AsFlags, target, gccPrefix) |
| 1229 | flags.LdFlags = append(flags.LdFlags, target, gccPrefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1232 | hod := "host" |
| 1233 | if ctx.Os().Class == android.Device { |
| 1234 | hod = "device" |
| 1235 | } |
| 1236 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1237 | if !ctx.noDefaultCompilerFlags() { |
Colin Cross | 56b4d45 | 2015-04-21 17:38:44 -0700 | [diff] [blame] | 1238 | flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) |
| 1239 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1240 | if flags.Clang { |
Dan Willemsen | 32968a2 | 2016-01-12 22:25:34 -0800 | [diff] [blame] | 1241 | flags.AsFlags = append(flags.AsFlags, toolchain.ClangAsflags()) |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1242 | flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}") |
Colin Cross | 56b4d45 | 2015-04-21 17:38:44 -0700 | [diff] [blame] | 1243 | flags.GlobalFlags = append(flags.GlobalFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1244 | toolchain.ClangCflags(), |
| 1245 | "${commonClangGlobalCflags}", |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1246 | fmt.Sprintf("${%sClangGlobalCflags}", hod)) |
Dan Willemsen | ac5e1cb | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 1247 | |
| 1248 | flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1249 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1250 | flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}") |
Colin Cross | 56b4d45 | 2015-04-21 17:38:44 -0700 | [diff] [blame] | 1251 | flags.GlobalFlags = append(flags.GlobalFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1252 | toolchain.Cflags(), |
| 1253 | "${commonGlobalCflags}", |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1254 | fmt.Sprintf("${%sGlobalCflags}", hod)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
Colin Cross | 7b66f15 | 2015-12-15 16:07:43 -0800 | [diff] [blame] | 1257 | if Bool(ctx.AConfig().ProductVariables.Brillo) { |
| 1258 | flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__") |
| 1259 | } |
| 1260 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1261 | if ctx.Device() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1262 | if Bool(compiler.Properties.Rtti) { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1263 | flags.CppFlags = append(flags.CppFlags, "-frtti") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1264 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1265 | flags.CppFlags = append(flags.CppFlags, "-fno-rtti") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1269 | flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1270 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1271 | if flags.Clang { |
| 1272 | flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1273 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1274 | flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags()) |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1275 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 1278 | if flags.Clang { |
| 1279 | flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainClangCflags()) |
| 1280 | } else { |
| 1281 | flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainCflags()) |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1284 | if !ctx.sdk() { |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 1285 | if ctx.Host() && !flags.Clang { |
| 1286 | // The host GCC doesn't support C++14 (and is deprecated, so likely |
| 1287 | // never will). Build these modules with C++11. |
| 1288 | flags.CppFlags = append(flags.CppFlags, "-std=gnu++11") |
| 1289 | } else { |
| 1290 | flags.CppFlags = append(flags.CppFlags, "-std=gnu++14") |
| 1291 | } |
| 1292 | } |
| 1293 | |
Dan Willemsen | 52b1cd2 | 2016-03-01 13:36:34 -0800 | [diff] [blame] | 1294 | // We can enforce some rules more strictly in the code we own. strict |
| 1295 | // indicates if this is code that we can be stricter with. If we have |
| 1296 | // rules that we want to apply to *our* code (but maybe can't for |
| 1297 | // vendor/device specific things), we could extend this to be a ternary |
| 1298 | // value. |
| 1299 | strict := true |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1300 | if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { |
Dan Willemsen | 52b1cd2 | 2016-03-01 13:36:34 -0800 | [diff] [blame] | 1301 | strict = false |
| 1302 | } |
| 1303 | |
| 1304 | // Can be used to make some annotations stricter for code we can fix |
| 1305 | // (such as when we mark functions as deprecated). |
| 1306 | if strict { |
| 1307 | flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT") |
| 1308 | } |
| 1309 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1310 | return flags |
| 1311 | } |
| 1312 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1313 | func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1314 | // Compile files listed in c.Properties.Srcs into objects |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1315 | objFiles := compiler.compileObjs(ctx, flags, "", |
| 1316 | compiler.Properties.Srcs, compiler.Properties.Exclude_srcs, |
| 1317 | deps.GeneratedSources, deps.GeneratedHeaders) |
| 1318 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1319 | if ctx.Failed() { |
| 1320 | return nil |
| 1321 | } |
| 1322 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1323 | return objFiles |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | // Compile a list of source files into objects a specified subdirectory |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1327 | func (compiler *baseCompiler) compileObjs(ctx android.ModuleContext, flags Flags, |
| 1328 | subdir string, srcFiles, excludes []string, extraSrcs, deps android.Paths) android.Paths { |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 1329 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1330 | buildFlags := flagsToBuilderFlags(flags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1331 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1332 | inputFiles := ctx.ExpandSources(srcFiles, excludes) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1333 | inputFiles = append(inputFiles, extraSrcs...) |
| 1334 | srcPaths, gendeps := genSources(ctx, inputFiles, buildFlags) |
| 1335 | |
| 1336 | deps = append(deps, gendeps...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1337 | deps = append(deps, flags.CFlagsDeps...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1338 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1339 | return TransformSourceToObj(ctx, subdir, srcPaths, buildFlags, deps) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1342 | // baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties |
| 1343 | type baseLinker struct { |
| 1344 | Properties BaseLinkerProperties |
| 1345 | dynamicProperties struct { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1346 | VariantIsShared bool `blueprint:"mutated"` |
| 1347 | VariantIsStatic bool `blueprint:"mutated"` |
| 1348 | VariantIsStaticBinary bool `blueprint:"mutated"` |
| 1349 | RunPaths []string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1350 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 1353 | func (linker *baseLinker) appendLdflags(flags []string) { |
| 1354 | linker.Properties.Ldflags = append(linker.Properties.Ldflags, flags...) |
| 1355 | } |
| 1356 | |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1357 | func (linker *baseLinker) begin(ctx BaseModuleContext) { |
| 1358 | if ctx.toolchain().Is64Bit() { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1359 | linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"} |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1360 | } else { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1361 | linker.dynamicProperties.RunPaths = []string{"../lib", "lib"} |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1362 | } |
| 1363 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1364 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1365 | func (linker *baseLinker) props() []interface{} { |
| 1366 | return []interface{}{&linker.Properties, &linker.dynamicProperties} |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1369 | func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1370 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...) |
| 1371 | deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...) |
| 1372 | deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1373 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1374 | deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...) |
| 1375 | deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...) |
| 1376 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1377 | if !ctx.sdk() && ctx.ModuleName() != "libcompiler_rt-extras" { |
Stephen Hines | 1034786 | 2016-07-18 15:54:54 -0700 | [diff] [blame] | 1378 | deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt-extras") |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1381 | if ctx.Device() { |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 1382 | // libgcc and libatomic have to be last on the command line |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1383 | deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic") |
| 1384 | if !Bool(linker.Properties.No_libgcc) { |
| 1385 | deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc") |
Dan Willemsen | d67be22 | 2015-09-16 15:19:33 -0700 | [diff] [blame] | 1386 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1387 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1388 | if !linker.static() { |
| 1389 | if linker.Properties.System_shared_libs != nil { |
| 1390 | deps.LateSharedLibs = append(deps.LateSharedLibs, |
| 1391 | linker.Properties.System_shared_libs...) |
| 1392 | } else if !ctx.sdk() { |
| 1393 | deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm") |
| 1394 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1395 | } |
Colin Cross | 577f6e4 | 2015-03-27 18:23:34 -0700 | [diff] [blame] | 1396 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1397 | if ctx.sdk() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1398 | deps.SharedLibs = append(deps.SharedLibs, |
Dan Willemsen | 97704ed | 2016-07-07 21:40:39 -0700 | [diff] [blame] | 1399 | "libc", |
| 1400 | "libm", |
Colin Cross | 577f6e4 | 2015-03-27 18:23:34 -0700 | [diff] [blame] | 1401 | ) |
| 1402 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1405 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1408 | func (linker *baseLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 1409 | toolchain := ctx.toolchain() |
| 1410 | |
Colin Cross | a89d2e1 | 2016-01-11 12:48:37 -0800 | [diff] [blame] | 1411 | flags.Nocrt = Bool(linker.Properties.Nocrt) |
| 1412 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1413 | if !ctx.noDefaultCompilerFlags() { |
| 1414 | if ctx.Device() && !Bool(linker.Properties.Allow_undefined_symbols) { |
| 1415 | flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") |
| 1416 | } |
| 1417 | |
| 1418 | if flags.Clang { |
| 1419 | flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags()) |
| 1420 | } else { |
| 1421 | flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags()) |
| 1422 | } |
| 1423 | |
| 1424 | if ctx.Host() { |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1425 | CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs) |
| 1426 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1427 | flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...) |
| 1428 | } |
| 1429 | } |
| 1430 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1431 | CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags) |
| 1432 | |
Dan Willemsen | 00ced76 | 2016-05-10 17:31:21 -0700 | [diff] [blame] | 1433 | flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...) |
| 1434 | |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1435 | if ctx.Host() && !linker.static() { |
| 1436 | rpath_prefix := `\$$ORIGIN/` |
| 1437 | if ctx.Darwin() { |
| 1438 | rpath_prefix = "@loader_path/" |
| 1439 | } |
| 1440 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1441 | for _, rpath := range linker.dynamicProperties.RunPaths { |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1442 | flags.LdFlags = append(flags.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath) |
| 1443 | } |
| 1444 | } |
| 1445 | |
Dan Willemsen | e717492 | 2016-03-30 17:33:52 -0700 | [diff] [blame] | 1446 | if flags.Clang { |
| 1447 | flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainClangLdflags()) |
| 1448 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1449 | flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainLdflags()) |
| 1450 | } |
| 1451 | |
| 1452 | return flags |
| 1453 | } |
| 1454 | |
| 1455 | func (linker *baseLinker) static() bool { |
| 1456 | return linker.dynamicProperties.VariantIsStatic |
| 1457 | } |
| 1458 | |
| 1459 | func (linker *baseLinker) staticBinary() bool { |
| 1460 | return linker.dynamicProperties.VariantIsStaticBinary |
| 1461 | } |
| 1462 | |
| 1463 | func (linker *baseLinker) setStatic(static bool) { |
| 1464 | linker.dynamicProperties.VariantIsStatic = static |
| 1465 | } |
| 1466 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1467 | func (linker *baseLinker) isDependencyRoot() bool { |
| 1468 | return false |
| 1469 | } |
| 1470 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1471 | type baseLinkerInterface interface { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1472 | // Returns true if the build options for the module have selected a static or shared build |
| 1473 | buildStatic() bool |
| 1474 | buildShared() bool |
| 1475 | |
| 1476 | // Sets whether a specific variant is static or shared |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1477 | setStatic(bool) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1478 | |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1479 | // Returns whether a specific variant is a static library or binary |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1480 | static() bool |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1481 | |
| 1482 | // Returns whether a module is a static binary |
| 1483 | staticBinary() bool |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1484 | |
| 1485 | // Returns true for dependency roots (binaries) |
| 1486 | // TODO(ccross): also handle dlopenable libraries |
| 1487 | isDependencyRoot() bool |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1490 | type baseInstaller struct { |
| 1491 | Properties InstallerProperties |
| 1492 | |
| 1493 | dir string |
| 1494 | dir64 string |
| 1495 | data bool |
| 1496 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1497 | path android.OutputPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | var _ installer = (*baseInstaller)(nil) |
| 1501 | |
| 1502 | func (installer *baseInstaller) props() []interface{} { |
| 1503 | return []interface{}{&installer.Properties} |
| 1504 | } |
| 1505 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1506 | func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1507 | subDir := installer.dir |
| 1508 | if ctx.toolchain().Is64Bit() && installer.dir64 != "" { |
| 1509 | subDir = installer.dir64 |
| 1510 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1511 | if !ctx.Host() && !ctx.Arch().Native { |
| 1512 | subDir = filepath.Join(subDir, ctx.Arch().ArchType.String()) |
| 1513 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1514 | dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1515 | installer.path = ctx.InstallFile(dir, file) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 1516 | for _, symlink := range installer.Properties.Symlinks { |
| 1517 | ctx.InstallSymlink(dir, symlink, installer.path) |
| 1518 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | func (installer *baseInstaller) inData() bool { |
| 1522 | return installer.data |
| 1523 | } |
| 1524 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1525 | // |
| 1526 | // Combined static+shared libraries |
| 1527 | // |
| 1528 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1529 | type flagExporter struct { |
| 1530 | Properties FlagExporterProperties |
| 1531 | |
| 1532 | flags []string |
| 1533 | } |
| 1534 | |
| 1535 | func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1536 | includeDirs := android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs) |
Dan Willemsen | e6c7f18 | 2016-07-13 10:45:01 -0700 | [diff] [blame] | 1537 | for _, dir := range includeDirs.Strings() { |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1538 | f.flags = append(f.flags, inc+dir) |
Dan Willemsen | e6c7f18 | 2016-07-13 10:45:01 -0700 | [diff] [blame] | 1539 | } |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | func (f *flagExporter) reexportFlags(flags []string) { |
| 1543 | f.flags = append(f.flags, flags...) |
| 1544 | } |
| 1545 | |
| 1546 | func (f *flagExporter) exportedFlags() []string { |
| 1547 | return f.flags |
| 1548 | } |
| 1549 | |
| 1550 | type exportedFlagsProducer interface { |
| 1551 | exportedFlags() []string |
| 1552 | } |
| 1553 | |
| 1554 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 1555 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1556 | type libraryCompiler struct { |
| 1557 | baseCompiler |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 1558 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1559 | linker *libraryLinker |
| 1560 | Properties LibraryCompilerProperties |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1561 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1562 | // For reusing static library objects for shared library |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1563 | reuseObjFiles android.Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1566 | var _ compiler = (*libraryCompiler)(nil) |
| 1567 | |
| 1568 | func (library *libraryCompiler) props() []interface{} { |
| 1569 | props := library.baseCompiler.props() |
| 1570 | return append(props, &library.Properties) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1573 | func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags { |
| 1574 | flags = library.baseCompiler.flags(ctx, flags) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1575 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1576 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 1577 | // all code is position independent, and then those warnings get promoted to |
| 1578 | // errors. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1579 | if ctx.Os() != android.Windows { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1580 | flags.CFlags = append(flags.CFlags, "-fPIC") |
| 1581 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1582 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1583 | if library.linker.static() { |
| 1584 | flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...) |
Colin Cross | d8e780d | 2015-04-28 17:39:43 -0700 | [diff] [blame] | 1585 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1586 | flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...) |
Colin Cross | d8e780d | 2015-04-28 17:39:43 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1589 | return flags |
| 1590 | } |
| 1591 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1592 | func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { |
| 1593 | var objFiles android.Paths |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1594 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1595 | objFiles = library.baseCompiler.compile(ctx, flags, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1596 | library.reuseObjFiles = objFiles |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1597 | |
| 1598 | if library.linker.static() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1599 | objFiles = append(objFiles, library.compileObjs(ctx, flags, android.DeviceStaticLibrary, |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1600 | library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs, |
| 1601 | nil, deps.GeneratedHeaders)...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1602 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1603 | objFiles = append(objFiles, library.compileObjs(ctx, flags, android.DeviceSharedLibrary, |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1604 | library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs, |
| 1605 | nil, deps.GeneratedHeaders)...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | return objFiles |
| 1609 | } |
| 1610 | |
| 1611 | type libraryLinker struct { |
| 1612 | baseLinker |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1613 | flagExporter |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1614 | stripper |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1615 | |
| 1616 | Properties LibraryLinkerProperties |
| 1617 | |
| 1618 | dynamicProperties struct { |
| 1619 | BuildStatic bool `blueprint:"mutated"` |
| 1620 | BuildShared bool `blueprint:"mutated"` |
| 1621 | } |
| 1622 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1623 | // If we're used as a whole_static_lib, our missing dependencies need |
| 1624 | // to be given |
| 1625 | wholeStaticMissingDeps []string |
| 1626 | |
| 1627 | // For whole_static_libs |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1628 | objFiles android.Paths |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | var _ linker = (*libraryLinker)(nil) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1632 | |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 1633 | type libraryInterface interface { |
| 1634 | getWholeStaticMissingDeps() []string |
| 1635 | static() bool |
| 1636 | objs() android.Paths |
| 1637 | } |
| 1638 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1639 | func (library *libraryLinker) props() []interface{} { |
| 1640 | props := library.baseLinker.props() |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1641 | return append(props, |
| 1642 | &library.Properties, |
| 1643 | &library.dynamicProperties, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1644 | &library.flagExporter.Properties, |
| 1645 | &library.stripper.StripProperties) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
Dan Willemsen | 648c8ae | 2016-07-21 16:42:14 -0700 | [diff] [blame] | 1648 | func (library *libraryLinker) getLibName(ctx ModuleContext) string { |
| 1649 | name := ctx.ModuleName() |
| 1650 | |
Dan Willemsen | 627d83d | 2016-07-22 13:40:59 -0700 | [diff] [blame] | 1651 | if ctx.Host() && Bool(library.Properties.Unique_host_soname) { |
Dan Willemsen | 648c8ae | 2016-07-21 16:42:14 -0700 | [diff] [blame] | 1652 | if !strings.HasSuffix(name, "-host") { |
| 1653 | name = name + "-host" |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | return name + library.Properties.VariantName |
| 1658 | } |
| 1659 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1660 | func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 1661 | flags = library.baseLinker.flags(ctx, flags) |
| 1662 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1663 | if !library.static() { |
Dan Willemsen | 648c8ae | 2016-07-21 16:42:14 -0700 | [diff] [blame] | 1664 | libName := library.getLibName(ctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1665 | // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead |
| 1666 | sharedFlag := "-Wl,-shared" |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 1667 | if flags.Clang || ctx.Host() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1668 | sharedFlag = "-shared" |
| 1669 | } |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1670 | var f []string |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1671 | if ctx.Device() { |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1672 | f = append(f, |
Dan Willemsen | 99db8c3 | 2016-03-03 18:05:38 -0800 | [diff] [blame] | 1673 | "-nostdlib", |
| 1674 | "-Wl,--gc-sections", |
| 1675 | ) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1676 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1677 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1678 | if ctx.Darwin() { |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1679 | f = append(f, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1680 | "-dynamiclib", |
| 1681 | "-single_module", |
| 1682 | //"-read_only_relocs suppress", |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1683 | "-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(), |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1684 | ) |
| 1685 | } else { |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1686 | f = append(f, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1687 | sharedFlag, |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1688 | "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix()) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1689 | } |
Colin Cross | f87b261 | 2016-07-13 18:55:43 -0700 | [diff] [blame] | 1690 | |
| 1691 | flags.LdFlags = append(f, flags.LdFlags...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1692 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1693 | |
| 1694 | return flags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1697 | func (library *libraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1698 | deps = library.baseLinker.deps(ctx, deps) |
| 1699 | if library.static() { |
| 1700 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Static.Whole_static_libs...) |
| 1701 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...) |
| 1702 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...) |
| 1703 | } else { |
Colin Cross | a89d2e1 | 2016-01-11 12:48:37 -0800 | [diff] [blame] | 1704 | if ctx.Device() && !Bool(library.baseLinker.Properties.Nocrt) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1705 | if !ctx.sdk() { |
| 1706 | deps.CrtBegin = "crtbegin_so" |
| 1707 | deps.CrtEnd = "crtend_so" |
| 1708 | } else { |
| 1709 | deps.CrtBegin = "ndk_crtbegin_so." + ctx.sdkVersion() |
| 1710 | deps.CrtEnd = "ndk_crtend_so." + ctx.sdkVersion() |
| 1711 | } |
| 1712 | } |
| 1713 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...) |
| 1714 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...) |
| 1715 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...) |
| 1716 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1717 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1718 | return deps |
| 1719 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1720 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1721 | func (library *libraryLinker) linkStatic(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1722 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1723 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1724 | library.objFiles = append(android.Paths{}, deps.WholeStaticLibObjFiles...) |
Dan Willemsen | 025b480 | 2016-05-11 17:25:48 -0700 | [diff] [blame] | 1725 | library.objFiles = append(library.objFiles, objFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1726 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1727 | outputFile := android.PathForModuleOut(ctx, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1728 | ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1729 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1730 | if ctx.Darwin() { |
Dan Willemsen | 025b480 | 2016-05-11 17:25:48 -0700 | [diff] [blame] | 1731 | TransformDarwinObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1732 | } else { |
Dan Willemsen | 025b480 | 2016-05-11 17:25:48 -0700 | [diff] [blame] | 1733 | TransformObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1734 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1735 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1736 | library.wholeStaticMissingDeps = ctx.GetMissingDependencies() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1737 | |
| 1738 | ctx.CheckbuildFile(outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1739 | |
| 1740 | return outputFile |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1743 | func (library *libraryLinker) linkShared(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1744 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1745 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1746 | var linkerDeps android.Paths |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 1747 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1748 | versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script) |
| 1749 | unexportedSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Unexported_symbols_list) |
| 1750 | forceNotWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_not_weak_list) |
| 1751 | forceWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_weak_list) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1752 | if !ctx.Darwin() { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1753 | if versionScript.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1754 | flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1755 | linkerDeps = append(linkerDeps, versionScript.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1756 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1757 | if unexportedSymbols.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1758 | ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin") |
| 1759 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1760 | if forceNotWeakSymbols.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1761 | ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin") |
| 1762 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1763 | if forceWeakSymbols.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1764 | ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin") |
| 1765 | } |
| 1766 | } else { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1767 | if versionScript.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1768 | ctx.PropertyErrorf("version_script", "Not supported on Darwin") |
| 1769 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1770 | if unexportedSymbols.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1771 | flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1772 | linkerDeps = append(linkerDeps, unexportedSymbols.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1773 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1774 | if forceNotWeakSymbols.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1775 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1776 | linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1777 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1778 | if forceWeakSymbols.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1779 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1780 | linkerDeps = append(linkerDeps, forceWeakSymbols.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1781 | } |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
Dan Willemsen | 648c8ae | 2016-07-21 16:42:14 -0700 | [diff] [blame] | 1784 | fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix() |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1785 | outputFile := android.PathForModuleOut(ctx, fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1786 | ret := outputFile |
| 1787 | |
| 1788 | builderFlags := flagsToBuilderFlags(flags) |
| 1789 | |
| 1790 | if library.stripper.needsStrip(ctx) { |
| 1791 | strippedOutputFile := outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1792 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1793 | library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 1794 | } |
| 1795 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1796 | sharedLibs := deps.SharedLibs |
| 1797 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1798 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1799 | TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, |
| 1800 | deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1801 | linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1802 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1803 | return ret |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1804 | } |
| 1805 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1806 | func (library *libraryLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1807 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1808 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1809 | objFiles = append(objFiles, deps.ObjFiles...) |
| 1810 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1811 | var out android.Path |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1812 | if library.static() { |
| 1813 | out = library.linkStatic(ctx, flags, deps, objFiles) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1814 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1815 | out = library.linkShared(ctx, flags, deps, objFiles) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1816 | } |
| 1817 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1818 | library.exportIncludes(ctx, "-I") |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1819 | library.reexportFlags(deps.ReexportedFlags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1820 | |
| 1821 | return out |
| 1822 | } |
| 1823 | |
| 1824 | func (library *libraryLinker) buildStatic() bool { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1825 | return library.dynamicProperties.BuildStatic && |
| 1826 | (library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | func (library *libraryLinker) buildShared() bool { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1830 | return library.dynamicProperties.BuildShared && |
| 1831 | (library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | func (library *libraryLinker) getWholeStaticMissingDeps() []string { |
| 1835 | return library.wholeStaticMissingDeps |
| 1836 | } |
| 1837 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1838 | func (library *libraryLinker) installable() bool { |
| 1839 | return !library.static() |
| 1840 | } |
| 1841 | |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 1842 | func (library *libraryLinker) objs() android.Paths { |
| 1843 | return library.objFiles |
| 1844 | } |
| 1845 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1846 | type libraryInstaller struct { |
| 1847 | baseInstaller |
| 1848 | |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1849 | linker *libraryLinker |
| 1850 | sanitize *sanitize |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1851 | } |
| 1852 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1853 | func (library *libraryInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1854 | if !library.linker.static() { |
| 1855 | library.baseInstaller.install(ctx, file) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1856 | } |
| 1857 | } |
| 1858 | |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1859 | func (library *libraryInstaller) inData() bool { |
| 1860 | return library.baseInstaller.inData() || library.sanitize.inData() |
| 1861 | } |
| 1862 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1863 | func NewLibrary(hod android.HostOrDeviceSupported, shared, static bool) *Module { |
| 1864 | module := newModule(hod, android.MultilibBoth) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1865 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1866 | linker := &libraryLinker{} |
| 1867 | linker.dynamicProperties.BuildShared = shared |
| 1868 | linker.dynamicProperties.BuildStatic = static |
| 1869 | module.linker = linker |
| 1870 | |
| 1871 | module.compiler = &libraryCompiler{ |
| 1872 | linker: linker, |
| 1873 | } |
| 1874 | module.installer = &libraryInstaller{ |
| 1875 | baseInstaller: baseInstaller{ |
| 1876 | dir: "lib", |
| 1877 | dir64: "lib64", |
| 1878 | }, |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1879 | linker: linker, |
| 1880 | sanitize: module.sanitize, |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1883 | return module |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1886 | func libraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1887 | module := NewLibrary(android.HostAndDeviceSupported, true, true) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1888 | return module.Init() |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1891 | // |
| 1892 | // Objects (for crt*.o) |
| 1893 | // |
| 1894 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1895 | type objectLinker struct { |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 1896 | Properties ObjectLinkerProperties |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1899 | func objectFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1900 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1901 | module.compiler = &baseCompiler{} |
| 1902 | module.linker = &objectLinker{} |
| 1903 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1904 | } |
| 1905 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame^] | 1906 | func (object *objectLinker) appendLdflags(flags []string) { |
| 1907 | panic(fmt.Errorf("appendLdflags on object Linker not supported")) |
| 1908 | } |
| 1909 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 1910 | func (object *objectLinker) props() []interface{} { |
| 1911 | return []interface{}{&object.Properties} |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1914 | func (*objectLinker) begin(ctx BaseModuleContext) {} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1915 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 1916 | func (object *objectLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1917 | deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1918 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1919 | } |
| 1920 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1921 | func (*objectLinker) flags(ctx ModuleContext, flags Flags) Flags { |
Dan Willemsen | e717492 | 2016-03-30 17:33:52 -0700 | [diff] [blame] | 1922 | if flags.Clang { |
| 1923 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags()) |
| 1924 | } else { |
| 1925 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags()) |
| 1926 | } |
| 1927 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1928 | return flags |
| 1929 | } |
| 1930 | |
| 1931 | func (object *objectLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1932 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1933 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1934 | objFiles = append(objFiles, deps.ObjFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1935 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1936 | var outputFile android.Path |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1937 | if len(objFiles) == 1 { |
| 1938 | outputFile = objFiles[0] |
| 1939 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1940 | output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1941 | TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1942 | outputFile = output |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1943 | } |
| 1944 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1945 | ctx.CheckbuildFile(outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1946 | return outputFile |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1947 | } |
| 1948 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1949 | func (*objectLinker) installable() bool { |
| 1950 | return false |
| 1951 | } |
| 1952 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1953 | // |
| 1954 | // Executables |
| 1955 | // |
| 1956 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1957 | type binaryLinker struct { |
| 1958 | baseLinker |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1959 | stripper |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1960 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1961 | Properties BinaryLinkerProperties |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1962 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1963 | hostToolPath android.OptionalPath |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1966 | var _ linker = (*binaryLinker)(nil) |
| 1967 | |
| 1968 | func (binary *binaryLinker) props() []interface{} { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1969 | return append(binary.baseLinker.props(), |
| 1970 | &binary.Properties, |
| 1971 | &binary.stripper.StripProperties) |
| 1972 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1973 | } |
| 1974 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1975 | func (binary *binaryLinker) buildStatic() bool { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1976 | return binary.baseLinker.staticBinary() |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1979 | func (binary *binaryLinker) buildShared() bool { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1980 | return !binary.baseLinker.staticBinary() |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1983 | func (binary *binaryLinker) getStem(ctx BaseModuleContext) string { |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1984 | stem := ctx.ModuleName() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1985 | if binary.Properties.Stem != "" { |
| 1986 | stem = binary.Properties.Stem |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1987 | } |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1988 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1989 | return stem + binary.Properties.Suffix |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1990 | } |
| 1991 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1992 | func (binary *binaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1993 | deps = binary.baseLinker.deps(ctx, deps) |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1994 | if ctx.Device() { |
Colin Cross | a89d2e1 | 2016-01-11 12:48:37 -0800 | [diff] [blame] | 1995 | if !Bool(binary.baseLinker.Properties.Nocrt) { |
| 1996 | if !ctx.sdk() { |
| 1997 | if binary.buildStatic() { |
| 1998 | deps.CrtBegin = "crtbegin_static" |
| 1999 | } else { |
| 2000 | deps.CrtBegin = "crtbegin_dynamic" |
| 2001 | } |
| 2002 | deps.CrtEnd = "crtend_android" |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2003 | } else { |
Colin Cross | a89d2e1 | 2016-01-11 12:48:37 -0800 | [diff] [blame] | 2004 | if binary.buildStatic() { |
| 2005 | deps.CrtBegin = "ndk_crtbegin_static." + ctx.sdkVersion() |
| 2006 | } else { |
| 2007 | if Bool(binary.Properties.Static_executable) { |
| 2008 | deps.CrtBegin = "ndk_crtbegin_static." + ctx.sdkVersion() |
| 2009 | } else { |
| 2010 | deps.CrtBegin = "ndk_crtbegin_dynamic." + ctx.sdkVersion() |
| 2011 | } |
| 2012 | deps.CrtEnd = "ndk_crtend_android." + ctx.sdkVersion() |
| 2013 | } |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2014 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2015 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2016 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2017 | if binary.buildStatic() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2018 | if inList("libc++_static", deps.StaticLibs) { |
| 2019 | deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl") |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 2020 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2021 | // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with |
| 2022 | // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs, |
| 2023 | // move them to the beginning of deps.LateStaticLibs |
| 2024 | var groupLibs []string |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2025 | deps.StaticLibs, groupLibs = filterList(deps.StaticLibs, |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2026 | []string{"libc", "libc_nomalloc", "libcompiler_rt"}) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2027 | deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2028 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2029 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2030 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2031 | if binary.buildShared() && inList("libc", deps.StaticLibs) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2032 | ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" + |
| 2033 | "from static libs or set static_executable: true") |
| 2034 | } |
| 2035 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2036 | } |
| 2037 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2038 | func (*binaryLinker) installable() bool { |
| 2039 | return true |
| 2040 | } |
| 2041 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2042 | func (binary *binaryLinker) isDependencyRoot() bool { |
| 2043 | return true |
| 2044 | } |
| 2045 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2046 | func NewBinary(hod android.HostOrDeviceSupported) *Module { |
| 2047 | module := newModule(hod, android.MultilibFirst) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2048 | module.compiler = &baseCompiler{} |
| 2049 | module.linker = &binaryLinker{} |
| 2050 | module.installer = &baseInstaller{ |
| 2051 | dir: "bin", |
| 2052 | } |
| 2053 | return module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2054 | } |
| 2055 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2056 | func binaryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2057 | module := NewBinary(android.HostAndDeviceSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2058 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2059 | } |
| 2060 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2061 | func (binary *binaryLinker) begin(ctx BaseModuleContext) { |
| 2062 | binary.baseLinker.begin(ctx) |
| 2063 | |
| 2064 | static := Bool(binary.Properties.Static_executable) |
| 2065 | if ctx.Host() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2066 | if ctx.Os() == android.Linux { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2067 | if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) { |
| 2068 | static = true |
| 2069 | } |
| 2070 | } else { |
| 2071 | // Static executables are not supported on Darwin or Windows |
| 2072 | static = false |
| 2073 | } |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 2074 | } |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2075 | if static { |
| 2076 | binary.dynamicProperties.VariantIsStatic = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2077 | binary.dynamicProperties.VariantIsStaticBinary = true |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2081 | func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 2082 | flags = binary.baseLinker.flags(ctx, flags) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 2083 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2084 | if ctx.Host() && !binary.staticBinary() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2085 | flags.LdFlags = append(flags.LdFlags, "-pie") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2086 | if ctx.Os() == android.Windows { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2087 | flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup") |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 2092 | // all code is position independent, and then those warnings get promoted to |
| 2093 | // errors. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2094 | if ctx.Os() != android.Windows { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2095 | flags.CFlags = append(flags.CFlags, "-fpie") |
| 2096 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2097 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2098 | if ctx.Device() { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2099 | if binary.buildStatic() { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2100 | // Clang driver needs -static to create static executable. |
| 2101 | // However, bionic/linker uses -shared to overwrite. |
| 2102 | // Linker for x86 targets does not allow coexistance of -static and -shared, |
| 2103 | // so we add -static only if -shared is not used. |
| 2104 | if !inList("-shared", flags.LdFlags) { |
| 2105 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 2106 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2107 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2108 | flags.LdFlags = append(flags.LdFlags, |
| 2109 | "-nostdlib", |
| 2110 | "-Bstatic", |
| 2111 | "-Wl,--gc-sections", |
| 2112 | ) |
| 2113 | |
| 2114 | } else { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2115 | if flags.DynamicLinker == "" { |
| 2116 | flags.DynamicLinker = "/system/bin/linker" |
| 2117 | if flags.Toolchain.Is64Bit() { |
| 2118 | flags.DynamicLinker += "64" |
| 2119 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | flags.LdFlags = append(flags.LdFlags, |
Colin Cross | 979422c | 2015-12-01 14:09:48 -0800 | [diff] [blame] | 2123 | "-pie", |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2124 | "-nostdlib", |
| 2125 | "-Bdynamic", |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2126 | "-Wl,--gc-sections", |
| 2127 | "-Wl,-z,nocopyreloc", |
| 2128 | ) |
| 2129 | } |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2130 | } else { |
| 2131 | if binary.staticBinary() { |
| 2132 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 2133 | } |
| 2134 | if ctx.Darwin() { |
| 2135 | flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names") |
| 2136 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2137 | } |
| 2138 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2139 | return flags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2140 | } |
| 2141 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2142 | func (binary *binaryLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2143 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2144 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2145 | fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2146 | outputFile := android.PathForModuleOut(ctx, fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2147 | ret := outputFile |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2148 | if ctx.Os().Class == android.Host { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2149 | binary.hostToolPath = android.OptionalPathForPath(outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2150 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2151 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2152 | var linkerDeps android.Paths |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 2153 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2154 | sharedLibs := deps.SharedLibs |
| 2155 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
| 2156 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2157 | if flags.DynamicLinker != "" { |
| 2158 | flags.LdFlags = append(flags.LdFlags, " -Wl,-dynamic-linker,"+flags.DynamicLinker) |
| 2159 | } |
| 2160 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2161 | builderFlags := flagsToBuilderFlags(flags) |
| 2162 | |
| 2163 | if binary.stripper.needsStrip(ctx) { |
| 2164 | strippedOutputFile := outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2165 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2166 | binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 2167 | } |
| 2168 | |
| 2169 | if binary.Properties.Prefix_symbols != "" { |
| 2170 | afterPrefixSymbols := outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2171 | outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2172 | TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile, |
| 2173 | flagsToBuilderFlags(flags), afterPrefixSymbols) |
| 2174 | } |
| 2175 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2176 | TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs, |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 2177 | deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2178 | builderFlags, outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2179 | |
| 2180 | return ret |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2181 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2182 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2183 | func (binary *binaryLinker) HostToolPath() android.OptionalPath { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2184 | return binary.hostToolPath |
Colin Cross | d350ecd | 2015-04-28 13:25:36 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2187 | type stripper struct { |
| 2188 | StripProperties StripProperties |
| 2189 | } |
| 2190 | |
| 2191 | func (stripper *stripper) needsStrip(ctx ModuleContext) bool { |
| 2192 | return !ctx.AConfig().EmbeddedInMake() && !stripper.StripProperties.Strip.None |
| 2193 | } |
| 2194 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2195 | func (stripper *stripper) strip(ctx ModuleContext, in, out android.ModuleOutPath, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2196 | flags builderFlags) { |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 2197 | if ctx.Darwin() { |
| 2198 | TransformDarwinStrip(ctx, in, out) |
| 2199 | } else { |
| 2200 | flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols |
| 2201 | // TODO(ccross): don't add gnu debuglink for user builds |
| 2202 | flags.stripAddGnuDebuglink = true |
| 2203 | TransformStrip(ctx, in, out, flags) |
| 2204 | } |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2207 | func testPerSrcMutator(mctx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2208 | if m, ok := mctx.Module().(*Module); ok { |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 2209 | if test, ok := m.linker.(*testBinaryLinker); ok { |
| 2210 | if Bool(test.testLinker.Properties.Test_per_src) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2211 | testNames := make([]string, len(m.compiler.(*baseCompiler).Properties.Srcs)) |
| 2212 | for i, src := range m.compiler.(*baseCompiler).Properties.Srcs { |
| 2213 | testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) |
| 2214 | } |
| 2215 | tests := mctx.CreateLocalVariations(testNames...) |
| 2216 | for i, src := range m.compiler.(*baseCompiler).Properties.Srcs { |
| 2217 | tests[i].(*Module).compiler.(*baseCompiler).Properties.Srcs = []string{src} |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 2218 | tests[i].(*Module).linker.(*testBinaryLinker).binaryLinker.Properties.Stem = testNames[i] |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2219 | } |
Colin Cross | 6002e05 | 2015-09-16 16:00:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | } |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2225 | type testLinker struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2226 | Properties TestLinkerProperties |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2227 | } |
| 2228 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2229 | func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2230 | if !test.Properties.Gtest { |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2231 | return flags |
| 2232 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2233 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2234 | flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING") |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2235 | if ctx.Host() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2236 | flags.CFlags = append(flags.CFlags, "-O0", "-g") |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2237 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2238 | switch ctx.Os() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2239 | case android.Windows: |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2240 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS") |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2241 | case android.Linux: |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2242 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX") |
| 2243 | flags.LdFlags = append(flags.LdFlags, "-lpthread") |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2244 | case android.Darwin: |
Dan Willemsen | 4a94683 | 2016-05-13 14:13:01 -0700 | [diff] [blame] | 2245 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC") |
| 2246 | flags.LdFlags = append(flags.LdFlags, "-lpthread") |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2247 | } |
| 2248 | } else { |
| 2249 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID") |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 2252 | return flags |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2255 | func (test *testLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 2256 | if test.Properties.Gtest { |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 2257 | if ctx.sdk() && ctx.Device() { |
| 2258 | switch ctx.selectedStl() { |
| 2259 | case "ndk_libc++_shared", "ndk_libc++_static": |
| 2260 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_libcxx", "libgtest_ndk_libcxx") |
| 2261 | case "ndk_libgnustl_static": |
| 2262 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_gnustl", "libgtest_ndk_gnustl") |
| 2263 | default: |
| 2264 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk", "libgtest_ndk") |
| 2265 | } |
| 2266 | } else { |
| 2267 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest") |
| 2268 | } |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2269 | } |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 2270 | return deps |
| 2271 | } |
| 2272 | |
| 2273 | type testBinaryLinker struct { |
| 2274 | testLinker |
| 2275 | binaryLinker |
| 2276 | } |
| 2277 | |
| 2278 | func (test *testBinaryLinker) begin(ctx BaseModuleContext) { |
| 2279 | test.binaryLinker.begin(ctx) |
| 2280 | runpath := "../../lib" |
| 2281 | if ctx.toolchain().Is64Bit() { |
| 2282 | runpath += "64" |
| 2283 | } |
| 2284 | test.dynamicProperties.RunPaths = append([]string{runpath}, test.dynamicProperties.RunPaths...) |
| 2285 | } |
| 2286 | |
| 2287 | func (test *testBinaryLinker) props() []interface{} { |
| 2288 | return append(test.binaryLinker.props(), &test.testLinker.Properties) |
| 2289 | } |
| 2290 | |
| 2291 | func (test *testBinaryLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 2292 | flags = test.binaryLinker.flags(ctx, flags) |
| 2293 | flags = test.testLinker.flags(ctx, flags) |
| 2294 | return flags |
| 2295 | } |
| 2296 | |
| 2297 | func (test *testBinaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 2298 | deps = test.testLinker.deps(ctx, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2299 | deps = test.binaryLinker.deps(ctx, deps) |
| 2300 | return deps |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 2303 | type testLibraryLinker struct { |
| 2304 | testLinker |
| 2305 | *libraryLinker |
| 2306 | } |
| 2307 | |
| 2308 | func (test *testLibraryLinker) props() []interface{} { |
| 2309 | return append(test.libraryLinker.props(), &test.testLinker.Properties) |
| 2310 | } |
| 2311 | |
| 2312 | func (test *testLibraryLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 2313 | flags = test.libraryLinker.flags(ctx, flags) |
| 2314 | flags = test.testLinker.flags(ctx, flags) |
| 2315 | return flags |
| 2316 | } |
| 2317 | |
| 2318 | func (test *testLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 2319 | deps = test.testLinker.deps(ctx, deps) |
| 2320 | deps = test.libraryLinker.deps(ctx, deps) |
| 2321 | return deps |
| 2322 | } |
| 2323 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2324 | type testInstaller struct { |
| 2325 | baseInstaller |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 2326 | } |
| 2327 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2328 | func (installer *testInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2329 | installer.dir = filepath.Join(installer.dir, ctx.ModuleName()) |
| 2330 | installer.dir64 = filepath.Join(installer.dir64, ctx.ModuleName()) |
| 2331 | installer.baseInstaller.install(ctx, file) |
| 2332 | } |
| 2333 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2334 | func NewTest(hod android.HostOrDeviceSupported) *Module { |
| 2335 | module := newModule(hod, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2336 | module.compiler = &baseCompiler{} |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 2337 | linker := &testBinaryLinker{} |
| 2338 | linker.testLinker.Properties.Gtest = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2339 | module.linker = linker |
| 2340 | module.installer = &testInstaller{ |
| 2341 | baseInstaller: baseInstaller{ |
| 2342 | dir: "nativetest", |
| 2343 | dir64: "nativetest64", |
| 2344 | data: true, |
| 2345 | }, |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2346 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2347 | return module |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2348 | } |
| 2349 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2350 | func testFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2351 | module := NewTest(android.HostAndDeviceSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2352 | return module.Init() |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Colin Cross | c7a38dc | 2016-07-12 13:13:09 -0700 | [diff] [blame] | 2355 | func NewTestLibrary(hod android.HostOrDeviceSupported) *Module { |
| 2356 | module := NewLibrary(android.HostAndDeviceSupported, false, true) |
| 2357 | linker := &testLibraryLinker{ |
| 2358 | libraryLinker: module.linker.(*libraryLinker), |
| 2359 | } |
| 2360 | linker.testLinker.Properties.Gtest = true |
| 2361 | module.linker = linker |
| 2362 | module.installer = &testInstaller{ |
| 2363 | baseInstaller: baseInstaller{ |
| 2364 | dir: "nativetest", |
| 2365 | dir64: "nativetest64", |
| 2366 | data: true, |
| 2367 | }, |
| 2368 | } |
| 2369 | return module |
| 2370 | } |
| 2371 | |
| 2372 | func testLibraryFactory() (blueprint.Module, []interface{}) { |
| 2373 | module := NewTestLibrary(android.HostAndDeviceSupported) |
| 2374 | return module.Init() |
| 2375 | } |
| 2376 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2377 | type benchmarkLinker struct { |
Colin Cross | aa3bf37 | 2016-07-14 10:27:10 -0700 | [diff] [blame] | 2378 | testBinaryLinker |
Colin Cross | 9ffb4f5 | 2015-04-24 17:48:09 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2381 | func (benchmark *benchmarkLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Colin Cross | aa3bf37 | 2016-07-14 10:27:10 -0700 | [diff] [blame] | 2382 | deps = benchmark.testBinaryLinker.deps(ctx, deps) |
Colin Cross | 2683274 | 2016-07-11 14:57:56 -0700 | [diff] [blame] | 2383 | deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark") |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2384 | return deps |
Colin Cross | 9ffb4f5 | 2015-04-24 17:48:09 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2387 | func NewBenchmark(hod android.HostOrDeviceSupported) *Module { |
| 2388 | module := newModule(hod, android.MultilibFirst) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2389 | module.compiler = &baseCompiler{} |
| 2390 | module.linker = &benchmarkLinker{} |
Colin Cross | 624b8ed | 2016-07-11 17:20:09 -0700 | [diff] [blame] | 2391 | module.installer = &testInstaller{ |
| 2392 | baseInstaller: baseInstaller{ |
| 2393 | dir: "nativetest", |
| 2394 | dir64: "nativetest64", |
| 2395 | data: true, |
| 2396 | }, |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2397 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2398 | return module |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2401 | func benchmarkFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2402 | module := NewBenchmark(android.HostAndDeviceSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2403 | return module.Init() |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2406 | // |
| 2407 | // Static library |
| 2408 | // |
| 2409 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2410 | func libraryStaticFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2411 | module := NewLibrary(android.HostAndDeviceSupported, false, true) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2412 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | // |
| 2416 | // Shared libraries |
| 2417 | // |
| 2418 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2419 | func librarySharedFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2420 | module := NewLibrary(android.HostAndDeviceSupported, true, false) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2421 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | // |
| 2425 | // Host static library |
| 2426 | // |
| 2427 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2428 | func libraryHostStaticFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2429 | module := NewLibrary(android.HostSupported, false, true) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2430 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | // |
| 2434 | // Host Shared libraries |
| 2435 | // |
| 2436 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2437 | func libraryHostSharedFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2438 | module := NewLibrary(android.HostSupported, true, false) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2439 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | // |
| 2443 | // Host Binaries |
| 2444 | // |
| 2445 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2446 | func binaryHostFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2447 | module := NewBinary(android.HostSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2448 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | // |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 2452 | // Host Tests |
| 2453 | // |
| 2454 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2455 | func testHostFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2456 | module := NewTest(android.HostSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2457 | return module.Init() |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | // |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2461 | // Host Benchmarks |
| 2462 | // |
| 2463 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2464 | func benchmarkHostFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2465 | module := NewBenchmark(android.HostSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2466 | return module.Init() |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2470 | // Defaults |
| 2471 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2472 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2473 | android.ModuleBase |
| 2474 | android.DefaultsModule |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2475 | } |
| 2476 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2477 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2478 | } |
| 2479 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2480 | func defaultsFactory() (blueprint.Module, []interface{}) { |
| 2481 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2482 | |
| 2483 | propertyStructs := []interface{}{ |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2484 | &BaseProperties{}, |
| 2485 | &BaseCompilerProperties{}, |
| 2486 | &BaseLinkerProperties{}, |
| 2487 | &LibraryCompilerProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2488 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2489 | &LibraryLinkerProperties{}, |
| 2490 | &BinaryLinkerProperties{}, |
| 2491 | &TestLinkerProperties{}, |
| 2492 | &UnusedProperties{}, |
| 2493 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2494 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2495 | &StripProperties{}, |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2498 | _, propertyStructs = android.InitAndroidArchModule(module, android.HostAndDeviceDefault, |
| 2499 | android.MultilibDefault, propertyStructs...) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2500 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2501 | return android.InitDefaultsModule(module, module, propertyStructs...) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | // |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2505 | // Device libraries shipped with gcc |
| 2506 | // |
| 2507 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2508 | type toolchainLibraryLinker struct { |
| 2509 | baseLinker |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2510 | } |
| 2511 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2512 | var _ baseLinkerInterface = (*toolchainLibraryLinker)(nil) |
| 2513 | |
| 2514 | func (*toolchainLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2515 | // toolchain libraries can't have any dependencies |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2516 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2519 | func (*toolchainLibraryLinker) buildStatic() bool { |
| 2520 | return true |
| 2521 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2522 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2523 | func (*toolchainLibraryLinker) buildShared() bool { |
| 2524 | return false |
| 2525 | } |
| 2526 | |
| 2527 | func toolchainLibraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2528 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2529 | module.compiler = &baseCompiler{} |
| 2530 | module.linker = &toolchainLibraryLinker{} |
Dan Willemsen | fc9c28c | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 2531 | module.Properties.Clang = proptools.BoolPtr(false) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2532 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2533 | } |
| 2534 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2535 | func (library *toolchainLibraryLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2536 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2537 | |
| 2538 | libName := ctx.ModuleName() + staticLibraryExtension |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2539 | outputFile := android.PathForModuleOut(ctx, libName) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2540 | |
Dan Willemsen | fc9c28c | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 2541 | if flags.Clang { |
| 2542 | ctx.ModuleErrorf("toolchain_library must use GCC, not Clang") |
| 2543 | } |
| 2544 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2545 | CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2546 | |
| 2547 | ctx.CheckbuildFile(outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2548 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2549 | return outputFile |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2552 | func (*toolchainLibraryLinker) installable() bool { |
| 2553 | return false |
| 2554 | } |
| 2555 | |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2556 | // NDK prebuilt libraries. |
| 2557 | // |
| 2558 | // These differ from regular prebuilts in that they aren't stripped and usually aren't installed |
| 2559 | // either (with the exception of the shared STLs, which are installed to the app's directory rather |
| 2560 | // than to the system image). |
| 2561 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2562 | func getNdkLibDir(ctx android.ModuleContext, toolchain Toolchain, version string) android.SourcePath { |
Colin Cross | c7fd91a | 2016-05-17 13:15:15 -0700 | [diff] [blame] | 2563 | suffix := "" |
| 2564 | // Most 64-bit NDK prebuilts store libraries in "lib64", except for arm64 which is not a |
| 2565 | // multilib toolchain and stores the libraries in "lib". |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2566 | if toolchain.Is64Bit() && ctx.Arch().ArchType != android.Arm64 { |
Colin Cross | c7fd91a | 2016-05-17 13:15:15 -0700 | [diff] [blame] | 2567 | suffix = "64" |
| 2568 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2569 | return android.PathForSource(ctx, fmt.Sprintf("prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib%s", |
Colin Cross | c7fd91a | 2016-05-17 13:15:15 -0700 | [diff] [blame] | 2570 | version, toolchain.Name(), suffix)) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2573 | func ndkPrebuiltModuleToPath(ctx android.ModuleContext, toolchain Toolchain, |
| 2574 | ext string, version string) android.Path { |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2575 | |
| 2576 | // NDK prebuilts are named like: ndk_NAME.EXT.SDK_VERSION. |
| 2577 | // We want to translate to just NAME.EXT |
| 2578 | name := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0] |
| 2579 | dir := getNdkLibDir(ctx, toolchain, version) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2580 | return dir.Join(ctx, name+ext) |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2583 | type ndkPrebuiltObjectLinker struct { |
| 2584 | objectLinker |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2587 | func (*ndkPrebuiltObjectLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2588 | // NDK objects can't have any dependencies |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2589 | return deps |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2592 | func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2593 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2594 | module.linker = &ndkPrebuiltObjectLinker{} |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2595 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2596 | return module.Init() |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2599 | func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2600 | deps PathDeps, objFiles android.Paths) android.Path { |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2601 | // A null build step, but it sets up the output path. |
| 2602 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") { |
| 2603 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name") |
| 2604 | } |
| 2605 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2606 | return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion()) |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2609 | type ndkPrebuiltLibraryLinker struct { |
| 2610 | libraryLinker |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2613 | var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil) |
| 2614 | var _ exportedFlagsProducer = (*libraryLinker)(nil) |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2615 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2616 | func (ndk *ndkPrebuiltLibraryLinker) props() []interface{} { |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2617 | return append(ndk.libraryLinker.props(), &ndk.Properties, &ndk.flagExporter.Properties) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2620 | func (*ndkPrebuiltLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2621 | // NDK libraries can't have any dependencies |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2622 | return deps |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2625 | func ndkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2626 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2627 | linker := &ndkPrebuiltLibraryLinker{} |
| 2628 | linker.dynamicProperties.BuildShared = true |
| 2629 | module.linker = linker |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2630 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2631 | return module.Init() |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2634 | func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2635 | deps PathDeps, objFiles android.Paths) android.Path { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2636 | // A null build step, but it sets up the output path. |
| 2637 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { |
| 2638 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") |
| 2639 | } |
| 2640 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2641 | ndk.exportIncludes(ctx, "-isystem") |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2642 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2643 | return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(), |
| 2644 | ctx.sdkVersion()) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | // The NDK STLs are slightly different from the prebuilt system libraries: |
| 2648 | // * Are not specific to each platform version. |
| 2649 | // * The libraries are not in a predictable location for each STL. |
| 2650 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2651 | type ndkPrebuiltStlLinker struct { |
| 2652 | ndkPrebuiltLibraryLinker |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2655 | func ndkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2656 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2657 | linker := &ndkPrebuiltStlLinker{} |
| 2658 | linker.dynamicProperties.BuildShared = true |
| 2659 | module.linker = linker |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2660 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2661 | return module.Init() |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2664 | func ndkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2665 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2666 | linker := &ndkPrebuiltStlLinker{} |
| 2667 | linker.dynamicProperties.BuildStatic = true |
| 2668 | module.linker = linker |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2669 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2670 | return module.Init() |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2673 | func getNdkStlLibDir(ctx android.ModuleContext, toolchain Toolchain, stl string) android.SourcePath { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2674 | gccVersion := toolchain.GccVersion() |
| 2675 | var libDir string |
| 2676 | switch stl { |
| 2677 | case "libstlport": |
| 2678 | libDir = "cxx-stl/stlport/libs" |
| 2679 | case "libc++": |
| 2680 | libDir = "cxx-stl/llvm-libc++/libs" |
| 2681 | case "libgnustl": |
| 2682 | libDir = fmt.Sprintf("cxx-stl/gnu-libstdc++/%s/libs", gccVersion) |
| 2683 | } |
| 2684 | |
| 2685 | if libDir != "" { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2686 | ndkSrcRoot := "prebuilts/ndk/current/sources" |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2687 | return android.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0]) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | ctx.ModuleErrorf("Unknown NDK STL: %s", stl) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2691 | return android.PathForSource(ctx, "") |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2694 | func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2695 | deps PathDeps, objFiles android.Paths) android.Path { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2696 | // A null build step, but it sets up the output path. |
| 2697 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { |
| 2698 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") |
| 2699 | } |
| 2700 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2701 | ndk.exportIncludes(ctx, "-I") |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2702 | |
| 2703 | libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2704 | libExt := flags.Toolchain.ShlibSuffix() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2705 | if ndk.dynamicProperties.BuildStatic { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2706 | libExt = staticLibraryExtension |
| 2707 | } |
| 2708 | |
| 2709 | stlName := strings.TrimSuffix(libName, "_shared") |
| 2710 | stlName = strings.TrimSuffix(stlName, "_static") |
| 2711 | libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2712 | return libDir.Join(ctx, libName+libExt) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2715 | func linkageMutator(mctx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2716 | if m, ok := mctx.Module().(*Module); ok { |
| 2717 | if m.linker != nil { |
| 2718 | if linker, ok := m.linker.(baseLinkerInterface); ok { |
| 2719 | var modules []blueprint.Module |
| 2720 | if linker.buildStatic() && linker.buildShared() { |
| 2721 | modules = mctx.CreateLocalVariations("static", "shared") |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2722 | static := modules[0].(*Module) |
| 2723 | shared := modules[1].(*Module) |
| 2724 | |
| 2725 | static.linker.(baseLinkerInterface).setStatic(true) |
| 2726 | shared.linker.(baseLinkerInterface).setStatic(false) |
| 2727 | |
| 2728 | if staticCompiler, ok := static.compiler.(*libraryCompiler); ok { |
| 2729 | sharedCompiler := shared.compiler.(*libraryCompiler) |
| 2730 | if len(staticCompiler.Properties.Static.Cflags) == 0 && |
| 2731 | len(sharedCompiler.Properties.Shared.Cflags) == 0 { |
| 2732 | // Optimize out compiling common .o files twice for static+shared libraries |
| 2733 | mctx.AddInterVariantDependency(reuseObjTag, shared, static) |
| 2734 | sharedCompiler.baseCompiler.Properties.Srcs = nil |
Colin Cross | 5dab840 | 2016-07-27 10:30:21 -0700 | [diff] [blame] | 2735 | sharedCompiler.baseCompiler.Properties.Generated_sources = nil |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2736 | } |
| 2737 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2738 | } else if linker.buildStatic() { |
| 2739 | modules = mctx.CreateLocalVariations("static") |
| 2740 | modules[0].(*Module).linker.(baseLinkerInterface).setStatic(true) |
| 2741 | } else if linker.buildShared() { |
| 2742 | modules = mctx.CreateLocalVariations("shared") |
| 2743 | modules[0].(*Module).linker.(baseLinkerInterface).setStatic(false) |
| 2744 | } else { |
| 2745 | panic(fmt.Errorf("library %q not static or shared", mctx.ModuleName())) |
| 2746 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2747 | } |
| 2748 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2749 | } |
| 2750 | } |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 2751 | |
| 2752 | // lastUniqueElements returns all unique elements of a slice, keeping the last copy of each |
| 2753 | // modifies the slice contents in place, and returns a subslice of the original slice |
| 2754 | func lastUniqueElements(list []string) []string { |
| 2755 | totalSkip := 0 |
| 2756 | for i := len(list) - 1; i >= totalSkip; i-- { |
| 2757 | skip := 0 |
| 2758 | for j := i - 1; j >= totalSkip; j-- { |
| 2759 | if list[i] == list[j] { |
| 2760 | skip++ |
| 2761 | } else { |
| 2762 | list[j+skip] = list[j] |
| 2763 | } |
| 2764 | } |
| 2765 | totalSkip += skip |
| 2766 | } |
| 2767 | return list[totalSkip:] |
| 2768 | } |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 2769 | |
| 2770 | var Bool = proptools.Bool |