Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "github.com/google/blueprint" |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 21 | "github.com/google/blueprint/pathtools" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 22 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 23 | "android/soong/android" |
| 24 | ) |
| 25 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 26 | type LibraryProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 27 | Static struct { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 28 | Srcs []string `android:"arch_variant"` |
| 29 | Cflags []string `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 30 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 31 | Enabled *bool `android:"arch_variant"` |
| 32 | Whole_static_libs []string `android:"arch_variant"` |
| 33 | Static_libs []string `android:"arch_variant"` |
| 34 | Shared_libs []string `android:"arch_variant"` |
| 35 | } `android:"arch_variant"` |
| 36 | Shared struct { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 37 | Srcs []string `android:"arch_variant"` |
| 38 | Cflags []string `android:"arch_variant"` |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 39 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 40 | Enabled *bool `android:"arch_variant"` |
| 41 | Whole_static_libs []string `android:"arch_variant"` |
| 42 | Static_libs []string `android:"arch_variant"` |
| 43 | Shared_libs []string `android:"arch_variant"` |
| 44 | } `android:"arch_variant"` |
| 45 | |
| 46 | // local file name to pass to the linker as --version_script |
| 47 | Version_script *string `android:"arch_variant"` |
| 48 | // local file name to pass to the linker as -unexported_symbols_list |
| 49 | Unexported_symbols_list *string `android:"arch_variant"` |
| 50 | // local file name to pass to the linker as -force_symbols_not_weak_list |
| 51 | Force_symbols_not_weak_list *string `android:"arch_variant"` |
| 52 | // local file name to pass to the linker as -force_symbols_weak_list |
| 53 | Force_symbols_weak_list *string `android:"arch_variant"` |
| 54 | |
| 55 | // rename host libraries to prevent overlap with system installed libraries |
| 56 | Unique_host_soname *bool |
| 57 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 58 | Aidl struct { |
| 59 | // export headers generated from .aidl sources |
| 60 | Export_aidl_headers bool |
| 61 | } |
| 62 | |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 63 | Proto struct { |
| 64 | // export headers generated from .proto sources |
| 65 | Export_proto_headers bool |
| 66 | } |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 67 | } |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 68 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 69 | type LibraryMutatedProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 70 | VariantName string `blueprint:"mutated"` |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 71 | |
| 72 | // Build a static variant |
| 73 | BuildStatic bool `blueprint:"mutated"` |
| 74 | // Build a shared variant |
| 75 | BuildShared bool `blueprint:"mutated"` |
| 76 | // This variant is shared |
| 77 | VariantIsShared bool `blueprint:"mutated"` |
| 78 | // This variant is static |
| 79 | VariantIsStatic bool `blueprint:"mutated"` |
| 80 | } |
| 81 | |
| 82 | type FlagExporterProperties struct { |
| 83 | // list of directories relative to the Blueprints file that will |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 84 | // be added to the include path (using -I) for this module and any module that links |
| 85 | // against this module |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 86 | Export_include_dirs []string `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 90 | android.RegisterModuleType("cc_library_static", libraryStaticFactory) |
| 91 | android.RegisterModuleType("cc_library_shared", librarySharedFactory) |
| 92 | android.RegisterModuleType("cc_library", libraryFactory) |
| 93 | android.RegisterModuleType("cc_library_host_static", libraryHostStaticFactory) |
| 94 | android.RegisterModuleType("cc_library_host_shared", libraryHostSharedFactory) |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 95 | android.RegisterModuleType("cc_library_headers", libraryHeaderFactory) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // Module factory for combined static + shared libraries, device by default but with possible host |
| 99 | // support |
| 100 | func libraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 101 | module, _ := NewLibrary(android.HostAndDeviceSupported) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 102 | return module.Init() |
| 103 | } |
| 104 | |
| 105 | // Module factory for static libraries |
| 106 | func libraryStaticFactory() (blueprint.Module, []interface{}) { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 107 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 108 | library.BuildOnlyStatic() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 109 | return module.Init() |
| 110 | } |
| 111 | |
| 112 | // Module factory for shared libraries |
| 113 | func librarySharedFactory() (blueprint.Module, []interface{}) { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 114 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 115 | library.BuildOnlyShared() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 116 | return module.Init() |
| 117 | } |
| 118 | |
| 119 | // Module factory for host static libraries |
| 120 | func libraryHostStaticFactory() (blueprint.Module, []interface{}) { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 121 | module, library := NewLibrary(android.HostSupported) |
| 122 | library.BuildOnlyStatic() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 123 | return module.Init() |
| 124 | } |
| 125 | |
| 126 | // Module factory for host shared libraries |
| 127 | func libraryHostSharedFactory() (blueprint.Module, []interface{}) { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 128 | module, library := NewLibrary(android.HostSupported) |
| 129 | library.BuildOnlyShared() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 130 | return module.Init() |
| 131 | } |
| 132 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 133 | // Module factory for header-only libraries |
| 134 | func libraryHeaderFactory() (blueprint.Module, []interface{}) { |
| 135 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 136 | library.HeaderOnly() |
| 137 | return module.Init() |
| 138 | } |
| 139 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 140 | type flagExporter struct { |
| 141 | Properties FlagExporterProperties |
| 142 | |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 143 | flags []string |
| 144 | flagsDeps android.Paths |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) { |
| 148 | includeDirs := android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs) |
| 149 | for _, dir := range includeDirs.Strings() { |
| 150 | f.flags = append(f.flags, inc+dir) |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | func (f *flagExporter) reexportFlags(flags []string) { |
| 155 | f.flags = append(f.flags, flags...) |
| 156 | } |
| 157 | |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 158 | func (f *flagExporter) reexportDeps(deps android.Paths) { |
| 159 | f.flagsDeps = append(f.flagsDeps, deps...) |
| 160 | } |
| 161 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 162 | func (f *flagExporter) exportedFlags() []string { |
| 163 | return f.flags |
| 164 | } |
| 165 | |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 166 | func (f *flagExporter) exportedFlagsDeps() android.Paths { |
| 167 | return f.flagsDeps |
| 168 | } |
| 169 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 170 | type exportedFlagsProducer interface { |
| 171 | exportedFlags() []string |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 172 | exportedFlagsDeps() android.Paths |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 176 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 177 | // libraryDecorator wraps baseCompiler, baseLinker and baseInstaller to provide library-specific |
| 178 | // functionality: static vs. shared linkage, reusing object files for shared libraries |
| 179 | type libraryDecorator struct { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 180 | Properties LibraryProperties |
| 181 | MutatedProperties LibraryMutatedProperties |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 182 | |
| 183 | // For reusing static library objects for shared library |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 184 | reuseObjects Objects |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 185 | // table-of-contents file to optimize out relinking when possible |
| 186 | tocFile android.OptionalPath |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 187 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 188 | flagExporter |
| 189 | stripper |
Dan Willemsen | 394e9dc | 2016-09-14 15:04:48 -0700 | [diff] [blame] | 190 | relocationPacker |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 191 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 192 | // If we're used as a whole_static_lib, our missing dependencies need |
| 193 | // to be given |
| 194 | wholeStaticMissingDeps []string |
| 195 | |
| 196 | // For whole_static_libs |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 197 | objects Objects |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 198 | |
| 199 | // Uses the module's name if empty, but can be overridden. Does not include |
| 200 | // shlib suffix. |
| 201 | libName string |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 202 | |
| 203 | sanitize *sanitize |
| 204 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 205 | // Output archive of gcno coverage information files |
| 206 | coverageOutputFile android.OptionalPath |
| 207 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 208 | // Decorated interafaces |
| 209 | *baseCompiler |
| 210 | *baseLinker |
| 211 | *baseInstaller |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 214 | func (library *libraryDecorator) linkerProps() []interface{} { |
| 215 | var props []interface{} |
| 216 | props = append(props, library.baseLinker.linkerProps()...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 217 | return append(props, |
| 218 | &library.Properties, |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 219 | &library.MutatedProperties, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 220 | &library.flagExporter.Properties, |
Dan Willemsen | 394e9dc | 2016-09-14 15:04:48 -0700 | [diff] [blame] | 221 | &library.stripper.StripProperties, |
| 222 | &library.relocationPacker.Properties) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 225 | func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 226 | flags = library.baseLinker.linkerFlags(ctx, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 227 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 228 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 229 | // all code is position independent, and then those warnings get promoted to |
| 230 | // errors. |
| 231 | if ctx.Os() != android.Windows { |
| 232 | flags.CFlags = append(flags.CFlags, "-fPIC") |
| 233 | } |
| 234 | |
| 235 | if library.static() { |
| 236 | flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...) |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 237 | } else if library.shared() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 238 | flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...) |
| 239 | } |
| 240 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 241 | if library.shared() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 242 | libName := library.getLibName(ctx) |
| 243 | // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead |
| 244 | sharedFlag := "-Wl,-shared" |
| 245 | if flags.Clang || ctx.Host() { |
| 246 | sharedFlag = "-shared" |
| 247 | } |
| 248 | var f []string |
| 249 | if ctx.Device() { |
| 250 | f = append(f, |
| 251 | "-nostdlib", |
| 252 | "-Wl,--gc-sections", |
| 253 | ) |
| 254 | } |
| 255 | |
| 256 | if ctx.Darwin() { |
| 257 | f = append(f, |
| 258 | "-dynamiclib", |
| 259 | "-single_module", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 260 | "-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(), |
| 261 | ) |
Colin Cross | 7863cf5 | 2016-10-20 10:47:21 -0700 | [diff] [blame] | 262 | if ctx.Arch().ArchType == android.X86 { |
| 263 | f = append(f, |
| 264 | "-read_only_relocs suppress", |
| 265 | ) |
| 266 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 267 | } else { |
| 268 | f = append(f, |
| 269 | sharedFlag, |
| 270 | "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix()) |
| 271 | } |
| 272 | |
| 273 | flags.LdFlags = append(f, flags.LdFlags...) |
| 274 | } |
| 275 | |
| 276 | return flags |
| 277 | } |
| 278 | |
Dan Willemsen | 273af7f | 2016-11-03 15:53:42 -0700 | [diff] [blame] | 279 | func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags { |
| 280 | exportIncludeDirs := android.PathsForModuleSrc(ctx, library.flagExporter.Properties.Export_include_dirs) |
| 281 | if len(exportIncludeDirs) > 0 { |
| 282 | flags.GlobalFlags = append(flags.GlobalFlags, includeDirsToFlags(exportIncludeDirs)) |
| 283 | } |
| 284 | |
| 285 | return library.baseCompiler.compilerFlags(ctx, flags) |
| 286 | } |
| 287 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 288 | func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 289 | if !library.buildShared() && !library.buildStatic() { |
| 290 | if len(library.baseCompiler.Properties.Srcs) > 0 { |
| 291 | ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs") |
| 292 | } |
| 293 | if len(library.Properties.Static.Srcs) > 0 { |
| 294 | ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs") |
| 295 | } |
| 296 | if len(library.Properties.Shared.Srcs) > 0 { |
| 297 | ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs") |
| 298 | } |
| 299 | return Objects{} |
| 300 | } |
| 301 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 302 | objs := library.baseCompiler.compile(ctx, flags, deps) |
| 303 | library.reuseObjects = objs |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 304 | buildFlags := flagsToBuilderFlags(flags) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 305 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 306 | if library.static() { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 307 | srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 308 | objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary, |
| 309 | srcs, library.baseCompiler.deps)) |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 310 | } else if library.shared() { |
Colin Cross | 2f33635 | 2016-10-26 10:03:47 -0700 | [diff] [blame] | 311 | srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 312 | objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary, |
| 313 | srcs, library.baseCompiler.deps)) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 316 | return objs |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | type libraryInterface interface { |
| 320 | getWholeStaticMissingDeps() []string |
| 321 | static() bool |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 322 | objs() Objects |
| 323 | reuseObjs() Objects |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 324 | toc() android.OptionalPath |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 325 | |
| 326 | // Returns true if the build options for the module have selected a static or shared build |
| 327 | buildStatic() bool |
| 328 | buildShared() bool |
| 329 | |
| 330 | // Sets whether a specific variant is static or shared |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 331 | setStatic() |
| 332 | setShared() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | func (library *libraryDecorator) getLibName(ctx ModuleContext) string { |
| 336 | name := library.libName |
| 337 | if name == "" { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 338 | name = ctx.baseModuleName() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | if ctx.Host() && Bool(library.Properties.Unique_host_soname) { |
| 342 | if !strings.HasSuffix(name, "-host") { |
| 343 | name = name + "-host" |
| 344 | } |
| 345 | } |
| 346 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 347 | return name + library.MutatedProperties.VariantName |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) { |
| 351 | location := InstallInSystem |
| 352 | if library.sanitize.inData() { |
| 353 | location = InstallInData |
| 354 | } |
| 355 | library.baseInstaller.location = location |
| 356 | |
| 357 | library.baseLinker.linkerInit(ctx) |
Dan Willemsen | 394e9dc | 2016-09-14 15:04:48 -0700 | [diff] [blame] | 358 | |
| 359 | library.relocationPacker.packingInit(ctx) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 362 | func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 363 | deps = library.baseLinker.linkerDeps(ctx, deps) |
| 364 | |
| 365 | if library.static() { |
| 366 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, |
| 367 | library.Properties.Static.Whole_static_libs...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 368 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...) |
| 369 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...) |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 370 | } else if library.shared() { |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 371 | if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) { |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 372 | if !ctx.sdk() && !ctx.vndk() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 373 | deps.CrtBegin = "crtbegin_so" |
| 374 | deps.CrtEnd = "crtend_so" |
| 375 | } else { |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 376 | // TODO(danalbert): Add generation of crt objects. |
| 377 | // For `sdk_version: "current"`, we don't actually have a |
| 378 | // freshly generated set of CRT objects. Use the last stable |
| 379 | // version. |
| 380 | version := ctx.sdkVersion() |
| 381 | if version == "current" { |
| 382 | version = ctx.AConfig().PlatformSdkVersion() |
| 383 | } |
| 384 | deps.CrtBegin = "ndk_crtbegin_so." + version |
| 385 | deps.CrtEnd = "ndk_crtend_so." + version |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...) |
| 389 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...) |
| 390 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...) |
| 391 | } |
| 392 | |
| 393 | return deps |
| 394 | } |
| 395 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 396 | func (library *libraryDecorator) linkStatic(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 397 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 398 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 399 | library.objects = deps.WholeStaticLibObjs.Copy() |
| 400 | library.objects = library.objects.Append(objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 401 | |
| 402 | outputFile := android.PathForModuleOut(ctx, |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 403 | ctx.ModuleName()+library.MutatedProperties.VariantName+staticLibraryExtension) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 404 | builderFlags := flagsToBuilderFlags(flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 405 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 406 | TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles) |
| 407 | |
| 408 | library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags, |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 409 | ctx.ModuleName()+library.MutatedProperties.VariantName) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 410 | |
| 411 | library.wholeStaticMissingDeps = ctx.GetMissingDependencies() |
| 412 | |
| 413 | ctx.CheckbuildFile(outputFile) |
| 414 | |
| 415 | return outputFile |
| 416 | } |
| 417 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 418 | func (library *libraryDecorator) linkShared(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 419 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 420 | |
| 421 | var linkerDeps android.Paths |
| 422 | |
| 423 | versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script) |
| 424 | unexportedSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Unexported_symbols_list) |
| 425 | forceNotWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_not_weak_list) |
| 426 | forceWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_weak_list) |
| 427 | if !ctx.Darwin() { |
| 428 | if versionScript.Valid() { |
| 429 | flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String()) |
| 430 | linkerDeps = append(linkerDeps, versionScript.Path()) |
| 431 | } |
| 432 | if unexportedSymbols.Valid() { |
| 433 | ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin") |
| 434 | } |
| 435 | if forceNotWeakSymbols.Valid() { |
| 436 | ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin") |
| 437 | } |
| 438 | if forceWeakSymbols.Valid() { |
| 439 | ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin") |
| 440 | } |
| 441 | } else { |
| 442 | if versionScript.Valid() { |
| 443 | ctx.PropertyErrorf("version_script", "Not supported on Darwin") |
| 444 | } |
| 445 | if unexportedSymbols.Valid() { |
| 446 | flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String()) |
| 447 | linkerDeps = append(linkerDeps, unexportedSymbols.Path()) |
| 448 | } |
| 449 | if forceNotWeakSymbols.Valid() { |
| 450 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String()) |
| 451 | linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path()) |
| 452 | } |
| 453 | if forceWeakSymbols.Valid() { |
| 454 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String()) |
| 455 | linkerDeps = append(linkerDeps, forceWeakSymbols.Path()) |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix() |
| 460 | outputFile := android.PathForModuleOut(ctx, fileName) |
| 461 | ret := outputFile |
| 462 | |
| 463 | builderFlags := flagsToBuilderFlags(flags) |
| 464 | |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 465 | if !ctx.Darwin() { |
| 466 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 467 | // depending on a table of contents file instead of the library itself. |
| 468 | tocPath := outputFile.RelPathString() |
| 469 | tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc") |
| 470 | tocFile := android.PathForOutput(ctx, tocPath) |
| 471 | library.tocFile = android.OptionalPathForPath(tocFile) |
| 472 | TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags) |
| 473 | } |
| 474 | |
Dan Willemsen | 394e9dc | 2016-09-14 15:04:48 -0700 | [diff] [blame] | 475 | if library.relocationPacker.needsPacking(ctx) { |
| 476 | packedOutputFile := outputFile |
| 477 | outputFile = android.PathForModuleOut(ctx, "unpacked", fileName) |
| 478 | library.relocationPacker.pack(ctx, outputFile, packedOutputFile, builderFlags) |
| 479 | } |
| 480 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 481 | if library.stripper.needsStrip(ctx) { |
| 482 | strippedOutputFile := outputFile |
| 483 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
| 484 | library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 485 | } |
| 486 | |
| 487 | sharedLibs := deps.SharedLibs |
| 488 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
| 489 | |
Dan Albert | d015c4a | 2016-08-10 14:34:08 -0700 | [diff] [blame] | 490 | // TODO(danalbert): Clean this up when soong supports prebuilts. |
| 491 | if strings.HasPrefix(ctx.selectedStl(), "ndk_libc++") { |
| 492 | libDir := getNdkStlLibDir(ctx, flags.Toolchain, "libc++") |
| 493 | |
| 494 | if strings.HasSuffix(ctx.selectedStl(), "_shared") { |
| 495 | deps.StaticLibs = append(deps.StaticLibs, |
| 496 | libDir.Join(ctx, "libandroid_support.a")) |
| 497 | } else { |
| 498 | deps.StaticLibs = append(deps.StaticLibs, |
| 499 | libDir.Join(ctx, "libc++abi.a"), |
| 500 | libDir.Join(ctx, "libandroid_support.a")) |
| 501 | } |
| 502 | |
| 503 | if ctx.Arch().ArchType == android.Arm { |
| 504 | deps.StaticLibs = append(deps.StaticLibs, |
| 505 | libDir.Join(ctx, "libunwind.a")) |
| 506 | } |
| 507 | } |
| 508 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 509 | linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) |
| 510 | linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 511 | linkerDeps = append(linkerDeps, objs.tidyFiles...) |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 512 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 513 | TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 514 | deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, |
| 515 | linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile) |
| 516 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 517 | objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) |
| 518 | objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) |
| 519 | library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx)) |
| 520 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 521 | return ret |
| 522 | } |
| 523 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 524 | func (library *libraryDecorator) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 525 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 526 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 527 | objs = objs.Append(deps.Objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 528 | |
| 529 | var out android.Path |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 530 | if library.static() || library.header() { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 531 | out = library.linkStatic(ctx, flags, deps, objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 532 | } else { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 533 | out = library.linkShared(ctx, flags, deps, objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | library.exportIncludes(ctx, "-I") |
| 537 | library.reexportFlags(deps.ReexportedFlags) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 538 | library.reexportDeps(deps.ReexportedFlagsDeps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 539 | |
Dan Willemsen | e1240db | 2016-11-03 14:28:51 -0700 | [diff] [blame] | 540 | if library.Properties.Aidl.Export_aidl_headers { |
| 541 | if library.baseCompiler.hasSrcExt(".aidl") { |
| 542 | library.reexportFlags([]string{ |
| 543 | "-I" + android.PathForModuleGen(ctx, "aidl").String(), |
| 544 | }) |
| 545 | library.reexportDeps(library.baseCompiler.deps) // TODO: restrict to aidl deps |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if library.Properties.Proto.Export_proto_headers { |
| 550 | if library.baseCompiler.hasSrcExt(".proto") { |
Colin Cross | 0c461f1 | 2016-10-20 16:11:43 -0700 | [diff] [blame] | 551 | library.reexportFlags([]string{ |
| 552 | "-I" + protoSubDir(ctx).String(), |
| 553 | "-I" + protoDir(ctx).String(), |
| 554 | }) |
| 555 | library.reexportDeps(library.baseCompiler.deps) // TODO: restrict to proto deps |
| 556 | } |
| 557 | } |
| 558 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 559 | return out |
| 560 | } |
| 561 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 562 | func (library *libraryDecorator) buildStatic() bool { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 563 | return library.MutatedProperties.BuildStatic && |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 564 | (library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled) |
| 565 | } |
| 566 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 567 | func (library *libraryDecorator) buildShared() bool { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 568 | return library.MutatedProperties.BuildShared && |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 569 | (library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled) |
| 570 | } |
| 571 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 572 | func (library *libraryDecorator) getWholeStaticMissingDeps() []string { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 573 | return library.wholeStaticMissingDeps |
| 574 | } |
| 575 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 576 | func (library *libraryDecorator) objs() Objects { |
| 577 | return library.objects |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 580 | func (library *libraryDecorator) reuseObjs() Objects { |
| 581 | return library.reuseObjects |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 584 | func (library *libraryDecorator) toc() android.OptionalPath { |
| 585 | return library.tocFile |
| 586 | } |
| 587 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 588 | func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { |
| 589 | if !ctx.static() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 590 | library.baseInstaller.install(ctx, file) |
| 591 | } |
| 592 | } |
| 593 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 594 | func (library *libraryDecorator) static() bool { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 595 | return library.MutatedProperties.VariantIsStatic |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 598 | func (library *libraryDecorator) shared() bool { |
| 599 | return library.MutatedProperties.VariantIsShared |
| 600 | } |
| 601 | |
| 602 | func (library *libraryDecorator) header() bool { |
| 603 | return !library.static() && !library.shared() |
| 604 | } |
| 605 | |
| 606 | func (library *libraryDecorator) setStatic() { |
| 607 | library.MutatedProperties.VariantIsStatic = true |
| 608 | library.MutatedProperties.VariantIsShared = false |
| 609 | } |
| 610 | |
| 611 | func (library *libraryDecorator) setShared() { |
| 612 | library.MutatedProperties.VariantIsStatic = false |
| 613 | library.MutatedProperties.VariantIsShared = true |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 616 | func (library *libraryDecorator) BuildOnlyStatic() { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 617 | library.MutatedProperties.BuildShared = false |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | func (library *libraryDecorator) BuildOnlyShared() { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 621 | library.MutatedProperties.BuildStatic = false |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 622 | } |
| 623 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 624 | func (library *libraryDecorator) HeaderOnly() { |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 625 | library.MutatedProperties.BuildShared = false |
| 626 | library.MutatedProperties.BuildStatic = false |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 629 | func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 630 | module := newModule(hod, android.MultilibBoth) |
| 631 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 632 | library := &libraryDecorator{ |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 633 | MutatedProperties: LibraryMutatedProperties{ |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 634 | BuildShared: true, |
| 635 | BuildStatic: true, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 636 | }, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 637 | baseCompiler: NewBaseCompiler(), |
| 638 | baseLinker: NewBaseLinker(), |
| 639 | baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem), |
| 640 | sanitize: module.sanitize, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 643 | module.compiler = library |
| 644 | module.linker = library |
| 645 | module.installer = library |
| 646 | |
| 647 | return module, library |
| 648 | } |
| 649 | |
| 650 | func linkageMutator(mctx android.BottomUpMutatorContext) { |
| 651 | if m, ok := mctx.Module().(*Module); ok && m.linker != nil { |
| 652 | if library, ok := m.linker.(libraryInterface); ok { |
| 653 | var modules []blueprint.Module |
| 654 | if library.buildStatic() && library.buildShared() { |
| 655 | modules = mctx.CreateLocalVariations("static", "shared") |
| 656 | static := modules[0].(*Module) |
| 657 | shared := modules[1].(*Module) |
| 658 | |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 659 | static.linker.(libraryInterface).setStatic() |
| 660 | shared.linker.(libraryInterface).setShared() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 661 | |
| 662 | if staticCompiler, ok := static.compiler.(*libraryDecorator); ok { |
| 663 | sharedCompiler := shared.compiler.(*libraryDecorator) |
| 664 | if len(staticCompiler.Properties.Static.Cflags) == 0 && |
| 665 | len(sharedCompiler.Properties.Shared.Cflags) == 0 { |
| 666 | // Optimize out compiling common .o files twice for static+shared libraries |
| 667 | mctx.AddInterVariantDependency(reuseObjTag, shared, static) |
| 668 | sharedCompiler.baseCompiler.Properties.Srcs = nil |
| 669 | sharedCompiler.baseCompiler.Properties.Generated_sources = nil |
| 670 | } |
| 671 | } |
| 672 | } else if library.buildStatic() { |
| 673 | modules = mctx.CreateLocalVariations("static") |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 674 | modules[0].(*Module).linker.(libraryInterface).setStatic() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 675 | } else if library.buildShared() { |
| 676 | modules = mctx.CreateLocalVariations("shared") |
Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 677 | modules[0].(*Module).linker.(libraryInterface).setShared() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 681 | } |