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