Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // |
| 2 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | // you may not use this file except in compliance with the License. |
| 4 | // You may obtain a copy of the License at |
| 5 | // |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | // |
| 8 | // Unless required by applicable law or agreed to in writing, software |
| 9 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | // See the License for the specific language governing permissions and |
| 12 | // limitations under the License. |
| 13 | |
| 14 | package cc |
| 15 | |
| 16 | // This file contains the module types for compiling C/C++ for Android, and converts the properties |
| 17 | // into the flags and filenames necessary to pass to the compiler. The final creation of the rules |
| 18 | // is handled in builder.go |
| 19 | |
| 20 | import ( |
| 21 | "blueprint" |
| 22 | "blueprint/pathtools" |
| 23 | "fmt" |
| 24 | "path/filepath" |
| 25 | "strings" |
| 26 | |
| 27 | "android/soong/common" |
| 28 | ) |
| 29 | |
| 30 | type Config interface { |
| 31 | SrcDir() string |
| 32 | PrebuiltOS() string |
| 33 | } |
| 34 | |
| 35 | var ( |
| 36 | HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", Config.PrebuiltOS) |
| 37 | SrcDir = pctx.VariableConfigMethod("SrcDir", Config.SrcDir) |
| 38 | |
| 39 | LibcRoot = pctx.StaticVariable("LibcRoot", "${SrcDir}/bionic/libc") |
| 40 | LibmRoot = pctx.StaticVariable("LibmRoot", "${SrcDir}/bionic/libm") |
| 41 | ) |
| 42 | |
| 43 | // Flags used by lots of devices. Putting them in package static variables will save bytes in |
| 44 | // build.ninja so they aren't repeated for every file |
| 45 | var ( |
| 46 | commonGlobalCflags = []string{ |
| 47 | "-DANDROID", |
| 48 | "-fmessage-length=0", |
| 49 | "-W", |
| 50 | "-Wall", |
| 51 | "-Wno-unused", |
| 52 | "-Winit-self", |
| 53 | "-Wpointer-arith", |
| 54 | |
| 55 | // COMMON_RELEASE_CFLAGS |
| 56 | "-DNDEBUG", |
| 57 | "-UDEBUG", |
| 58 | } |
| 59 | |
| 60 | deviceGlobalCflags = []string{ |
| 61 | // TARGET_ERROR_FLAGS |
| 62 | "-Werror=return-type", |
| 63 | "-Werror=non-virtual-dtor", |
| 64 | "-Werror=address", |
| 65 | "-Werror=sequence-point", |
| 66 | } |
| 67 | |
| 68 | hostGlobalCflags = []string{} |
| 69 | |
| 70 | commonGlobalCppflags = []string{ |
| 71 | "-Wsign-promo", |
| 72 | "-std=gnu++11", |
| 73 | } |
| 74 | ) |
| 75 | |
| 76 | func init() { |
| 77 | pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
| 78 | pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
| 79 | pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
| 80 | |
| 81 | pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
| 82 | |
| 83 | pctx.StaticVariable("commonClangGlobalCflags", |
| 84 | strings.Join(clangFilterUnknownCflags(commonGlobalCflags), " ")) |
| 85 | pctx.StaticVariable("deviceClangGlobalCflags", |
| 86 | strings.Join(clangFilterUnknownCflags(deviceGlobalCflags), " ")) |
| 87 | pctx.StaticVariable("hostClangGlobalCflags", |
| 88 | strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " ")) |
Tim Kilbourn | f294814 | 2015-03-11 12:03:03 -0700 | [diff] [blame] | 89 | pctx.StaticVariable("commonClangGlobalCppflags", |
| 90 | strings.Join(clangFilterUnknownCflags(commonGlobalCppflags), " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 91 | |
| 92 | // Everything in this list is a crime against abstraction and dependency tracking. |
| 93 | // Do not add anything to this list. |
| 94 | pctx.StaticVariable("commonGlobalIncludes", strings.Join([]string{ |
| 95 | "-isystem ${SrcDir}/system/core/include", |
| 96 | "-isystem ${SrcDir}/hardware/libhardware/include", |
| 97 | "-isystem ${SrcDir}/hardware/libhardware_legacy/include", |
| 98 | "-isystem ${SrcDir}/hardware/ril/include", |
| 99 | "-isystem ${SrcDir}/libnativehelper/include", |
| 100 | "-isystem ${SrcDir}/frameworks/native/include", |
| 101 | "-isystem ${SrcDir}/frameworks/native/opengl/include", |
| 102 | "-isystem ${SrcDir}/frameworks/av/include", |
| 103 | "-isystem ${SrcDir}/frameworks/base/include", |
| 104 | }, " ")) |
| 105 | |
| 106 | pctx.StaticVariable("clangPath", "${SrcDir}/prebuilts/clang/${HostPrebuiltTag}/host/3.6/bin/") |
| 107 | } |
| 108 | |
| 109 | // CcProperties describes properties used to compile all C or C++ modules |
| 110 | type ccProperties struct { |
| 111 | // srcs: list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files. |
| 112 | Srcs []string `android:"arch_variant,arch_subtract"` |
| 113 | |
| 114 | // cflags: list of module-specific flags that will be used for C and C++ compiles. |
| 115 | Cflags []string `android:"arch_variant"` |
| 116 | |
| 117 | // cppflags: list of module-specific flags that will be used for C++ compiles |
| 118 | Cppflags []string `android:"arch_variant"` |
| 119 | |
| 120 | // conlyflags: list of module-specific flags that will be used for C compiles |
| 121 | Conlyflags []string `android:"arch_variant"` |
| 122 | |
| 123 | // asflags: list of module-specific flags that will be used for .S compiles |
| 124 | Asflags []string `android:"arch_variant"` |
| 125 | |
| 126 | // ldflags: list of module-specific flags that will be used for all link steps |
| 127 | Ldflags []string `android:"arch_variant"` |
| 128 | |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 129 | // instruction_set: the instruction set architecture to use to compile the C/C++ |
| 130 | // module. |
| 131 | Instruction_set string `android:"arch_variant"` |
| 132 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 133 | // include_dirs: list of directories relative to the root of the source tree that will |
| 134 | // be added to the include path using -I. |
| 135 | // If possible, don't use this. If adding paths from the current directory use |
| 136 | // local_include_dirs, if adding paths from other modules use export_include_dirs in |
| 137 | // that module. |
| 138 | Include_dirs []string `android:"arch_variant"` |
| 139 | |
| 140 | // local_include_dirs: list of directories relative to the Blueprints file that will |
| 141 | // be added to the include path using -I |
| 142 | Local_include_dirs []string `android:"arch_variant"` |
| 143 | |
| 144 | // export_include_dirs: list of directories relative to the Blueprints file that will |
| 145 | // be added to the include path using -I for any module that links against this module |
| 146 | Export_include_dirs []string |
| 147 | |
| 148 | // clang_cflags: list of module-specific flags that will be used for C and C++ compiles when |
| 149 | // compiling with clang |
| 150 | Clang_cflags []string `android:"arch_variant"` |
| 151 | |
| 152 | // clang_asflags: list of module-specific flags that will be used for .S compiles when |
| 153 | // compiling with clang |
| 154 | Clang_asflags []string `android:"arch_variant"` |
| 155 | |
| 156 | // system_shared_libs: list of system libraries that will be dynamically linked to |
| 157 | // shared library and executable modules. If unset, generally defaults to libc |
| 158 | // and libm. Set to [] to prevent linking against libc and libm. |
| 159 | System_shared_libs []string |
| 160 | |
| 161 | // whole_static_libs: list of modules whose object files should be linked into this module |
| 162 | // in their entirety. For static library modules, all of the .o files from the intermediate |
| 163 | // directory of the dependency will be linked into this modules .a file. For a shared library, |
| 164 | // the dependency's .a file will be linked into this module using -Wl,--whole-archive. |
| 165 | Whole_static_libs []string `android:"arch_variant"` |
| 166 | |
| 167 | // static_libs: list of modules that should be statically linked into this module. |
| 168 | Static_libs []string `android:"arch_variant"` |
| 169 | |
| 170 | // shared_libs: list of modules that should be dynamically linked into this module. |
| 171 | Shared_libs []string `android:"arch_variant"` |
| 172 | |
| 173 | // allow_undefined_symbols: allow the module to contain undefined symbols. By default, |
| 174 | // modules cannot contain undefined symbols that are not satisified by their immediate |
| 175 | // dependencies. Set this flag to true to remove --no-undefined from the linker flags. |
| 176 | // This flag should only be necessary for compiling low-level libraries like libc. |
| 177 | Allow_undefined_symbols bool |
| 178 | |
| 179 | // nocrt: don't link in crt_begin and crt_end. This flag should only be necessary for |
| 180 | // compiling crt or libc. |
| 181 | Nocrt bool `android:"arch_variant"` |
| 182 | |
| 183 | // no_default_compiler_flags: don't insert default compiler flags into asflags, cflags, |
| 184 | // cppflags, conlyflags, ldflags, or include_dirs |
| 185 | No_default_compiler_flags bool |
| 186 | |
| 187 | // clang: compile module with clang instead of gcc |
| 188 | Clang bool `android:"arch_variant"` |
| 189 | |
| 190 | // rtti: pass -frtti instead of -fno-rtti |
| 191 | Rtti bool |
| 192 | |
| 193 | // host_ldlibs: -l arguments to pass to linker for host-provided shared libraries |
| 194 | Host_ldlibs []string `android:"arch_variant"` |
| 195 | |
| 196 | // stl: select the STL library to use. Possible values are "libc++", "libc++_static", |
| 197 | // "stlport", "stlport_static", "ndk", "libstdc++", or "none". Leave blank to select the |
| 198 | // default |
| 199 | Stl string |
| 200 | |
| 201 | // Set for combined shared/static libraries to prevent compiling object files a second time |
| 202 | SkipCompileObjs bool `blueprint:"mutated"` |
Colin Cross | af19a29 | 2015-03-18 12:07:10 -0700 | [diff] [blame^] | 203 | |
| 204 | Debug struct { |
| 205 | Cflags []string `android:"arch_variant"` |
| 206 | } `android:"arch_variant"` |
| 207 | Release struct { |
| 208 | Cflags []string `android:"arch_variant"` |
| 209 | } `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | type unusedProperties struct { |
| 213 | Asan bool |
| 214 | Native_coverage bool |
| 215 | Strip string |
| 216 | Tags []string |
| 217 | Required []string |
| 218 | } |
| 219 | |
| 220 | // Building C/C++ code is handled by objects that satisfy this interface via composition |
| 221 | type ccModuleType interface { |
| 222 | common.AndroidModule |
| 223 | |
| 224 | // Return the cflags that are specific to this _type_ of module |
| 225 | moduleTypeCflags(common.AndroidModuleContext, toolchain) []string |
| 226 | |
| 227 | // Return the ldflags that are specific to this _type_ of module |
| 228 | moduleTypeLdflags(common.AndroidModuleContext, toolchain) []string |
| 229 | |
| 230 | // Create a ccDeps struct that collects the module dependency info. Can also |
| 231 | // modify ccFlags in order to add dependency include directories, etc. |
| 232 | collectDeps(common.AndroidModuleContext, ccFlags) (ccDeps, ccFlags) |
| 233 | |
| 234 | // Compile objects into final module |
| 235 | compileModule(common.AndroidModuleContext, ccFlags, ccDeps, []string) |
| 236 | |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 237 | // Install the built module. |
| 238 | installModule(common.AndroidModuleContext, ccFlags) |
| 239 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 240 | // Return the output file (.o, .a or .so) for use by other modules |
| 241 | outputFile() string |
| 242 | } |
| 243 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 244 | type ccDeps struct { |
| 245 | staticLibs, sharedLibs, lateStaticLibs, wholeStaticLibs, objFiles, includeDirs []string |
| 246 | |
| 247 | crtBegin, crtEnd string |
| 248 | } |
| 249 | |
| 250 | type ccFlags struct { |
| 251 | globalFlags []string |
| 252 | asFlags []string |
| 253 | cFlags []string |
| 254 | conlyFlags []string |
| 255 | cppFlags []string |
| 256 | ldFlags []string |
| 257 | ldLibs []string |
| 258 | includeDirs []string |
| 259 | nocrt bool |
| 260 | toolchain toolchain |
| 261 | clang bool |
| 262 | |
| 263 | extraStaticLibs []string |
| 264 | extraSharedLibs []string |
| 265 | } |
| 266 | |
| 267 | // ccBase contains the properties and members used by all C/C++ module types, and implements |
| 268 | // the blueprint.Module interface. It expects to be embedded into an outer specialization struct, |
| 269 | // and uses a ccModuleType interface to that struct to create the build steps. |
| 270 | type ccBase struct { |
| 271 | common.AndroidModuleBase |
| 272 | module ccModuleType |
| 273 | |
| 274 | properties ccProperties |
| 275 | unused unusedProperties |
| 276 | |
| 277 | installPath string |
| 278 | } |
| 279 | |
| 280 | func newCCBase(base *ccBase, module ccModuleType, hod common.HostOrDeviceSupported, |
| 281 | multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) { |
| 282 | |
| 283 | base.module = module |
| 284 | |
| 285 | props = append(props, &base.properties, &base.unused) |
| 286 | |
| 287 | return common.InitAndroidModule(module, hod, multilib, props...) |
| 288 | } |
| 289 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 290 | func (c *ccBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 291 | toolchain := c.findToolchain(ctx) |
| 292 | if ctx.Failed() { |
| 293 | return |
| 294 | } |
| 295 | |
| 296 | flags := c.flags(ctx, toolchain) |
| 297 | if ctx.Failed() { |
| 298 | return |
| 299 | } |
| 300 | |
| 301 | flags = c.addStlFlags(ctx, flags) |
| 302 | if ctx.Failed() { |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | deps, flags := c.ccModuleType().collectDeps(ctx, flags) |
| 307 | if ctx.Failed() { |
| 308 | return |
| 309 | } |
| 310 | |
| 311 | objFiles := c.compileObjs(ctx, flags, deps) |
| 312 | if ctx.Failed() { |
| 313 | return |
| 314 | } |
| 315 | |
| 316 | c.ccModuleType().compileModule(ctx, flags, deps, objFiles) |
| 317 | if ctx.Failed() { |
| 318 | return |
| 319 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 320 | |
| 321 | c.ccModuleType().installModule(ctx, flags) |
| 322 | if ctx.Failed() { |
| 323 | return |
| 324 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | func (c *ccBase) ccModuleType() ccModuleType { |
| 328 | return c.module |
| 329 | } |
| 330 | |
| 331 | var _ common.AndroidDynamicDepender = (*ccBase)(nil) |
| 332 | |
| 333 | func (c *ccBase) findToolchain(ctx common.AndroidModuleContext) toolchain { |
| 334 | arch := ctx.Arch() |
| 335 | factory := toolchainFactories[arch.HostOrDevice][arch.ArchType] |
| 336 | if factory == nil { |
| 337 | panic(fmt.Sprintf("Toolchain not found for %s arch %q", |
| 338 | arch.HostOrDevice.String(), arch.String())) |
| 339 | } |
| 340 | return factory(arch.ArchVariant, arch.CpuVariant) |
| 341 | } |
| 342 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 343 | func (c *ccBase) moduleTypeCflags(ctx common.AndroidModuleContext, toolchain toolchain) []string { |
| 344 | return nil |
| 345 | } |
| 346 | |
| 347 | func (c *ccBase) moduleTypeLdflags(ctx common.AndroidModuleContext, toolchain toolchain) []string { |
| 348 | return nil |
| 349 | } |
| 350 | |
| 351 | func (c *ccBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 352 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, c.properties.Whole_static_libs...) |
| 353 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, c.properties.Static_libs...) |
| 354 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, c.properties.Shared_libs...) |
| 355 | |
| 356 | return nil |
| 357 | } |
| 358 | |
| 359 | // Create a ccFlags struct that collects the compile flags from global values, |
| 360 | // per-target values, module type values, and per-module Blueprints properties |
| 361 | func (c *ccBase) flags(ctx common.AndroidModuleContext, toolchain toolchain) ccFlags { |
| 362 | |
| 363 | arch := ctx.Arch() |
| 364 | |
| 365 | flags := ccFlags{ |
| 366 | cFlags: c.properties.Cflags, |
| 367 | cppFlags: c.properties.Cppflags, |
| 368 | conlyFlags: c.properties.Conlyflags, |
| 369 | ldFlags: c.properties.Ldflags, |
| 370 | asFlags: c.properties.Asflags, |
| 371 | nocrt: c.properties.Nocrt, |
| 372 | toolchain: toolchain, |
| 373 | clang: c.properties.Clang, |
| 374 | } |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 375 | instructionSet := c.properties.Instruction_set |
| 376 | instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet) |
| 377 | if err != nil { |
| 378 | ctx.ModuleErrorf("%s", err) |
| 379 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 380 | |
Colin Cross | af19a29 | 2015-03-18 12:07:10 -0700 | [diff] [blame^] | 381 | // TODO: debug |
| 382 | flags.cFlags = append(flags.cFlags, c.properties.Release.Cflags...) |
| 383 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 384 | if arch.HostOrDevice.Host() { |
| 385 | // TODO: allow per-module clang disable for host |
| 386 | flags.clang = true |
| 387 | } |
| 388 | |
| 389 | if flags.clang { |
| 390 | flags.cFlags = clangFilterUnknownCflags(flags.cFlags) |
| 391 | flags.cFlags = append(flags.cFlags, c.properties.Clang_cflags...) |
| 392 | flags.asFlags = append(flags.asFlags, c.properties.Clang_asflags...) |
| 393 | flags.cppFlags = clangFilterUnknownCflags(flags.cppFlags) |
| 394 | flags.conlyFlags = clangFilterUnknownCflags(flags.conlyFlags) |
| 395 | flags.ldFlags = clangFilterUnknownCflags(flags.ldFlags) |
| 396 | |
Colin Cross | bdd7b1c | 2015-03-16 16:21:20 -0700 | [diff] [blame] | 397 | flags.cFlags = append(flags.cFlags, "${clangExtraCflags}") |
| 398 | flags.conlyFlags = append(flags.conlyFlags, "${clangExtraConlyflags}") |
| 399 | if arch.HostOrDevice.Device() { |
| 400 | flags.cFlags = append(flags.cFlags, "${clangExtraTargetCflags}") |
| 401 | } |
| 402 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 403 | target := "-target " + toolchain.ClangTriple() |
| 404 | gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin") |
| 405 | |
| 406 | flags.cFlags = append(flags.cFlags, target, gccPrefix) |
| 407 | flags.asFlags = append(flags.asFlags, target, gccPrefix) |
| 408 | flags.ldFlags = append(flags.ldFlags, target, gccPrefix) |
| 409 | |
| 410 | if arch.HostOrDevice.Host() { |
| 411 | gccToolchain := "--gcc-toolchain=" + toolchain.GccRoot() |
| 412 | sysroot := "--sysroot=" + filepath.Join(toolchain.GccRoot(), "sysroot") |
| 413 | |
| 414 | // TODO: also need more -B, -L flags to make host builds hermetic |
| 415 | flags.cFlags = append(flags.cFlags, gccToolchain, sysroot) |
| 416 | flags.asFlags = append(flags.asFlags, gccToolchain, sysroot) |
| 417 | flags.ldFlags = append(flags.ldFlags, gccToolchain, sysroot) |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | flags.includeDirs = pathtools.PrefixPaths(c.properties.Include_dirs, ctx.Config().(Config).SrcDir()) |
| 422 | localIncludeDirs := pathtools.PrefixPaths(c.properties.Local_include_dirs, common.ModuleSrcDir(ctx)) |
| 423 | flags.includeDirs = append(flags.includeDirs, localIncludeDirs...) |
| 424 | |
| 425 | if !c.properties.No_default_compiler_flags { |
| 426 | flags.includeDirs = append(flags.includeDirs, []string{ |
| 427 | common.ModuleSrcDir(ctx), |
| 428 | common.ModuleOutDir(ctx), |
| 429 | common.ModuleGenDir(ctx), |
| 430 | }...) |
| 431 | |
| 432 | if arch.HostOrDevice.Device() && !c.properties.Allow_undefined_symbols { |
| 433 | flags.ldFlags = append(flags.ldFlags, "-Wl,--no-undefined") |
| 434 | } |
| 435 | |
| 436 | if flags.clang { |
Tim Kilbourn | f294814 | 2015-03-11 12:03:03 -0700 | [diff] [blame] | 437 | flags.cppFlags = append(flags.cppFlags, "${commonClangGlobalCppflags}") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 438 | flags.globalFlags = []string{ |
| 439 | "${commonGlobalIncludes}", |
| 440 | toolchain.IncludeFlags(), |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 441 | instructionSetFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 442 | toolchain.ClangCflags(), |
| 443 | "${commonClangGlobalCflags}", |
| 444 | fmt.Sprintf("${%sClangGlobalCflags}", arch.HostOrDevice), |
| 445 | } |
| 446 | } else { |
Tim Kilbourn | f294814 | 2015-03-11 12:03:03 -0700 | [diff] [blame] | 447 | flags.cppFlags = append(flags.cppFlags, "${commonGlobalCppflags}") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 448 | flags.globalFlags = []string{ |
| 449 | "${commonGlobalIncludes}", |
| 450 | toolchain.IncludeFlags(), |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 451 | instructionSetFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 452 | toolchain.Cflags(), |
| 453 | "${commonGlobalCflags}", |
| 454 | fmt.Sprintf("${%sGlobalCflags}", arch.HostOrDevice), |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | if arch.HostOrDevice.Host() { |
| 459 | flags.ldFlags = append(flags.ldFlags, c.properties.Host_ldlibs...) |
| 460 | } |
| 461 | |
| 462 | if arch.HostOrDevice.Device() { |
| 463 | if c.properties.Rtti { |
| 464 | flags.cppFlags = append(flags.cppFlags, "-frtti") |
| 465 | } else { |
| 466 | flags.cppFlags = append(flags.cppFlags, "-fno-rtti") |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | flags.asFlags = append(flags.asFlags, "-D__ASSEMBLY__") |
| 471 | |
| 472 | if flags.clang { |
| 473 | flags.cppFlags = append(flags.cppFlags, toolchain.ClangCppflags()) |
| 474 | flags.ldFlags = append(flags.ldFlags, toolchain.ClangLdflags()) |
| 475 | } else { |
| 476 | flags.cppFlags = append(flags.cppFlags, toolchain.Cppflags()) |
| 477 | flags.ldFlags = append(flags.ldFlags, toolchain.Ldflags()) |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | flags.cFlags = append(flags.cFlags, c.ccModuleType().moduleTypeCflags(ctx, toolchain)...) |
| 482 | flags.ldFlags = append(flags.ldFlags, c.ccModuleType().moduleTypeLdflags(ctx, toolchain)...) |
| 483 | |
| 484 | // Optimization to reduce size of build.ninja |
| 485 | // Replace the long list of flags for each file with a module-local variable |
| 486 | ctx.Variable(pctx, "cflags", strings.Join(flags.cFlags, " ")) |
| 487 | ctx.Variable(pctx, "cppflags", strings.Join(flags.cppFlags, " ")) |
| 488 | ctx.Variable(pctx, "asflags", strings.Join(flags.asFlags, " ")) |
| 489 | flags.cFlags = []string{"$cflags"} |
| 490 | flags.cppFlags = []string{"$cppflags"} |
| 491 | flags.asFlags = []string{"$asflags"} |
| 492 | |
| 493 | return flags |
| 494 | } |
| 495 | |
| 496 | // Modify ccFlags structs with STL library info |
| 497 | func (c *ccBase) addStlFlags(ctx common.AndroidModuleContext, flags ccFlags) ccFlags { |
| 498 | if !c.properties.No_default_compiler_flags { |
| 499 | arch := ctx.Arch() |
| 500 | stl := "libc++" // TODO: mingw needs libstdc++ |
| 501 | if c.properties.Stl != "" { |
| 502 | stl = c.properties.Stl |
| 503 | } |
| 504 | |
| 505 | stlStatic := false |
| 506 | if strings.HasSuffix(stl, "_static") { |
| 507 | stlStatic = true |
| 508 | } |
| 509 | |
| 510 | switch stl { |
| 511 | case "libc++", "libc++_static": |
| 512 | flags.cFlags = append(flags.cFlags, "-D_USING_LIBCXX") |
| 513 | flags.includeDirs = append(flags.includeDirs, "${SrcDir}/external/libcxx/include") |
| 514 | if arch.HostOrDevice.Host() { |
| 515 | flags.cppFlags = append(flags.cppFlags, "-nostdinc++") |
| 516 | flags.ldFlags = append(flags.ldFlags, "-nodefaultlibs") |
| 517 | flags.ldLibs = append(flags.ldLibs, "-lc", "-lm", "-lpthread") |
| 518 | } |
| 519 | if stlStatic { |
| 520 | flags.extraStaticLibs = append(flags.extraStaticLibs, "libc++_static") |
| 521 | } else { |
| 522 | flags.extraSharedLibs = append(flags.extraSharedLibs, "libc++") |
| 523 | } |
| 524 | case "stlport", "stlport_static": |
| 525 | if arch.HostOrDevice.Device() { |
| 526 | flags.includeDirs = append(flags.includeDirs, |
| 527 | "${SrcDir}/external/stlport/stlport", |
| 528 | "${SrcDir}/bionic/libstdc++/include", |
| 529 | "${SrcDir}/bionic") |
| 530 | if stlStatic { |
| 531 | flags.extraStaticLibs = append(flags.extraStaticLibs, "libstdc++", "libstlport_static") |
| 532 | } else { |
| 533 | flags.extraSharedLibs = append(flags.extraSharedLibs, "libstdc++", "libstlport") |
| 534 | } |
| 535 | } |
| 536 | case "ndk": |
| 537 | panic("TODO") |
| 538 | case "libstdc++": |
| 539 | // Using bionic's basic libstdc++. Not actually an STL. Only around until the |
| 540 | // tree is in good enough shape to not need it. |
| 541 | // Host builds will use GNU libstdc++. |
| 542 | if arch.HostOrDevice.Device() { |
| 543 | flags.includeDirs = append(flags.includeDirs, "${SrcDir}/bionic/libstdc++/include") |
| 544 | flags.extraSharedLibs = append(flags.extraSharedLibs, "libstdc++") |
| 545 | } |
| 546 | case "none": |
| 547 | if arch.HostOrDevice.Host() { |
| 548 | flags.cppFlags = append(flags.cppFlags, "-nostdinc++") |
| 549 | flags.ldFlags = append(flags.ldFlags, "-nodefaultlibs") |
| 550 | flags.ldLibs = append(flags.ldLibs, "-lc", "-lm") |
| 551 | } |
| 552 | default: |
| 553 | ctx.ModuleErrorf("stl: %q is not a supported STL", stl) |
| 554 | } |
| 555 | |
| 556 | } |
| 557 | return flags |
| 558 | } |
| 559 | |
| 560 | // Compile a list of source files into objects a specified subdirectory |
| 561 | func (c *ccBase) customCompileObjs(ctx common.AndroidModuleContext, flags ccFlags, |
| 562 | deps ccDeps, subdir string, srcFiles []string) []string { |
| 563 | |
| 564 | srcFiles = pathtools.PrefixPaths(srcFiles, common.ModuleSrcDir(ctx)) |
| 565 | srcFiles = common.ExpandGlobs(ctx, srcFiles) |
| 566 | |
| 567 | return TransformSourceToObj(ctx, subdir, srcFiles, ccFlagsToBuilderFlags(flags)) |
| 568 | } |
| 569 | |
| 570 | // Compile files listed in c.properties.Srcs into objects |
| 571 | func (c *ccBase) compileObjs(ctx common.AndroidModuleContext, flags ccFlags, |
| 572 | deps ccDeps) []string { |
| 573 | |
| 574 | if c.properties.SkipCompileObjs { |
| 575 | return nil |
| 576 | } |
| 577 | |
| 578 | return c.customCompileObjs(ctx, flags, deps, "", c.properties.Srcs) |
| 579 | } |
| 580 | |
| 581 | func (c *ccBase) outputFile() string { |
| 582 | return "" |
| 583 | } |
| 584 | |
| 585 | func (c *ccBase) collectDepsFromList(ctx common.AndroidModuleContext, |
| 586 | names []string) (modules []common.AndroidModule, |
| 587 | outputFiles []string, exportedIncludeDirs []string) { |
| 588 | |
| 589 | for _, n := range names { |
| 590 | found := false |
| 591 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 592 | otherName := ctx.OtherModuleName(m) |
| 593 | if otherName != n { |
| 594 | return |
| 595 | } |
| 596 | |
| 597 | if a, ok := m.(ccModuleType); ok { |
| 598 | if a.Disabled() { |
| 599 | // If a cc_library host+device module depends on a library that exists as both |
| 600 | // cc_library_shared and cc_library_host_shared, it will end up with two |
| 601 | // dependencies with the same name, one of which is marked disabled for each |
| 602 | // of host and device. Ignore the disabled one. |
| 603 | return |
| 604 | } |
| 605 | if a.HostOrDevice() != ctx.Arch().HostOrDevice { |
| 606 | ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), |
| 607 | otherName) |
| 608 | return |
| 609 | } |
| 610 | |
| 611 | if outputFile := a.outputFile(); outputFile != "" { |
| 612 | if found { |
| 613 | ctx.ModuleErrorf("multiple modules satisified dependency on %q", otherName) |
| 614 | return |
| 615 | } |
| 616 | outputFiles = append(outputFiles, outputFile) |
| 617 | modules = append(modules, a) |
| 618 | if i, ok := a.(ccExportedIncludeDirsProducer); ok { |
| 619 | exportedIncludeDirs = append(exportedIncludeDirs, i.exportedIncludeDirs()...) |
| 620 | } |
| 621 | found = true |
| 622 | } else { |
| 623 | ctx.ModuleErrorf("module %q missing output file", otherName) |
| 624 | return |
| 625 | } |
| 626 | } else { |
| 627 | ctx.ModuleErrorf("module %q not an android module", otherName) |
| 628 | return |
| 629 | } |
| 630 | }) |
| 631 | if !found { |
| 632 | ctx.ModuleErrorf("unsatisified dependency on %q", n) |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | return modules, outputFiles, exportedIncludeDirs |
| 637 | } |
| 638 | |
| 639 | func (c *ccBase) collectDeps(ctx common.AndroidModuleContext, flags ccFlags) (ccDeps, ccFlags) { |
| 640 | var deps ccDeps |
| 641 | var newIncludeDirs []string |
| 642 | |
| 643 | wholeStaticLibNames := c.properties.Whole_static_libs |
| 644 | _, deps.wholeStaticLibs, newIncludeDirs = c.collectDepsFromList(ctx, wholeStaticLibNames) |
| 645 | |
| 646 | deps.includeDirs = append(deps.includeDirs, newIncludeDirs...) |
| 647 | |
| 648 | staticLibNames := c.properties.Static_libs |
| 649 | staticLibNames = append(staticLibNames, flags.extraStaticLibs...) |
| 650 | _, deps.staticLibs, newIncludeDirs = c.collectDepsFromList(ctx, staticLibNames) |
| 651 | deps.includeDirs = append(deps.includeDirs, newIncludeDirs...) |
| 652 | |
| 653 | return deps, flags |
| 654 | } |
| 655 | |
| 656 | // ccDynamic contains the properties and members used by shared libraries and dynamic executables |
| 657 | type ccDynamic struct { |
| 658 | ccBase |
| 659 | } |
| 660 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 661 | func newCCDynamic(dynamic *ccDynamic, module ccModuleType, hod common.HostOrDeviceSupported, |
| 662 | multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) { |
| 663 | |
| 664 | dynamic.properties.System_shared_libs = []string{defaultSystemSharedLibraries} |
| 665 | |
| 666 | return newCCBase(&dynamic.ccBase, module, hod, multilib, props...) |
| 667 | } |
| 668 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 669 | const defaultSystemSharedLibraries = "__default__" |
| 670 | |
| 671 | func (c *ccDynamic) systemSharedLibs() []string { |
| 672 | |
| 673 | if len(c.properties.System_shared_libs) == 1 && |
| 674 | c.properties.System_shared_libs[0] == defaultSystemSharedLibraries { |
| 675 | |
| 676 | if c.HostOrDevice().Host() { |
| 677 | return []string{} |
| 678 | } else { |
| 679 | return []string{"libc", "libm"} |
| 680 | } |
| 681 | } |
| 682 | return c.properties.System_shared_libs |
| 683 | } |
| 684 | |
| 685 | var ( |
| 686 | stlSharedLibs = []string{"libc++", "libstlport", "libstdc++"} |
| 687 | stlSharedHostLibs = []string{"libc++"} |
| 688 | stlStaticLibs = []string{"libc++_static", "libstlport_static", "libstdc++"} |
| 689 | stlStaticHostLibs = []string{"libc++_static"} |
| 690 | ) |
| 691 | |
| 692 | func (c *ccDynamic) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 693 | deps := c.ccBase.AndroidDynamicDependencies(ctx) |
| 694 | |
| 695 | if c.HostOrDevice().Device() { |
| 696 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, c.systemSharedLibs()...) |
| 697 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, |
| 698 | "libcompiler_rt-extras", |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 699 | "libgcov", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 700 | "libatomic", |
| 701 | "libgcc") |
| 702 | |
| 703 | if c.properties.Stl != "none" { |
| 704 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, stlSharedLibs...) |
| 705 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, stlStaticLibs...) |
| 706 | } |
| 707 | } else { |
| 708 | if c.properties.Stl != "none" { |
| 709 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, stlSharedHostLibs...) |
| 710 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, stlStaticHostLibs...) |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | return deps |
| 715 | } |
| 716 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 717 | func (c *ccDynamic) collectDeps(ctx common.AndroidModuleContext, flags ccFlags) (ccDeps, ccFlags) { |
| 718 | var newIncludeDirs []string |
| 719 | |
| 720 | deps, flags := c.ccBase.collectDeps(ctx, flags) |
| 721 | |
| 722 | systemSharedLibs := c.systemSharedLibs() |
| 723 | sharedLibNames := make([]string, 0, len(c.properties.Shared_libs)+len(systemSharedLibs)+ |
| 724 | len(flags.extraSharedLibs)) |
| 725 | sharedLibNames = append(sharedLibNames, c.properties.Shared_libs...) |
| 726 | sharedLibNames = append(sharedLibNames, systemSharedLibs...) |
| 727 | sharedLibNames = append(sharedLibNames, flags.extraSharedLibs...) |
| 728 | _, deps.sharedLibs, newIncludeDirs = c.collectDepsFromList(ctx, sharedLibNames) |
| 729 | deps.includeDirs = append(deps.includeDirs, newIncludeDirs...) |
| 730 | |
| 731 | if ctx.Arch().HostOrDevice.Device() { |
| 732 | var staticLibs []string |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 733 | staticLibNames := []string{"libcompiler_rt-extras"} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 734 | _, staticLibs, newIncludeDirs = c.collectDepsFromList(ctx, staticLibNames) |
| 735 | deps.staticLibs = append(deps.staticLibs, staticLibs...) |
| 736 | deps.includeDirs = append(deps.includeDirs, newIncludeDirs...) |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 737 | |
| 738 | // libgcc and libatomic have to be last on the command line |
| 739 | staticLibNames = []string{"libgcov", "libatomic", "libgcc"} |
| 740 | _, staticLibs, newIncludeDirs = c.collectDepsFromList(ctx, staticLibNames) |
| 741 | deps.lateStaticLibs = append(deps.lateStaticLibs, staticLibs...) |
| 742 | deps.includeDirs = append(deps.includeDirs, newIncludeDirs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 746 | if obj, ok := m.(*ccObject); ok { |
| 747 | otherName := ctx.OtherModuleName(m) |
| 748 | if strings.HasPrefix(otherName, "crtbegin") { |
| 749 | if !c.properties.Nocrt { |
| 750 | deps.crtBegin = obj.outputFile() |
| 751 | } |
| 752 | } else if strings.HasPrefix(otherName, "crtend") { |
| 753 | if !c.properties.Nocrt { |
| 754 | deps.crtEnd = obj.outputFile() |
| 755 | } |
| 756 | } else { |
| 757 | ctx.ModuleErrorf("object module type only support for crtbegin and crtend, found %q", |
| 758 | ctx.OtherModuleName(m)) |
| 759 | } |
| 760 | } |
| 761 | }) |
| 762 | |
| 763 | flags.includeDirs = append(flags.includeDirs, deps.includeDirs...) |
| 764 | |
| 765 | return deps, flags |
| 766 | } |
| 767 | |
| 768 | type ccExportedIncludeDirsProducer interface { |
| 769 | exportedIncludeDirs() []string |
| 770 | } |
| 771 | |
| 772 | // |
| 773 | // Combined static+shared libraries |
| 774 | // |
| 775 | |
| 776 | type ccLibrary struct { |
| 777 | ccDynamic |
| 778 | |
| 779 | primary *ccLibrary |
| 780 | primaryObjFiles []string |
| 781 | objFiles []string |
| 782 | exportIncludeDirs []string |
| 783 | out string |
| 784 | |
| 785 | libraryProperties struct { |
| 786 | BuildStatic bool `blueprint:"mutated"` |
| 787 | BuildShared bool `blueprint:"mutated"` |
| 788 | IsShared bool `blueprint:"mutated"` |
| 789 | IsStatic bool `blueprint:"mutated"` |
| 790 | |
| 791 | Static struct { |
| 792 | Srcs []string `android:"arch_variant"` |
| 793 | Cflags []string `android:"arch_variant"` |
| 794 | } `android:"arch_variant"` |
| 795 | Shared struct { |
| 796 | Srcs []string `android:"arch_variant"` |
| 797 | Cflags []string `android:"arch_variant"` |
| 798 | } `android:"arch_variant"` |
| 799 | } |
| 800 | } |
| 801 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 802 | func newCCLibrary(library *ccLibrary, hod common.HostOrDeviceSupported) (blueprint.Module, []interface{}) { |
| 803 | return newCCDynamic(&library.ccDynamic, library, hod, common.MultilibBoth, |
| 804 | &library.libraryProperties) |
| 805 | } |
| 806 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 807 | func NewCCLibrary() (blueprint.Module, []interface{}) { |
| 808 | module := &ccLibrary{} |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 809 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 810 | module.libraryProperties.BuildShared = true |
| 811 | module.libraryProperties.BuildStatic = true |
| 812 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 813 | return newCCLibrary(module, common.HostAndDeviceSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | func (c *ccLibrary) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 817 | if c.libraryProperties.IsShared { |
| 818 | deps := c.ccDynamic.AndroidDynamicDependencies(ctx) |
| 819 | if c.HostOrDevice().Device() { |
| 820 | deps = append(deps, "crtbegin_so", "crtend_so") |
| 821 | } |
| 822 | return deps |
| 823 | } else { |
| 824 | return c.ccBase.AndroidDynamicDependencies(ctx) |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | func (c *ccLibrary) collectDeps(ctx common.AndroidModuleContext, flags ccFlags) (ccDeps, ccFlags) { |
| 829 | if c.libraryProperties.IsStatic { |
| 830 | deps, flags := c.ccBase.collectDeps(ctx, flags) |
| 831 | wholeStaticLibNames := c.properties.Whole_static_libs |
| 832 | wholeStaticLibs, _, _ := c.collectDepsFromList(ctx, wholeStaticLibNames) |
| 833 | |
| 834 | for _, m := range wholeStaticLibs { |
| 835 | if staticLib, ok := m.(*ccLibrary); ok && staticLib.libraryProperties.IsStatic { |
| 836 | deps.objFiles = append(deps.objFiles, staticLib.allObjFiles()...) |
| 837 | } else { |
| 838 | ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m)) |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | return deps, flags |
| 843 | } else if c.libraryProperties.IsShared { |
| 844 | return c.ccDynamic.collectDeps(ctx, flags) |
| 845 | } else { |
| 846 | panic("Not shared or static") |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | func (c *ccLibrary) outputFile() string { |
| 851 | return c.out |
| 852 | } |
| 853 | |
| 854 | func (c *ccLibrary) allObjFiles() []string { |
| 855 | return c.objFiles |
| 856 | } |
| 857 | |
| 858 | func (c *ccLibrary) exportedIncludeDirs() []string { |
| 859 | return c.exportIncludeDirs |
| 860 | } |
| 861 | |
| 862 | func (c *ccLibrary) moduleTypeCflags(ctx common.AndroidModuleContext, toolchain toolchain) []string { |
| 863 | return []string{"-fPIC"} |
| 864 | } |
| 865 | |
| 866 | func (c *ccLibrary) moduleTypeLdflags(ctx common.AndroidModuleContext, toolchain toolchain) []string { |
| 867 | if c.libraryProperties.IsShared { |
| 868 | libName := ctx.ModuleName() |
| 869 | // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead |
| 870 | sharedFlag := "-Wl,-shared" |
| 871 | if c.properties.Clang || ctx.Arch().HostOrDevice.Host() { |
| 872 | sharedFlag = "-shared" |
| 873 | } |
| 874 | if ctx.Arch().HostOrDevice.Device() { |
| 875 | return []string{ |
| 876 | "-nostdlib", |
| 877 | "-Wl,--gc-sections", |
| 878 | sharedFlag, |
Colin Cross | 6072ad4 | 2015-03-16 16:22:04 -0700 | [diff] [blame] | 879 | "-Wl,-soname," + libName + sharedLibraryExtension, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 880 | } |
| 881 | } else { |
| 882 | return []string{ |
| 883 | "-Wl,--gc-sections", |
| 884 | sharedFlag, |
Colin Cross | 6072ad4 | 2015-03-16 16:22:04 -0700 | [diff] [blame] | 885 | "-Wl,-soname," + libName + sharedLibraryExtension, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | } else { |
| 889 | return nil |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | func (c *ccLibrary) compileStaticLibrary(ctx common.AndroidModuleContext, |
| 894 | flags ccFlags, deps ccDeps, objFiles []string) { |
| 895 | |
| 896 | staticFlags := flags |
| 897 | staticFlags.cFlags = append(staticFlags.cFlags, c.libraryProperties.Static.Cflags...) |
| 898 | objFilesStatic := c.customCompileObjs(ctx, staticFlags, deps, common.DeviceStaticLibrary, |
| 899 | c.libraryProperties.Static.Srcs) |
| 900 | |
| 901 | objFiles = append(objFiles, objFilesStatic...) |
| 902 | |
| 903 | var includeDirs []string |
| 904 | |
| 905 | wholeStaticLibNames := c.properties.Whole_static_libs |
| 906 | wholeStaticLibs, _, newIncludeDirs := c.collectDepsFromList(ctx, wholeStaticLibNames) |
| 907 | includeDirs = append(includeDirs, newIncludeDirs...) |
| 908 | |
| 909 | for _, m := range wholeStaticLibs { |
| 910 | if staticLib, ok := m.(*ccLibrary); ok && staticLib.libraryProperties.IsStatic { |
| 911 | objFiles = append(objFiles, staticLib.allObjFiles()...) |
| 912 | } else { |
| 913 | ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m)) |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | staticLibNames := c.properties.Static_libs |
| 918 | _, _, newIncludeDirs = c.collectDepsFromList(ctx, staticLibNames) |
| 919 | includeDirs = append(includeDirs, newIncludeDirs...) |
| 920 | |
| 921 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 922 | if obj, ok := m.(*ccObject); ok { |
| 923 | otherName := ctx.OtherModuleName(m) |
| 924 | if !strings.HasPrefix(otherName, "crtbegin") && !strings.HasPrefix(otherName, "crtend") { |
| 925 | objFiles = append(objFiles, obj.outputFile()) |
| 926 | } |
| 927 | } |
| 928 | }) |
| 929 | |
| 930 | outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+staticLibraryExtension) |
| 931 | |
| 932 | TransformObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile) |
| 933 | |
| 934 | c.objFiles = objFiles |
| 935 | c.out = outputFile |
| 936 | c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs, |
| 937 | common.ModuleSrcDir(ctx)) |
| 938 | |
| 939 | ctx.CheckbuildFile(outputFile) |
| 940 | } |
| 941 | |
| 942 | func (c *ccLibrary) compileSharedLibrary(ctx common.AndroidModuleContext, |
| 943 | flags ccFlags, deps ccDeps, objFiles []string) { |
| 944 | |
| 945 | sharedFlags := flags |
| 946 | sharedFlags.cFlags = append(sharedFlags.cFlags, c.libraryProperties.Shared.Cflags...) |
| 947 | objFilesShared := c.customCompileObjs(ctx, sharedFlags, deps, common.DeviceSharedLibrary, |
| 948 | c.libraryProperties.Shared.Srcs) |
| 949 | |
| 950 | objFiles = append(objFiles, objFilesShared...) |
| 951 | |
| 952 | outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+sharedLibraryExtension) |
| 953 | |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 954 | TransformObjToDynamicBinary(ctx, objFiles, deps.sharedLibs, deps.staticLibs, |
| 955 | deps.lateStaticLibs, deps.wholeStaticLibs, deps.crtBegin, deps.crtEnd, |
| 956 | ccFlagsToBuilderFlags(flags), outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 957 | |
| 958 | c.out = outputFile |
| 959 | c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs, |
| 960 | common.ModuleSrcDir(ctx)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | func (c *ccLibrary) compileModule(ctx common.AndroidModuleContext, |
| 964 | flags ccFlags, deps ccDeps, objFiles []string) { |
| 965 | |
| 966 | // Reuse the object files from the matching static library if it exists |
| 967 | if c.primary == c { |
| 968 | c.primaryObjFiles = objFiles |
| 969 | } else { |
| 970 | objFiles = append([]string(nil), c.primary.primaryObjFiles...) |
| 971 | } |
| 972 | |
| 973 | if c.libraryProperties.IsStatic { |
| 974 | c.compileStaticLibrary(ctx, flags, deps, objFiles) |
| 975 | } else { |
| 976 | c.compileSharedLibrary(ctx, flags, deps, objFiles) |
| 977 | } |
| 978 | } |
| 979 | |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 980 | func (c *ccLibrary) installStaticLibrary(ctx common.AndroidModuleContext, flags ccFlags) { |
| 981 | // Static libraries do not get installed. |
| 982 | } |
| 983 | |
| 984 | func (c *ccLibrary) installSharedLibrary(ctx common.AndroidModuleContext, flags ccFlags) { |
| 985 | installDir := "lib" |
| 986 | if flags.toolchain.Is64Bit() { |
| 987 | installDir = "lib64" |
| 988 | } |
| 989 | |
| 990 | ctx.InstallFile(installDir, c.out) |
| 991 | } |
| 992 | |
| 993 | func (c *ccLibrary) installModule(ctx common.AndroidModuleContext, flags ccFlags) { |
| 994 | if c.libraryProperties.IsStatic { |
| 995 | c.installStaticLibrary(ctx, flags) |
| 996 | } else { |
| 997 | c.installSharedLibrary(ctx, flags) |
| 998 | } |
| 999 | } |
| 1000 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1001 | // |
| 1002 | // Objects (for crt*.o) |
| 1003 | // |
| 1004 | |
| 1005 | type ccObject struct { |
| 1006 | ccBase |
| 1007 | out string |
| 1008 | } |
| 1009 | |
| 1010 | func NewCCObject() (blueprint.Module, []interface{}) { |
| 1011 | module := &ccObject{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1012 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1013 | return newCCBase(&module.ccBase, module, common.DeviceSupported, common.MultilibBoth) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | func (*ccObject) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1017 | // object files can't have any dynamic dependencies |
| 1018 | return nil |
| 1019 | } |
| 1020 | |
| 1021 | func (c *ccObject) collectDeps(ctx common.AndroidModuleContext, flags ccFlags) (ccDeps, ccFlags) { |
| 1022 | deps, flags := c.ccBase.collectDeps(ctx, flags) |
| 1023 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 1024 | if obj, ok := m.(*ccObject); ok { |
| 1025 | deps.objFiles = append(deps.objFiles, obj.outputFile()) |
| 1026 | } else { |
| 1027 | ctx.ModuleErrorf("Unknown module type for dependency %q", ctx.OtherModuleName(m)) |
| 1028 | } |
| 1029 | }) |
| 1030 | |
| 1031 | return deps, flags |
| 1032 | } |
| 1033 | |
| 1034 | func (c *ccObject) compileModule(ctx common.AndroidModuleContext, |
| 1035 | flags ccFlags, deps ccDeps, objFiles []string) { |
| 1036 | |
| 1037 | objFiles = append(objFiles, deps.objFiles...) |
| 1038 | |
| 1039 | var outputFile string |
| 1040 | if len(objFiles) == 1 { |
| 1041 | outputFile = objFiles[0] |
| 1042 | } else { |
| 1043 | outputFile = filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+".o") |
| 1044 | TransformObjsToObj(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile) |
| 1045 | } |
| 1046 | |
| 1047 | c.out = outputFile |
| 1048 | |
| 1049 | ctx.CheckbuildFile(outputFile) |
| 1050 | } |
| 1051 | |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1052 | func (c *ccObject) installModule(ctx common.AndroidModuleContext, flags ccFlags) { |
| 1053 | // Object files do not get installed. |
| 1054 | } |
| 1055 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1056 | func (c *ccObject) outputFile() string { |
| 1057 | return c.out |
| 1058 | } |
| 1059 | |
| 1060 | // |
| 1061 | // Executables |
| 1062 | // |
| 1063 | |
| 1064 | type ccBinary struct { |
| 1065 | ccDynamic |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1066 | out string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1067 | binaryProperties binaryProperties |
| 1068 | } |
| 1069 | |
| 1070 | type binaryProperties struct { |
| 1071 | // static_executable: compile executable with -static |
| 1072 | Static_executable bool |
| 1073 | |
| 1074 | // stem: set the name of the output |
| 1075 | Stem string `android:"arch_variant"` |
| 1076 | |
| 1077 | // prefix_symbols: if set, add an extra objcopy --prefix-symbols= step |
| 1078 | Prefix_symbols string |
| 1079 | } |
| 1080 | |
| 1081 | func (c *ccBinary) getStem(ctx common.AndroidModuleContext) string { |
| 1082 | if c.binaryProperties.Stem != "" { |
| 1083 | return c.binaryProperties.Stem |
| 1084 | } |
| 1085 | return ctx.ModuleName() |
| 1086 | } |
| 1087 | |
| 1088 | func (c *ccBinary) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1089 | deps := c.ccDynamic.AndroidDynamicDependencies(ctx) |
| 1090 | if c.HostOrDevice().Device() { |
| 1091 | if c.binaryProperties.Static_executable { |
| 1092 | deps = append(deps, "crtbegin_static", "crtend_android") |
| 1093 | } else { |
| 1094 | deps = append(deps, "crtbegin_dynamic", "crtend_android") |
| 1095 | } |
| 1096 | } |
| 1097 | return deps |
| 1098 | } |
| 1099 | |
| 1100 | func NewCCBinary() (blueprint.Module, []interface{}) { |
| 1101 | module := &ccBinary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1102 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1103 | return newCCDynamic(&module.ccDynamic, module, common.HostAndDeviceSupported, common.MultilibFirst, |
| 1104 | &module.binaryProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | func (c *ccBinary) moduleTypeCflags(ctx common.AndroidModuleContext, toolchain toolchain) []string { |
| 1108 | return []string{"-fpie"} |
| 1109 | } |
| 1110 | |
| 1111 | func (c *ccBinary) moduleTypeLdflags(ctx common.AndroidModuleContext, toolchain toolchain) []string { |
| 1112 | if ctx.Arch().HostOrDevice.Device() { |
| 1113 | linker := "/system/bin/linker" |
| 1114 | if toolchain.Is64Bit() { |
| 1115 | linker = "/system/bin/linker64" |
| 1116 | } |
| 1117 | |
| 1118 | return []string{ |
| 1119 | "-nostdlib", |
| 1120 | "-Bdynamic", |
| 1121 | fmt.Sprintf("-Wl,-dynamic-linker,%s", linker), |
| 1122 | "-Wl,--gc-sections", |
| 1123 | "-Wl,-z,nocopyreloc", |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | return nil |
| 1128 | } |
| 1129 | |
| 1130 | func (c *ccBinary) compileModule(ctx common.AndroidModuleContext, |
| 1131 | flags ccFlags, deps ccDeps, objFiles []string) { |
| 1132 | |
| 1133 | if !c.binaryProperties.Static_executable && inList("libc", c.properties.Static_libs) { |
| 1134 | ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" + |
| 1135 | "from static libs or set static_executable: true") |
| 1136 | } |
| 1137 | |
| 1138 | outputFile := filepath.Join(common.ModuleOutDir(ctx), c.getStem(ctx)) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1139 | c.out = outputFile |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1140 | |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 1141 | TransformObjToDynamicBinary(ctx, objFiles, deps.sharedLibs, deps.staticLibs, |
| 1142 | deps.lateStaticLibs, deps.wholeStaticLibs, deps.crtBegin, deps.crtEnd, |
| 1143 | ccFlagsToBuilderFlags(flags), outputFile) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1144 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1145 | |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1146 | func (c *ccBinary) installModule(ctx common.AndroidModuleContext, flags ccFlags) { |
| 1147 | ctx.InstallFile("bin", c.out) |
| 1148 | } |
| 1149 | |
| 1150 | type ccTest struct { |
| 1151 | ccBinary |
| 1152 | } |
| 1153 | |
| 1154 | var ( |
| 1155 | gtestLibs = []string{"libgtest", "libgtest_main"} |
| 1156 | ) |
| 1157 | |
| 1158 | func (c *ccTest) collectDeps(ctx common.AndroidModuleContext, flags ccFlags) (ccDeps, ccFlags) { |
| 1159 | deps, flags := c.ccBinary.collectDeps(ctx, flags) |
| 1160 | |
| 1161 | flags.cFlags = append(flags.cFlags, "-DGTEST_HAS_STD_STRING") |
| 1162 | if c.HostOrDevice().Host() { |
| 1163 | flags.cFlags = append(flags.cFlags, "-O0", "-g") |
| 1164 | flags.ldLibs = append(flags.ldLibs, "-lpthread") |
| 1165 | } |
| 1166 | |
| 1167 | // TODO(danalbert): Make gtest export its dependencies. |
Tim Kilbourn | 5ccc730 | 2015-03-19 10:02:21 -0700 | [diff] [blame] | 1168 | flags.includeDirs = append(flags.includeDirs, |
| 1169 | filepath.Join(ctx.Config().(Config).SrcDir(), "external/gtest/include")) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1170 | |
| 1171 | _, staticLibs, _ := c.collectDepsFromList(ctx, gtestLibs) |
| 1172 | deps.staticLibs = append(deps.staticLibs, staticLibs...) |
| 1173 | |
| 1174 | return deps, flags |
| 1175 | } |
| 1176 | |
| 1177 | func (c *ccTest) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1178 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, gtestLibs...) |
| 1179 | deps := c.ccBinary.AndroidDynamicDependencies(ctx) |
| 1180 | return append(deps, gtestLibs...) |
| 1181 | } |
| 1182 | |
| 1183 | func (c *ccTest) installModule(ctx common.AndroidModuleContext, flags ccFlags) { |
| 1184 | if c.HostOrDevice().Device() { |
Tim Kilbourn | 5ccc730 | 2015-03-19 10:02:21 -0700 | [diff] [blame] | 1185 | ctx.InstallFile("../data/nativetest/"+ctx.ModuleName(), c.out) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1186 | } else { |
| 1187 | c.ccBinary.installModule(ctx, flags) |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | func NewCCTest() (blueprint.Module, []interface{}) { |
| 1192 | module := &ccTest{} |
| 1193 | return newCCDynamic(&module.ccDynamic, module, common.HostAndDeviceSupported, |
| 1194 | common.MultilibFirst, &module.binaryProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | // |
| 1198 | // Static library |
| 1199 | // |
| 1200 | |
| 1201 | func NewCCLibraryStatic() (blueprint.Module, []interface{}) { |
| 1202 | module := &ccLibrary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1203 | module.libraryProperties.BuildStatic = true |
| 1204 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1205 | return newCCLibrary(module, common.HostAndDeviceSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | // |
| 1209 | // Shared libraries |
| 1210 | // |
| 1211 | |
| 1212 | func NewCCLibraryShared() (blueprint.Module, []interface{}) { |
| 1213 | module := &ccLibrary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1214 | module.libraryProperties.BuildShared = true |
| 1215 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1216 | return newCCLibrary(module, common.HostAndDeviceSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | // |
| 1220 | // Host static library |
| 1221 | // |
| 1222 | |
| 1223 | func NewCCLibraryHostStatic() (blueprint.Module, []interface{}) { |
| 1224 | module := &ccLibrary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1225 | module.libraryProperties.BuildStatic = true |
| 1226 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1227 | return newCCLibrary(module, common.HostSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | // |
| 1231 | // Host Shared libraries |
| 1232 | // |
| 1233 | |
| 1234 | func NewCCLibraryHostShared() (blueprint.Module, []interface{}) { |
| 1235 | module := &ccLibrary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1236 | module.libraryProperties.BuildShared = true |
| 1237 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1238 | return newCCLibrary(module, common.HostSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | // |
| 1242 | // Host Binaries |
| 1243 | // |
| 1244 | |
| 1245 | func NewCCBinaryHost() (blueprint.Module, []interface{}) { |
| 1246 | module := &ccBinary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1247 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1248 | return newCCDynamic(&module.ccDynamic, module, common.HostSupported, common.MultilibFirst) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | // |
| 1252 | // Device libraries shipped with gcc |
| 1253 | // |
| 1254 | |
| 1255 | type toolchainLibrary struct { |
| 1256 | ccLibrary |
| 1257 | } |
| 1258 | |
| 1259 | func (*toolchainLibrary) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1260 | // toolchain libraries can't have any dependencies |
| 1261 | return nil |
| 1262 | } |
| 1263 | |
| 1264 | func (*toolchainLibrary) collectDeps(ctx common.AndroidModuleContext, flags ccFlags) (ccDeps, ccFlags) { |
| 1265 | // toolchain libraries can't have any dependencies |
| 1266 | return ccDeps{}, flags |
| 1267 | } |
| 1268 | |
| 1269 | func NewToolchainLibrary() (blueprint.Module, []interface{}) { |
| 1270 | module := &toolchainLibrary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1271 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1272 | return newCCBase(&module.ccBase, module, common.DeviceSupported, common.MultilibBoth) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | func (c *toolchainLibrary) compileModule(ctx common.AndroidModuleContext, |
| 1276 | flags ccFlags, deps ccDeps, objFiles []string) { |
| 1277 | |
| 1278 | libName := ctx.ModuleName() + staticLibraryExtension |
| 1279 | outputFile := filepath.Join(common.ModuleOutDir(ctx), libName) |
| 1280 | |
| 1281 | CopyGccLib(ctx, libName, ccFlagsToBuilderFlags(flags), outputFile) |
| 1282 | |
| 1283 | c.out = outputFile |
| 1284 | |
| 1285 | ctx.CheckbuildFile(outputFile) |
| 1286 | } |
| 1287 | |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1288 | func (c *toolchainLibrary) installModule(ctx common.AndroidModuleContext, flags ccFlags) { |
| 1289 | // Toolchain libraries do not get installed. |
| 1290 | } |
| 1291 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1292 | func LinkageMutator(mctx blueprint.EarlyMutatorContext) { |
| 1293 | if c, ok := mctx.Module().(*ccLibrary); ok { |
| 1294 | var modules []blueprint.Module |
| 1295 | if c.libraryProperties.BuildStatic && c.libraryProperties.BuildShared { |
| 1296 | modules = mctx.CreateLocalVariations("static", "shared") |
| 1297 | modules[0].(*ccLibrary).libraryProperties.IsStatic = true |
| 1298 | modules[1].(*ccLibrary).libraryProperties.IsShared = true |
| 1299 | } else if c.libraryProperties.BuildStatic { |
| 1300 | modules = mctx.CreateLocalVariations("static") |
| 1301 | modules[0].(*ccLibrary).libraryProperties.IsStatic = true |
| 1302 | } else if c.libraryProperties.BuildShared { |
| 1303 | modules = mctx.CreateLocalVariations("shared") |
| 1304 | modules[0].(*ccLibrary).libraryProperties.IsShared = true |
| 1305 | } else { |
| 1306 | panic("ccLibrary not static or shared") |
| 1307 | } |
| 1308 | primary := modules[0].(*ccLibrary) |
| 1309 | for _, m := range modules { |
| 1310 | m.(*ccLibrary).primary = primary |
| 1311 | if m != primary { |
| 1312 | m.(*ccLibrary).properties.SkipCompileObjs = true |
| 1313 | } |
| 1314 | } |
| 1315 | } else if _, ok := mctx.Module().(*toolchainLibrary); ok { |
| 1316 | mctx.CreateLocalVariations("static") |
| 1317 | } |
| 1318 | } |