Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package cc |
| 16 | |
| 17 | // This file contains the module types for compiling C/C++ for Android, and converts the properties |
| 18 | // into the flags and filenames necessary to pass to the compiler. The final creation of the rules |
| 19 | // is handled in builder.go |
| 20 | |
| 21 | import ( |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | "fmt" |
| 23 | "path/filepath" |
| 24 | "strings" |
| 25 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint" |
| 27 | "github.com/google/blueprint/pathtools" |
| 28 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 29 | "android/soong/common" |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 30 | "android/soong/genrule" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | type Config interface { |
| 34 | SrcDir() string |
| 35 | PrebuiltOS() string |
| 36 | } |
| 37 | |
| 38 | var ( |
| 39 | HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", Config.PrebuiltOS) |
| 40 | SrcDir = pctx.VariableConfigMethod("SrcDir", Config.SrcDir) |
| 41 | |
| 42 | LibcRoot = pctx.StaticVariable("LibcRoot", "${SrcDir}/bionic/libc") |
| 43 | LibmRoot = pctx.StaticVariable("LibmRoot", "${SrcDir}/bionic/libm") |
| 44 | ) |
| 45 | |
| 46 | // Flags used by lots of devices. Putting them in package static variables will save bytes in |
| 47 | // build.ninja so they aren't repeated for every file |
| 48 | var ( |
| 49 | commonGlobalCflags = []string{ |
| 50 | "-DANDROID", |
| 51 | "-fmessage-length=0", |
| 52 | "-W", |
| 53 | "-Wall", |
| 54 | "-Wno-unused", |
| 55 | "-Winit-self", |
| 56 | "-Wpointer-arith", |
| 57 | |
| 58 | // COMMON_RELEASE_CFLAGS |
| 59 | "-DNDEBUG", |
| 60 | "-UDEBUG", |
| 61 | } |
| 62 | |
| 63 | deviceGlobalCflags = []string{ |
| 64 | // TARGET_ERROR_FLAGS |
| 65 | "-Werror=return-type", |
| 66 | "-Werror=non-virtual-dtor", |
| 67 | "-Werror=address", |
| 68 | "-Werror=sequence-point", |
| 69 | } |
| 70 | |
| 71 | hostGlobalCflags = []string{} |
| 72 | |
| 73 | commonGlobalCppflags = []string{ |
| 74 | "-Wsign-promo", |
| 75 | "-std=gnu++11", |
| 76 | } |
| 77 | ) |
| 78 | |
| 79 | func init() { |
| 80 | pctx.StaticVariable("commonGlobalCflags", strings.Join(commonGlobalCflags, " ")) |
| 81 | pctx.StaticVariable("deviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) |
| 82 | pctx.StaticVariable("hostGlobalCflags", strings.Join(hostGlobalCflags, " ")) |
| 83 | |
| 84 | pctx.StaticVariable("commonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) |
| 85 | |
| 86 | pctx.StaticVariable("commonClangGlobalCflags", |
| 87 | strings.Join(clangFilterUnknownCflags(commonGlobalCflags), " ")) |
| 88 | pctx.StaticVariable("deviceClangGlobalCflags", |
| 89 | strings.Join(clangFilterUnknownCflags(deviceGlobalCflags), " ")) |
| 90 | pctx.StaticVariable("hostClangGlobalCflags", |
| 91 | strings.Join(clangFilterUnknownCflags(hostGlobalCflags), " ")) |
Tim Kilbourn | f294814 | 2015-03-11 12:03:03 -0700 | [diff] [blame] | 92 | pctx.StaticVariable("commonClangGlobalCppflags", |
| 93 | strings.Join(clangFilterUnknownCflags(commonGlobalCppflags), " ")) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 94 | |
| 95 | // Everything in this list is a crime against abstraction and dependency tracking. |
| 96 | // Do not add anything to this list. |
| 97 | pctx.StaticVariable("commonGlobalIncludes", strings.Join([]string{ |
| 98 | "-isystem ${SrcDir}/system/core/include", |
| 99 | "-isystem ${SrcDir}/hardware/libhardware/include", |
| 100 | "-isystem ${SrcDir}/hardware/libhardware_legacy/include", |
| 101 | "-isystem ${SrcDir}/hardware/ril/include", |
| 102 | "-isystem ${SrcDir}/libnativehelper/include", |
| 103 | "-isystem ${SrcDir}/frameworks/native/include", |
| 104 | "-isystem ${SrcDir}/frameworks/native/opengl/include", |
| 105 | "-isystem ${SrcDir}/frameworks/av/include", |
| 106 | "-isystem ${SrcDir}/frameworks/base/include", |
| 107 | }, " ")) |
| 108 | |
| 109 | pctx.StaticVariable("clangPath", "${SrcDir}/prebuilts/clang/${HostPrebuiltTag}/host/3.6/bin/") |
| 110 | } |
| 111 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 112 | // ccProperties describes properties used to compile all C or C++ modules |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 113 | type ccProperties struct { |
| 114 | // srcs: list of source files used to compile the C/C++ module. May be .c, .cpp, or .S files. |
| 115 | Srcs []string `android:"arch_variant,arch_subtract"` |
| 116 | |
| 117 | // cflags: list of module-specific flags that will be used for C and C++ compiles. |
| 118 | Cflags []string `android:"arch_variant"` |
| 119 | |
| 120 | // cppflags: list of module-specific flags that will be used for C++ compiles |
| 121 | Cppflags []string `android:"arch_variant"` |
| 122 | |
| 123 | // conlyflags: list of module-specific flags that will be used for C compiles |
| 124 | Conlyflags []string `android:"arch_variant"` |
| 125 | |
| 126 | // asflags: list of module-specific flags that will be used for .S compiles |
| 127 | Asflags []string `android:"arch_variant"` |
| 128 | |
| 129 | // ldflags: list of module-specific flags that will be used for all link steps |
| 130 | Ldflags []string `android:"arch_variant"` |
| 131 | |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 132 | // instruction_set: the instruction set architecture to use to compile the C/C++ |
| 133 | // module. |
| 134 | Instruction_set string `android:"arch_variant"` |
| 135 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 136 | // include_dirs: list of directories relative to the root of the source tree that will |
| 137 | // be added to the include path using -I. |
| 138 | // If possible, don't use this. If adding paths from the current directory use |
| 139 | // local_include_dirs, if adding paths from other modules use export_include_dirs in |
| 140 | // that module. |
| 141 | Include_dirs []string `android:"arch_variant"` |
| 142 | |
| 143 | // local_include_dirs: list of directories relative to the Blueprints file that will |
| 144 | // be added to the include path using -I |
| 145 | Local_include_dirs []string `android:"arch_variant"` |
| 146 | |
| 147 | // export_include_dirs: list of directories relative to the Blueprints file that will |
| 148 | // be added to the include path using -I for any module that links against this module |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 149 | Export_include_dirs []string `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 150 | |
| 151 | // clang_cflags: list of module-specific flags that will be used for C and C++ compiles when |
| 152 | // compiling with clang |
| 153 | Clang_cflags []string `android:"arch_variant"` |
| 154 | |
| 155 | // clang_asflags: list of module-specific flags that will be used for .S compiles when |
| 156 | // compiling with clang |
| 157 | Clang_asflags []string `android:"arch_variant"` |
| 158 | |
| 159 | // system_shared_libs: list of system libraries that will be dynamically linked to |
| 160 | // shared library and executable modules. If unset, generally defaults to libc |
| 161 | // and libm. Set to [] to prevent linking against libc and libm. |
| 162 | System_shared_libs []string |
| 163 | |
| 164 | // whole_static_libs: list of modules whose object files should be linked into this module |
| 165 | // in their entirety. For static library modules, all of the .o files from the intermediate |
| 166 | // directory of the dependency will be linked into this modules .a file. For a shared library, |
| 167 | // the dependency's .a file will be linked into this module using -Wl,--whole-archive. |
| 168 | Whole_static_libs []string `android:"arch_variant"` |
| 169 | |
| 170 | // static_libs: list of modules that should be statically linked into this module. |
| 171 | Static_libs []string `android:"arch_variant"` |
| 172 | |
| 173 | // shared_libs: list of modules that should be dynamically linked into this module. |
| 174 | Shared_libs []string `android:"arch_variant"` |
| 175 | |
| 176 | // allow_undefined_symbols: allow the module to contain undefined symbols. By default, |
| 177 | // modules cannot contain undefined symbols that are not satisified by their immediate |
| 178 | // dependencies. Set this flag to true to remove --no-undefined from the linker flags. |
| 179 | // This flag should only be necessary for compiling low-level libraries like libc. |
| 180 | Allow_undefined_symbols bool |
| 181 | |
| 182 | // nocrt: don't link in crt_begin and crt_end. This flag should only be necessary for |
| 183 | // compiling crt or libc. |
| 184 | Nocrt bool `android:"arch_variant"` |
| 185 | |
| 186 | // no_default_compiler_flags: don't insert default compiler flags into asflags, cflags, |
| 187 | // cppflags, conlyflags, ldflags, or include_dirs |
| 188 | No_default_compiler_flags bool |
| 189 | |
| 190 | // clang: compile module with clang instead of gcc |
| 191 | Clang bool `android:"arch_variant"` |
| 192 | |
| 193 | // rtti: pass -frtti instead of -fno-rtti |
| 194 | Rtti bool |
| 195 | |
| 196 | // host_ldlibs: -l arguments to pass to linker for host-provided shared libraries |
| 197 | Host_ldlibs []string `android:"arch_variant"` |
| 198 | |
| 199 | // stl: select the STL library to use. Possible values are "libc++", "libc++_static", |
| 200 | // "stlport", "stlport_static", "ndk", "libstdc++", or "none". Leave blank to select the |
| 201 | // default |
| 202 | Stl string |
| 203 | |
| 204 | // Set for combined shared/static libraries to prevent compiling object files a second time |
| 205 | SkipCompileObjs bool `blueprint:"mutated"` |
Colin Cross | af19a29 | 2015-03-18 12:07:10 -0700 | [diff] [blame] | 206 | |
| 207 | Debug struct { |
| 208 | Cflags []string `android:"arch_variant"` |
| 209 | } `android:"arch_variant"` |
| 210 | Release struct { |
| 211 | Cflags []string `android:"arch_variant"` |
| 212 | } `android:"arch_variant"` |
Colin Cross | efd8e48 | 2015-03-18 17:17:35 -0700 | [diff] [blame] | 213 | |
| 214 | // Minimum sdk version supported when compiling against the ndk |
| 215 | Sdk_version string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | type unusedProperties struct { |
| 219 | Asan bool |
| 220 | Native_coverage bool |
| 221 | Strip string |
| 222 | Tags []string |
| 223 | Required []string |
| 224 | } |
| 225 | |
| 226 | // Building C/C++ code is handled by objects that satisfy this interface via composition |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 227 | type CCModuleType interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 228 | common.AndroidModule |
| 229 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 230 | // Modify the ccFlags |
| 231 | Flags(common.AndroidModuleContext, CCFlags) CCFlags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 232 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 233 | // Return list of dependency names for use in AndroidDynamicDependencies and in depsToPaths |
| 234 | DepNames(common.AndroidBaseContext, CCDeps) CCDeps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 235 | |
| 236 | // Compile objects into final module |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 237 | compileModule(common.AndroidModuleContext, CCFlags, CCDeps, []string) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 238 | |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 239 | // Install the built module. |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 240 | installModule(common.AndroidModuleContext, CCFlags) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 241 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 242 | // Return the output file (.o, .a or .so) for use by other modules |
| 243 | outputFile() string |
| 244 | } |
| 245 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 246 | type CCDeps struct { |
| 247 | StaticLibs, SharedLibs, LateStaticLibs, WholeStaticLibs, ObjFiles, IncludeDirs []string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 248 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 249 | WholeStaticLibObjFiles []string |
| 250 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 251 | CrtBegin, CrtEnd string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 254 | type CCFlags struct { |
| 255 | GlobalFlags []string |
| 256 | AsFlags []string |
| 257 | CFlags []string |
| 258 | ConlyFlags []string |
| 259 | CppFlags []string |
| 260 | LdFlags []string |
| 261 | LdLibs []string |
| 262 | IncludeDirs []string |
| 263 | Nocrt bool |
| 264 | Toolchain Toolchain |
| 265 | Clang bool |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | // ccBase contains the properties and members used by all C/C++ module types, and implements |
| 269 | // the blueprint.Module interface. It expects to be embedded into an outer specialization struct, |
| 270 | // and uses a ccModuleType interface to that struct to create the build steps. |
| 271 | type ccBase struct { |
| 272 | common.AndroidModuleBase |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 273 | module CCModuleType |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 274 | |
| 275 | properties ccProperties |
| 276 | unused unusedProperties |
| 277 | |
| 278 | installPath string |
| 279 | } |
| 280 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 281 | func newCCBase(base *ccBase, module CCModuleType, hod common.HostOrDeviceSupported, |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 282 | multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) { |
| 283 | |
| 284 | base.module = module |
| 285 | |
| 286 | props = append(props, &base.properties, &base.unused) |
| 287 | |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 288 | return common.InitAndroidArchModule(module, hod, multilib, props...) |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 291 | func (c *ccBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 292 | toolchain := c.findToolchain(ctx) |
| 293 | if ctx.Failed() { |
| 294 | return |
| 295 | } |
| 296 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 297 | flags := c.collectFlags(ctx, toolchain) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 298 | if ctx.Failed() { |
| 299 | return |
| 300 | } |
| 301 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 302 | depNames := c.module.DepNames(ctx, CCDeps{}) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 303 | if ctx.Failed() { |
| 304 | return |
| 305 | } |
| 306 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 307 | deps := c.depsToPaths(ctx, depNames) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 308 | if ctx.Failed() { |
| 309 | return |
| 310 | } |
| 311 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 312 | flags.IncludeDirs = append(flags.IncludeDirs, deps.IncludeDirs...) |
Colin Cross | ed9f868 | 2015-03-18 17:17:35 -0700 | [diff] [blame] | 313 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 314 | objFiles := c.compileObjs(ctx, flags, deps) |
| 315 | if ctx.Failed() { |
| 316 | return |
| 317 | } |
| 318 | |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 319 | generatedObjFiles := c.compileGeneratedObjs(ctx, flags, deps) |
| 320 | if ctx.Failed() { |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | objFiles = append(objFiles, generatedObjFiles...) |
| 325 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 326 | c.ccModuleType().compileModule(ctx, flags, deps, objFiles) |
| 327 | if ctx.Failed() { |
| 328 | return |
| 329 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 330 | |
| 331 | c.ccModuleType().installModule(ctx, flags) |
| 332 | if ctx.Failed() { |
| 333 | return |
| 334 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 337 | func (c *ccBase) ccModuleType() CCModuleType { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 338 | return c.module |
| 339 | } |
| 340 | |
| 341 | var _ common.AndroidDynamicDepender = (*ccBase)(nil) |
| 342 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 343 | func (c *ccBase) findToolchain(ctx common.AndroidModuleContext) Toolchain { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 344 | arch := ctx.Arch() |
| 345 | factory := toolchainFactories[arch.HostOrDevice][arch.ArchType] |
| 346 | if factory == nil { |
| 347 | panic(fmt.Sprintf("Toolchain not found for %s arch %q", |
| 348 | arch.HostOrDevice.String(), arch.String())) |
| 349 | } |
| 350 | return factory(arch.ArchVariant, arch.CpuVariant) |
| 351 | } |
| 352 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 353 | func (c *ccBase) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
| 354 | depNames.WholeStaticLibs = append(depNames.WholeStaticLibs, c.properties.Whole_static_libs...) |
| 355 | depNames.StaticLibs = append(depNames.StaticLibs, c.properties.Static_libs...) |
| 356 | depNames.SharedLibs = append(depNames.SharedLibs, c.properties.Shared_libs...) |
| 357 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 358 | return depNames |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | func (c *ccBase) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 362 | depNames := CCDeps{} |
| 363 | depNames = c.module.DepNames(ctx, depNames) |
| 364 | staticLibs := depNames.WholeStaticLibs |
| 365 | staticLibs = append(staticLibs, depNames.StaticLibs...) |
| 366 | staticLibs = append(staticLibs, depNames.LateStaticLibs...) |
| 367 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, staticLibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 368 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 369 | ctx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depNames.SharedLibs...) |
| 370 | |
| 371 | ret := append([]string(nil), depNames.ObjFiles...) |
| 372 | if depNames.CrtBegin != "" { |
| 373 | ret = append(ret, depNames.CrtBegin) |
| 374 | } |
| 375 | if depNames.CrtEnd != "" { |
| 376 | ret = append(ret, depNames.CrtEnd) |
| 377 | } |
| 378 | |
| 379 | return ret |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Create a ccFlags struct that collects the compile flags from global values, |
| 383 | // per-target values, module type values, and per-module Blueprints properties |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 384 | func (c *ccBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolchain) CCFlags { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 385 | flags := CCFlags{ |
| 386 | CFlags: c.properties.Cflags, |
| 387 | CppFlags: c.properties.Cppflags, |
| 388 | ConlyFlags: c.properties.Conlyflags, |
| 389 | LdFlags: c.properties.Ldflags, |
| 390 | AsFlags: c.properties.Asflags, |
| 391 | Nocrt: c.properties.Nocrt, |
| 392 | Toolchain: toolchain, |
| 393 | Clang: c.properties.Clang, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 394 | } |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 395 | instructionSet := c.properties.Instruction_set |
| 396 | instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet) |
| 397 | if err != nil { |
| 398 | ctx.ModuleErrorf("%s", err) |
| 399 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 400 | |
Colin Cross | af19a29 | 2015-03-18 12:07:10 -0700 | [diff] [blame] | 401 | // TODO: debug |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 402 | flags.CFlags = append(flags.CFlags, c.properties.Release.Cflags...) |
Colin Cross | af19a29 | 2015-03-18 12:07:10 -0700 | [diff] [blame] | 403 | |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame^] | 404 | if ctx.Host() && !ctx.ContainsProperty("clang") { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 405 | flags.Clang = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 408 | if flags.Clang { |
| 409 | flags.CFlags = clangFilterUnknownCflags(flags.CFlags) |
| 410 | flags.CFlags = append(flags.CFlags, c.properties.Clang_cflags...) |
| 411 | flags.AsFlags = append(flags.AsFlags, c.properties.Clang_asflags...) |
| 412 | flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags) |
| 413 | flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags) |
| 414 | flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 415 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 416 | flags.CFlags = append(flags.CFlags, "${clangExtraCflags}") |
| 417 | flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}") |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 418 | if ctx.Device() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 419 | flags.CFlags = append(flags.CFlags, "${clangExtraTargetCflags}") |
Colin Cross | bdd7b1c | 2015-03-16 16:21:20 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 422 | target := "-target " + toolchain.ClangTriple() |
| 423 | gccPrefix := "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin") |
| 424 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 425 | flags.CFlags = append(flags.CFlags, target, gccPrefix) |
| 426 | flags.AsFlags = append(flags.AsFlags, target, gccPrefix) |
| 427 | flags.LdFlags = append(flags.LdFlags, target, gccPrefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 428 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 429 | if ctx.Host() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 430 | gccToolchain := "--gcc-toolchain=" + toolchain.GccRoot() |
| 431 | sysroot := "--sysroot=" + filepath.Join(toolchain.GccRoot(), "sysroot") |
| 432 | |
| 433 | // TODO: also need more -B, -L flags to make host builds hermetic |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 434 | flags.CFlags = append(flags.CFlags, gccToolchain, sysroot) |
| 435 | flags.AsFlags = append(flags.AsFlags, gccToolchain, sysroot) |
| 436 | flags.LdFlags = append(flags.LdFlags, gccToolchain, sysroot) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 440 | flags.IncludeDirs = pathtools.PrefixPaths(c.properties.Include_dirs, ctx.Config().(Config).SrcDir()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 441 | localIncludeDirs := pathtools.PrefixPaths(c.properties.Local_include_dirs, common.ModuleSrcDir(ctx)) |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 442 | flags.IncludeDirs = append(flags.IncludeDirs, localIncludeDirs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 443 | |
| 444 | if !c.properties.No_default_compiler_flags { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 445 | flags.IncludeDirs = append(flags.IncludeDirs, []string{ |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 446 | common.ModuleSrcDir(ctx), |
| 447 | common.ModuleOutDir(ctx), |
| 448 | common.ModuleGenDir(ctx), |
| 449 | }...) |
| 450 | |
Colin Cross | efd8e48 | 2015-03-18 17:17:35 -0700 | [diff] [blame] | 451 | if c.properties.Sdk_version == "" { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 452 | flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/libnativehelper/include/nativehelper") |
Colin Cross | efd8e48 | 2015-03-18 17:17:35 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 455 | if ctx.Device() && !c.properties.Allow_undefined_symbols { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 456 | flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 459 | if flags.Clang { |
| 460 | flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}") |
| 461 | flags.GlobalFlags = []string{ |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 462 | "${commonGlobalIncludes}", |
| 463 | toolchain.IncludeFlags(), |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 464 | instructionSetFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 465 | toolchain.ClangCflags(), |
| 466 | "${commonClangGlobalCflags}", |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 467 | fmt.Sprintf("${%sClangGlobalCflags}", ctx.Arch().HostOrDevice), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 468 | } |
| 469 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 470 | flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}") |
| 471 | flags.GlobalFlags = []string{ |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 472 | "${commonGlobalIncludes}", |
| 473 | toolchain.IncludeFlags(), |
Tim Kilbourn | 1a9bf26 | 2015-03-18 12:28:32 -0700 | [diff] [blame] | 474 | instructionSetFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 475 | toolchain.Cflags(), |
| 476 | "${commonGlobalCflags}", |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 477 | fmt.Sprintf("${%sGlobalCflags}", ctx.Arch().HostOrDevice), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 481 | if ctx.Host() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 482 | flags.LdFlags = append(flags.LdFlags, c.properties.Host_ldlibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 483 | } |
| 484 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 485 | if ctx.Device() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 486 | if c.properties.Rtti { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 487 | flags.CppFlags = append(flags.CppFlags, "-frtti") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 488 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 489 | flags.CppFlags = append(flags.CppFlags, "-fno-rtti") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 493 | flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 494 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 495 | if flags.Clang { |
| 496 | flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags()) |
| 497 | flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 498 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 499 | flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags()) |
| 500 | flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 504 | flags = c.ccModuleType().Flags(ctx, flags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 505 | |
| 506 | // Optimization to reduce size of build.ninja |
| 507 | // Replace the long list of flags for each file with a module-local variable |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 508 | ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " ")) |
| 509 | ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " ")) |
| 510 | ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " ")) |
| 511 | flags.CFlags = []string{"$cflags"} |
| 512 | flags.CppFlags = []string{"$cppflags"} |
| 513 | flags.AsFlags = []string{"$asflags"} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 514 | |
| 515 | return flags |
| 516 | } |
| 517 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 518 | func (c *ccBase) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 519 | return flags |
| 520 | } |
| 521 | |
| 522 | // Compile a list of source files into objects a specified subdirectory |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 523 | func (c *ccBase) customCompileObjs(ctx common.AndroidModuleContext, flags CCFlags, |
| 524 | deps CCDeps, subdir string, srcFiles []string) []string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 525 | |
| 526 | srcFiles = pathtools.PrefixPaths(srcFiles, common.ModuleSrcDir(ctx)) |
| 527 | srcFiles = common.ExpandGlobs(ctx, srcFiles) |
| 528 | |
| 529 | return TransformSourceToObj(ctx, subdir, srcFiles, ccFlagsToBuilderFlags(flags)) |
| 530 | } |
| 531 | |
| 532 | // Compile files listed in c.properties.Srcs into objects |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 533 | func (c *ccBase) compileObjs(ctx common.AndroidModuleContext, flags CCFlags, |
| 534 | deps CCDeps) []string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 535 | |
| 536 | if c.properties.SkipCompileObjs { |
| 537 | return nil |
| 538 | } |
| 539 | |
| 540 | return c.customCompileObjs(ctx, flags, deps, "", c.properties.Srcs) |
| 541 | } |
| 542 | |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 543 | // Compile generated source files from dependencies |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 544 | func (c *ccBase) compileGeneratedObjs(ctx common.AndroidModuleContext, flags CCFlags, |
| 545 | deps CCDeps) []string { |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 546 | var srcs []string |
| 547 | |
| 548 | if c.properties.SkipCompileObjs { |
| 549 | return nil |
| 550 | } |
| 551 | |
| 552 | ctx.VisitDirectDeps(func(module blueprint.Module) { |
| 553 | if gen, ok := module.(genrule.SourceFileGenerator); ok { |
| 554 | srcs = append(srcs, gen.GeneratedSourceFiles()...) |
| 555 | } |
| 556 | }) |
| 557 | |
| 558 | if len(srcs) == 0 { |
| 559 | return nil |
| 560 | } |
| 561 | |
| 562 | return TransformSourceToObj(ctx, "", srcs, ccFlagsToBuilderFlags(flags)) |
| 563 | } |
| 564 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 565 | func (c *ccBase) outputFile() string { |
| 566 | return "" |
| 567 | } |
| 568 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 569 | func (c *ccBase) depsToPathsFromList(ctx common.AndroidModuleContext, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 570 | names []string) (modules []common.AndroidModule, |
| 571 | outputFiles []string, exportedIncludeDirs []string) { |
| 572 | |
| 573 | for _, n := range names { |
| 574 | found := false |
| 575 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 576 | otherName := ctx.OtherModuleName(m) |
| 577 | if otherName != n { |
| 578 | return |
| 579 | } |
| 580 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 581 | if a, ok := m.(CCModuleType); ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 582 | if a.Disabled() { |
| 583 | // If a cc_library host+device module depends on a library that exists as both |
| 584 | // cc_library_shared and cc_library_host_shared, it will end up with two |
| 585 | // dependencies with the same name, one of which is marked disabled for each |
| 586 | // of host and device. Ignore the disabled one. |
| 587 | return |
| 588 | } |
| 589 | if a.HostOrDevice() != ctx.Arch().HostOrDevice { |
| 590 | ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), |
| 591 | otherName) |
| 592 | return |
| 593 | } |
| 594 | |
| 595 | if outputFile := a.outputFile(); outputFile != "" { |
| 596 | if found { |
| 597 | ctx.ModuleErrorf("multiple modules satisified dependency on %q", otherName) |
| 598 | return |
| 599 | } |
| 600 | outputFiles = append(outputFiles, outputFile) |
| 601 | modules = append(modules, a) |
| 602 | if i, ok := a.(ccExportedIncludeDirsProducer); ok { |
| 603 | exportedIncludeDirs = append(exportedIncludeDirs, i.exportedIncludeDirs()...) |
| 604 | } |
| 605 | found = true |
| 606 | } else { |
| 607 | ctx.ModuleErrorf("module %q missing output file", otherName) |
| 608 | return |
| 609 | } |
| 610 | } else { |
| 611 | ctx.ModuleErrorf("module %q not an android module", otherName) |
| 612 | return |
| 613 | } |
| 614 | }) |
| 615 | if !found { |
| 616 | ctx.ModuleErrorf("unsatisified dependency on %q", n) |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | return modules, outputFiles, exportedIncludeDirs |
| 621 | } |
| 622 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 623 | // Convert depenedency names to paths. Takes a CCDeps containing names and returns a CCDeps |
| 624 | // containing paths |
| 625 | func (c *ccBase) depsToPaths(ctx common.AndroidModuleContext, depNames CCDeps) CCDeps { |
| 626 | var depPaths CCDeps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 627 | var newIncludeDirs []string |
| 628 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 629 | var wholeStaticLibModules []common.AndroidModule |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 630 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 631 | wholeStaticLibModules, depPaths.WholeStaticLibs, newIncludeDirs = |
| 632 | c.depsToPathsFromList(ctx, depNames.WholeStaticLibs) |
| 633 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 634 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 635 | for _, m := range wholeStaticLibModules { |
| 636 | if staticLib, ok := m.(ccLibraryInterface); ok && staticLib.static() { |
| 637 | depPaths.WholeStaticLibObjFiles = |
| 638 | append(depPaths.WholeStaticLibObjFiles, staticLib.allObjFiles()...) |
| 639 | } else { |
| 640 | ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m)) |
| 641 | } |
| 642 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 643 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 644 | _, depPaths.StaticLibs, newIncludeDirs = c.depsToPathsFromList(ctx, depNames.StaticLibs) |
| 645 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...) |
| 646 | |
| 647 | _, depPaths.LateStaticLibs, newIncludeDirs = c.depsToPathsFromList(ctx, depNames.LateStaticLibs) |
| 648 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...) |
| 649 | |
| 650 | _, depPaths.SharedLibs, newIncludeDirs = c.depsToPathsFromList(ctx, depNames.SharedLibs) |
| 651 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, newIncludeDirs...) |
| 652 | |
| 653 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 654 | if obj, ok := m.(*ccObject); ok { |
| 655 | otherName := ctx.OtherModuleName(m) |
| 656 | if otherName == depNames.CrtBegin { |
| 657 | if !c.properties.Nocrt { |
| 658 | depPaths.CrtBegin = obj.outputFile() |
| 659 | } |
| 660 | } else if otherName == depNames.CrtEnd { |
| 661 | if !c.properties.Nocrt { |
| 662 | depPaths.CrtEnd = obj.outputFile() |
| 663 | } |
| 664 | } else { |
| 665 | depPaths.ObjFiles = append(depPaths.ObjFiles, obj.outputFile()) |
| 666 | } |
| 667 | } |
| 668 | }) |
| 669 | |
| 670 | return depPaths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 673 | // ccLinked contains the properties and members used by libraries and executables |
| 674 | type ccLinked struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 675 | ccBase |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 676 | |
| 677 | dynamicProperties struct { |
| 678 | VariantIsShared bool `blueprint:"mutated"` |
| 679 | VariantIsStatic bool `blueprint:"mutated"` |
| 680 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 681 | } |
| 682 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 683 | func newCCDynamic(dynamic *ccLinked, module CCModuleType, hod common.HostOrDeviceSupported, |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 684 | multilib common.Multilib, props ...interface{}) (blueprint.Module, []interface{}) { |
| 685 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 686 | props = append(props, &dynamic.dynamicProperties) |
| 687 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 688 | return newCCBase(&dynamic.ccBase, module, hod, multilib, props...) |
| 689 | } |
| 690 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 691 | func (c *ccLinked) systemSharedLibs(ctx common.AndroidBaseContext) []string { |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame^] | 692 | if ctx.ContainsProperty("system_shared_libs") { |
| 693 | return c.properties.System_shared_libs |
| 694 | } else { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 695 | if ctx.Host() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 696 | return []string{} |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 697 | } else if c.properties.Sdk_version != "" { |
| 698 | version := c.properties.Sdk_version |
| 699 | libs := []string{ |
| 700 | "ndk_libc." + version, |
| 701 | "ndk_libm." + version, |
| 702 | } |
| 703 | |
| 704 | if c.properties.Sdk_version != "" && c.stl(ctx) == "ndk_system" { |
| 705 | libs = append([]string{"libstdc++"}, libs...) |
| 706 | } |
| 707 | return libs |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 708 | } else { |
| 709 | return []string{"libc", "libm"} |
| 710 | } |
| 711 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 714 | func (c *ccLinked) stl(ctx common.AndroidBaseContext) string { |
| 715 | if c.properties.Sdk_version != "" { |
| 716 | switch c.properties.Stl { |
| 717 | case "": |
| 718 | return "ndk_system" |
| 719 | case "c++_shared", "c++_static", |
| 720 | "stlport_shared", "stlport_static", |
| 721 | "gnustl_static": |
| 722 | return "ndk_lib" + c.properties.Stl |
| 723 | default: |
| 724 | ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", c.properties.Stl) |
| 725 | return "" |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | switch c.properties.Stl { |
| 730 | case "libc++", "libc++_static", |
| 731 | "stlport", "stlport_static", |
| 732 | "libstdc++": |
| 733 | return c.properties.Stl |
| 734 | case "none": |
| 735 | return "" |
| 736 | case "": |
| 737 | if c.shared() { |
| 738 | return "libc++" // TODO: mingw needs libstdc++ |
| 739 | } else { |
| 740 | return "libc++_static" |
| 741 | } |
| 742 | default: |
| 743 | ctx.ModuleErrorf("stl: %q is not a supported STL", c.properties.Stl) |
| 744 | return "" |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | func (c *ccLinked) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags { |
| 749 | stl := c.stl(ctx) |
| 750 | if ctx.Failed() { |
| 751 | return flags |
| 752 | } |
| 753 | |
| 754 | switch stl { |
| 755 | case "libc++", "libc++_static": |
| 756 | flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX") |
| 757 | flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/external/libcxx/include") |
| 758 | if ctx.Host() { |
| 759 | flags.CppFlags = append(flags.CppFlags, "-nostdinc++") |
| 760 | flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs") |
| 761 | flags.LdLibs = append(flags.LdLibs, "-lc", "-lm", "-lpthread") |
| 762 | } |
| 763 | case "stlport", "stlport_static": |
| 764 | if ctx.Device() { |
| 765 | flags.IncludeDirs = append(flags.IncludeDirs, |
| 766 | "${SrcDir}/external/stlport/stlport", |
| 767 | "${SrcDir}/bionic/libstdc++/include", |
| 768 | "${SrcDir}/bionic") |
| 769 | } |
| 770 | case "libstdc++": |
| 771 | // Using bionic's basic libstdc++. Not actually an STL. Only around until the |
| 772 | // tree is in good enough shape to not need it. |
| 773 | // Host builds will use GNU libstdc++. |
| 774 | if ctx.Device() { |
| 775 | flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/bionic/libstdc++/include") |
| 776 | } |
| 777 | case "ndk_system": |
| 778 | ndkSrcRoot := ctx.Config().(Config).SrcDir() + "/prebuilts/ndk/current/sources/" |
| 779 | flags.IncludeDirs = append(flags.IncludeDirs, ndkSrcRoot+"cxx-stl/system/include") |
| 780 | case "ndk_libc++_shared", "ndk_libc++_static": |
| 781 | // TODO(danalbert): This really shouldn't be here... |
| 782 | flags.CppFlags = append(flags.CppFlags, "-std=c++11") |
| 783 | case "ndk_libstlport_shared", "ndk_libstlport_static", "ndk_libgnustl_static": |
| 784 | // Nothing |
| 785 | case "": |
| 786 | // None or error. |
| 787 | if ctx.Host() { |
| 788 | flags.CppFlags = append(flags.CppFlags, "-nostdinc++") |
| 789 | flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs") |
| 790 | flags.LdLibs = append(flags.LdLibs, "-lc", "-lm") |
| 791 | } |
| 792 | default: |
| 793 | panic(fmt.Errorf("Unknown stl in ccLinked.Flags: %q", stl)) |
| 794 | } |
| 795 | |
| 796 | return flags |
| 797 | } |
| 798 | |
| 799 | func (c *ccLinked) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 800 | depNames = c.ccBase.DepNames(ctx, depNames) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 801 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 802 | stl := c.stl(ctx) |
| 803 | if ctx.Failed() { |
| 804 | return depNames |
| 805 | } |
| 806 | |
| 807 | switch stl { |
| 808 | case "libc++": |
| 809 | depNames.SharedLibs = append(depNames.SharedLibs, stl) |
| 810 | case "libstdc++": |
| 811 | if ctx.Device() { |
| 812 | depNames.SharedLibs = append(depNames.SharedLibs, stl) |
| 813 | } |
| 814 | case "libc++_static": |
| 815 | depNames.StaticLibs = append(depNames.StaticLibs, stl) |
| 816 | case "stlport": |
| 817 | depNames.SharedLibs = append(depNames.SharedLibs, "libstdc++", "libstlport") |
| 818 | case "stlport_static": |
| 819 | depNames.StaticLibs = append(depNames.StaticLibs, "libstdc++", "libstlport_static") |
| 820 | case "": |
| 821 | // None or error. |
| 822 | case "ndk_system": |
| 823 | // TODO: Make a system STL prebuilt for the NDK. |
| 824 | // The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have |
| 825 | // its own includes. The includes are handled in ccBase.Flags(). |
| 826 | case "ndk_libc++_shared", "ndk_libstlport_shared": |
| 827 | depNames.SharedLibs = append(depNames.SharedLibs, stl) |
| 828 | case "ndk_libc++_static", "ndk_libstlport_static", "ndk_libgnustl_static": |
| 829 | depNames.StaticLibs = append(depNames.StaticLibs, stl) |
| 830 | default: |
| 831 | panic(fmt.Errorf("Unknown stl in ccLinked.DepNames: %q", stl)) |
| 832 | } |
| 833 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 834 | if ctx.Device() { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 835 | if ctx.ModuleName() != "libcompiler_rt-extras" { |
| 836 | depNames.StaticLibs = append(depNames.StaticLibs, "libcompiler_rt-extras") |
| 837 | } |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 838 | // libgcc and libatomic have to be last on the command line |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 839 | depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcov", "libatomic", "libgcc") |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 840 | |
| 841 | if c.shared() { |
| 842 | depNames.SharedLibs = append(depNames.SharedLibs, c.systemSharedLibs(ctx)...) |
| 843 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 846 | return depNames |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 847 | } |
| 848 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 849 | // ccLinkedInterface interface is used on ccLinked to deal with static or shared variants |
| 850 | type ccLinkedInterface interface { |
| 851 | // Returns true if the build options for the module have selected a static or shared build |
| 852 | buildStatic() bool |
| 853 | buildShared() bool |
| 854 | |
| 855 | // Sets whether a specific variant is static or shared |
| 856 | setStatic() |
| 857 | setShared() |
| 858 | |
| 859 | // Returns whether a specific variant is static or shared |
| 860 | static() bool |
| 861 | shared() bool |
| 862 | } |
| 863 | |
| 864 | var _ ccLinkedInterface = (*CCLibrary)(nil) |
| 865 | var _ ccLinkedInterface = (*CCBinary)(nil) |
| 866 | |
| 867 | func (c *ccLinked) static() bool { |
| 868 | return c.dynamicProperties.VariantIsStatic |
| 869 | } |
| 870 | |
| 871 | func (c *ccLinked) shared() bool { |
| 872 | return c.dynamicProperties.VariantIsShared |
| 873 | } |
| 874 | |
| 875 | func (c *ccLinked) setStatic() { |
| 876 | c.dynamicProperties.VariantIsStatic = true |
| 877 | } |
| 878 | |
| 879 | func (c *ccLinked) setShared() { |
| 880 | c.dynamicProperties.VariantIsShared = true |
| 881 | } |
| 882 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 883 | type ccExportedIncludeDirsProducer interface { |
| 884 | exportedIncludeDirs() []string |
| 885 | } |
| 886 | |
| 887 | // |
| 888 | // Combined static+shared libraries |
| 889 | // |
| 890 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 891 | type CCLibrary struct { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 892 | ccLinked |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 893 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 894 | reuseFrom ccLibraryInterface |
| 895 | reuseObjFiles []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 896 | objFiles []string |
| 897 | exportIncludeDirs []string |
| 898 | out string |
| 899 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 900 | LibraryProperties struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 901 | BuildStatic bool `blueprint:"mutated"` |
| 902 | BuildShared bool `blueprint:"mutated"` |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 903 | Static struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 904 | Srcs []string `android:"arch_variant"` |
| 905 | Cflags []string `android:"arch_variant"` |
| 906 | } `android:"arch_variant"` |
| 907 | Shared struct { |
| 908 | Srcs []string `android:"arch_variant"` |
| 909 | Cflags []string `android:"arch_variant"` |
| 910 | } `android:"arch_variant"` |
| 911 | } |
| 912 | } |
| 913 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 914 | func (c *CCLibrary) buildStatic() bool { |
| 915 | return c.LibraryProperties.BuildStatic |
| 916 | } |
| 917 | |
| 918 | func (c *CCLibrary) buildShared() bool { |
| 919 | return c.LibraryProperties.BuildShared |
| 920 | } |
| 921 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 922 | type ccLibraryInterface interface { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 923 | ccLinkedInterface |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 924 | ccLibrary() *CCLibrary |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 925 | setReuseFrom(ccLibraryInterface) |
| 926 | getReuseFrom() ccLibraryInterface |
| 927 | getReuseObjFiles() []string |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 928 | allObjFiles() []string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 931 | var _ ccLibraryInterface = (*CCLibrary)(nil) |
| 932 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 933 | func (c *CCLibrary) ccLibrary() *CCLibrary { |
| 934 | return c |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 935 | } |
| 936 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 937 | func NewCCLibrary(library *CCLibrary, module CCModuleType, |
| 938 | hod common.HostOrDeviceSupported) (blueprint.Module, []interface{}) { |
| 939 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 940 | return newCCDynamic(&library.ccLinked, module, hod, common.MultilibBoth, |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 941 | &library.LibraryProperties) |
| 942 | } |
| 943 | |
| 944 | func CCLibraryFactory() (blueprint.Module, []interface{}) { |
| 945 | module := &CCLibrary{} |
| 946 | |
| 947 | module.LibraryProperties.BuildShared = true |
| 948 | module.LibraryProperties.BuildStatic = true |
| 949 | |
| 950 | return NewCCLibrary(module, module, common.HostAndDeviceSupported) |
| 951 | } |
| 952 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 953 | func (c *CCLibrary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 954 | depNames = c.ccLinked.DepNames(ctx, depNames) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 955 | if c.shared() { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 956 | if ctx.Device() { |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 957 | depNames.CrtBegin = "crtbegin_so" |
| 958 | depNames.CrtEnd = "crtend_so" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 959 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 960 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 961 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 962 | return depNames |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 965 | func (c *CCLibrary) outputFile() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 966 | return c.out |
| 967 | } |
| 968 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 969 | func (c *CCLibrary) getReuseObjFiles() []string { |
| 970 | return c.reuseObjFiles |
| 971 | } |
| 972 | |
| 973 | func (c *CCLibrary) setReuseFrom(reuseFrom ccLibraryInterface) { |
| 974 | c.reuseFrom = reuseFrom |
| 975 | } |
| 976 | |
| 977 | func (c *CCLibrary) getReuseFrom() ccLibraryInterface { |
| 978 | return c.reuseFrom |
| 979 | } |
| 980 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 981 | func (c *CCLibrary) allObjFiles() []string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 982 | return c.objFiles |
| 983 | } |
| 984 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 985 | func (c *CCLibrary) exportedIncludeDirs() []string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 986 | return c.exportIncludeDirs |
| 987 | } |
| 988 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 989 | func (c *CCLibrary) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 990 | flags = c.ccLinked.Flags(ctx, flags) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 991 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 992 | flags.CFlags = append(flags.CFlags, "-fPIC") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 993 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 994 | if c.shared() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 995 | libName := ctx.ModuleName() |
| 996 | // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead |
| 997 | sharedFlag := "-Wl,-shared" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 998 | if c.properties.Clang || ctx.Host() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 999 | sharedFlag = "-shared" |
| 1000 | } |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1001 | if ctx.Device() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1002 | flags.LdFlags = append(flags.LdFlags, "-nostdlib") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1003 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1004 | |
| 1005 | flags.LdFlags = append(flags.LdFlags, |
| 1006 | "-Wl,--gc-sections", |
| 1007 | sharedFlag, |
| 1008 | "-Wl,-soname,"+libName+sharedLibraryExtension, |
| 1009 | ) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1010 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1011 | |
| 1012 | return flags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1015 | func (c *CCLibrary) compileStaticLibrary(ctx common.AndroidModuleContext, |
| 1016 | flags CCFlags, deps CCDeps, objFiles []string) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1017 | |
| 1018 | staticFlags := flags |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1019 | staticFlags.CFlags = append(staticFlags.CFlags, c.LibraryProperties.Static.Cflags...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1020 | objFilesStatic := c.customCompileObjs(ctx, staticFlags, deps, common.DeviceStaticLibrary, |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1021 | c.LibraryProperties.Static.Srcs) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1022 | |
| 1023 | objFiles = append(objFiles, objFilesStatic...) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1024 | objFiles = append(objFiles, deps.WholeStaticLibObjFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1025 | |
| 1026 | outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+staticLibraryExtension) |
| 1027 | |
| 1028 | TransformObjToStaticLib(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile) |
| 1029 | |
| 1030 | c.objFiles = objFiles |
| 1031 | c.out = outputFile |
| 1032 | c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs, |
| 1033 | common.ModuleSrcDir(ctx)) |
| 1034 | |
| 1035 | ctx.CheckbuildFile(outputFile) |
| 1036 | } |
| 1037 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1038 | func (c *CCLibrary) compileSharedLibrary(ctx common.AndroidModuleContext, |
| 1039 | flags CCFlags, deps CCDeps, objFiles []string) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1040 | |
| 1041 | sharedFlags := flags |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1042 | sharedFlags.CFlags = append(sharedFlags.CFlags, c.LibraryProperties.Shared.Cflags...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1043 | objFilesShared := c.customCompileObjs(ctx, sharedFlags, deps, common.DeviceSharedLibrary, |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1044 | c.LibraryProperties.Shared.Srcs) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1045 | |
| 1046 | objFiles = append(objFiles, objFilesShared...) |
| 1047 | |
| 1048 | outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+sharedLibraryExtension) |
| 1049 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1050 | TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs, |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1051 | deps.LateStaticLibs, deps.WholeStaticLibs, deps.CrtBegin, deps.CrtEnd, false, |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 1052 | ccFlagsToBuilderFlags(flags), outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1053 | |
| 1054 | c.out = outputFile |
| 1055 | c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs, |
| 1056 | common.ModuleSrcDir(ctx)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1057 | } |
| 1058 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1059 | func (c *CCLibrary) compileModule(ctx common.AndroidModuleContext, |
| 1060 | flags CCFlags, deps CCDeps, objFiles []string) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1061 | |
| 1062 | // Reuse the object files from the matching static library if it exists |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1063 | if c.getReuseFrom().ccLibrary() == c { |
| 1064 | c.reuseObjFiles = objFiles |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1065 | } else { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1066 | objFiles = append([]string(nil), c.getReuseFrom().getReuseObjFiles()...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1069 | if c.static() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1070 | c.compileStaticLibrary(ctx, flags, deps, objFiles) |
| 1071 | } else { |
| 1072 | c.compileSharedLibrary(ctx, flags, deps, objFiles) |
| 1073 | } |
| 1074 | } |
| 1075 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1076 | func (c *CCLibrary) installStaticLibrary(ctx common.AndroidModuleContext, flags CCFlags) { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1077 | // Static libraries do not get installed. |
| 1078 | } |
| 1079 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1080 | func (c *CCLibrary) installSharedLibrary(ctx common.AndroidModuleContext, flags CCFlags) { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1081 | installDir := "lib" |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1082 | if flags.Toolchain.Is64Bit() { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1083 | installDir = "lib64" |
| 1084 | } |
| 1085 | |
| 1086 | ctx.InstallFile(installDir, c.out) |
| 1087 | } |
| 1088 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1089 | func (c *CCLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1090 | if c.static() { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1091 | c.installStaticLibrary(ctx, flags) |
| 1092 | } else { |
| 1093 | c.installSharedLibrary(ctx, flags) |
| 1094 | } |
| 1095 | } |
| 1096 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1097 | // |
| 1098 | // Objects (for crt*.o) |
| 1099 | // |
| 1100 | |
| 1101 | type ccObject struct { |
| 1102 | ccBase |
| 1103 | out string |
| 1104 | } |
| 1105 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1106 | func CCObjectFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1107 | module := &ccObject{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1108 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1109 | return newCCBase(&module.ccBase, module, common.DeviceSupported, common.MultilibBoth) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | func (*ccObject) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1113 | // object files can't have any dynamic dependencies |
| 1114 | return nil |
| 1115 | } |
| 1116 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1117 | func (*ccObject) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
| 1118 | // object files can't have any dynamic dependencies |
| 1119 | return CCDeps{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | func (c *ccObject) compileModule(ctx common.AndroidModuleContext, |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1123 | flags CCFlags, deps CCDeps, objFiles []string) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1124 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1125 | objFiles = append(objFiles, deps.ObjFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1126 | |
| 1127 | var outputFile string |
| 1128 | if len(objFiles) == 1 { |
| 1129 | outputFile = objFiles[0] |
| 1130 | } else { |
| 1131 | outputFile = filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+".o") |
| 1132 | TransformObjsToObj(ctx, objFiles, ccFlagsToBuilderFlags(flags), outputFile) |
| 1133 | } |
| 1134 | |
| 1135 | c.out = outputFile |
| 1136 | |
| 1137 | ctx.CheckbuildFile(outputFile) |
| 1138 | } |
| 1139 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1140 | func (c *ccObject) installModule(ctx common.AndroidModuleContext, flags CCFlags) { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1141 | // Object files do not get installed. |
| 1142 | } |
| 1143 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1144 | func (c *ccObject) outputFile() string { |
| 1145 | return c.out |
| 1146 | } |
| 1147 | |
| 1148 | // |
| 1149 | // Executables |
| 1150 | // |
| 1151 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1152 | type CCBinary struct { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1153 | ccLinked |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1154 | out string |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1155 | BinaryProperties struct { |
| 1156 | // static_executable: compile executable with -static |
| 1157 | Static_executable bool |
| 1158 | |
| 1159 | // stem: set the name of the output |
| 1160 | Stem string `android:"arch_variant"` |
| 1161 | |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1162 | // suffix: append to the name of the output |
| 1163 | Suffix string `android:"arch_variant"` |
| 1164 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1165 | // prefix_symbols: if set, add an extra objcopy --prefix-symbols= step |
| 1166 | Prefix_symbols string |
| 1167 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1170 | func (c *CCBinary) buildStatic() bool { |
| 1171 | return c.BinaryProperties.Static_executable |
| 1172 | } |
| 1173 | |
| 1174 | func (c *CCBinary) buildShared() bool { |
| 1175 | return !c.BinaryProperties.Static_executable |
| 1176 | } |
| 1177 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1178 | func (c *CCBinary) getStem(ctx common.AndroidModuleContext) string { |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1179 | stem := ctx.ModuleName() |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1180 | if c.BinaryProperties.Stem != "" { |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1181 | stem = c.BinaryProperties.Stem |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1182 | } |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1183 | |
| 1184 | return stem + c.BinaryProperties.Suffix |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1185 | } |
| 1186 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1187 | func (c *CCBinary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1188 | depNames = c.ccLinked.DepNames(ctx, depNames) |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1189 | if ctx.Device() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1190 | if c.BinaryProperties.Static_executable { |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1191 | depNames.CrtBegin = "crtbegin_static" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1192 | } else { |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1193 | depNames.CrtBegin = "crtbegin_dynamic" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1194 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1195 | depNames.CrtEnd = "crtend_android" |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1196 | |
| 1197 | if c.BinaryProperties.Static_executable { |
| 1198 | // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with |
| 1199 | // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs, |
| 1200 | // move them to the beginning of deps.LateStaticLibs |
| 1201 | var groupLibs []string |
| 1202 | depNames.StaticLibs, groupLibs = filterList(depNames.StaticLibs, |
| 1203 | []string{"libc", "libc_nomalloc", "libcompiler_rt"}) |
| 1204 | depNames.LateStaticLibs = append(groupLibs, depNames.LateStaticLibs...) |
| 1205 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1206 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1207 | return depNames |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1210 | func NewCCBinary(binary *CCBinary, module CCModuleType, |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 1211 | hod common.HostOrDeviceSupported, props ...interface{}) (blueprint.Module, []interface{}) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1212 | |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 1213 | props = append(props, &binary.BinaryProperties) |
| 1214 | |
| 1215 | return newCCDynamic(&binary.ccLinked, module, hod, common.MultilibFirst, props...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1216 | } |
| 1217 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1218 | func CCBinaryFactory() (blueprint.Module, []interface{}) { |
| 1219 | module := &CCBinary{} |
| 1220 | |
| 1221 | return NewCCBinary(module, module, common.HostAndDeviceSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1224 | func (c *CCBinary) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1225 | flags = c.ccLinked.Flags(ctx, flags) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1226 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1227 | flags.CFlags = append(flags.CFlags, "-fpie") |
| 1228 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1229 | if ctx.Device() { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1230 | if c.BinaryProperties.Static_executable { |
| 1231 | // Clang driver needs -static to create static executable. |
| 1232 | // However, bionic/linker uses -shared to overwrite. |
| 1233 | // Linker for x86 targets does not allow coexistance of -static and -shared, |
| 1234 | // so we add -static only if -shared is not used. |
| 1235 | if !inList("-shared", flags.LdFlags) { |
| 1236 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 1237 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1238 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1239 | flags.LdFlags = append(flags.LdFlags, |
| 1240 | "-nostdlib", |
| 1241 | "-Bstatic", |
| 1242 | "-Wl,--gc-sections", |
| 1243 | ) |
| 1244 | |
| 1245 | } else { |
| 1246 | linker := "/system/bin/linker" |
| 1247 | if flags.Toolchain.Is64Bit() { |
| 1248 | linker = "/system/bin/linker64" |
| 1249 | } |
| 1250 | |
| 1251 | flags.LdFlags = append(flags.LdFlags, |
| 1252 | "-nostdlib", |
| 1253 | "-Bdynamic", |
| 1254 | fmt.Sprintf("-Wl,-dynamic-linker,%s", linker), |
| 1255 | "-Wl,--gc-sections", |
| 1256 | "-Wl,-z,nocopyreloc", |
| 1257 | ) |
| 1258 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1259 | } |
| 1260 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1261 | return flags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1264 | func (c *CCBinary) compileModule(ctx common.AndroidModuleContext, |
| 1265 | flags CCFlags, deps CCDeps, objFiles []string) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1266 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1267 | if !c.BinaryProperties.Static_executable && inList("libc", c.properties.Static_libs) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1268 | ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" + |
| 1269 | "from static libs or set static_executable: true") |
| 1270 | } |
| 1271 | |
| 1272 | outputFile := filepath.Join(common.ModuleOutDir(ctx), c.getStem(ctx)) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1273 | c.out = outputFile |
Colin Cross | bfae885 | 2015-03-26 14:44:11 -0700 | [diff] [blame] | 1274 | if c.BinaryProperties.Prefix_symbols != "" { |
| 1275 | afterPrefixSymbols := outputFile |
| 1276 | outputFile = outputFile + ".intermediate" |
| 1277 | TransformBinaryPrefixSymbols(ctx, c.BinaryProperties.Prefix_symbols, outputFile, |
| 1278 | ccFlagsToBuilderFlags(flags), afterPrefixSymbols) |
| 1279 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1280 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1281 | TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs, |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1282 | deps.LateStaticLibs, deps.WholeStaticLibs, deps.CrtBegin, deps.CrtEnd, true, |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 1283 | ccFlagsToBuilderFlags(flags), outputFile) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1284 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1285 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1286 | func (c *CCBinary) installModule(ctx common.AndroidModuleContext, flags CCFlags) { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1287 | ctx.InstallFile("bin", c.out) |
| 1288 | } |
| 1289 | |
| 1290 | type ccTest struct { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1291 | CCBinary |
Colin Cross | 6b29069 | 2015-03-19 14:05:33 -0700 | [diff] [blame] | 1292 | |
| 1293 | testProperties struct { |
| 1294 | // test_per_src: Create a separate test for each source file. Useful when there is |
| 1295 | // global state that can not be torn down and reset between each test suite. |
| 1296 | Test_per_src bool |
| 1297 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1300 | func (c *ccTest) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags { |
| 1301 | flags = c.CCBinary.Flags(ctx, flags) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1302 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1303 | flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING") |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1304 | if ctx.Host() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1305 | flags.CFlags = append(flags.CFlags, "-O0", "-g") |
| 1306 | flags.LdLibs = append(flags.LdLibs, "-lpthread") |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | // TODO(danalbert): Make gtest export its dependencies. |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1310 | flags.IncludeDirs = append(flags.IncludeDirs, |
Tim Kilbourn | 5ccc730 | 2015-03-19 10:02:21 -0700 | [diff] [blame] | 1311 | filepath.Join(ctx.Config().(Config).SrcDir(), "external/gtest/include")) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1312 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1313 | return flags |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1316 | func (c *ccTest) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
| 1317 | depNames = c.CCBinary.DepNames(ctx, depNames) |
| 1318 | depNames.StaticLibs = append(depNames.StaticLibs, "libgtest", "libgtest_main") |
| 1319 | return depNames |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1322 | func (c *ccTest) installModule(ctx common.AndroidModuleContext, flags CCFlags) { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1323 | if ctx.Device() { |
Tim Kilbourn | 5ccc730 | 2015-03-19 10:02:21 -0700 | [diff] [blame] | 1324 | ctx.InstallFile("../data/nativetest/"+ctx.ModuleName(), c.out) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1325 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1326 | c.CCBinary.installModule(ctx, flags) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1330 | func CCTestFactory() (blueprint.Module, []interface{}) { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1331 | module := &ccTest{} |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 1332 | return NewCCBinary(&module.CCBinary, module, common.HostAndDeviceSupported, |
| 1333 | &module.testProperties) |
Colin Cross | 6b29069 | 2015-03-19 14:05:33 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | func TestPerSrcMutator(mctx blueprint.EarlyMutatorContext) { |
| 1337 | if test, ok := mctx.Module().(*ccTest); ok { |
| 1338 | if test.testProperties.Test_per_src { |
| 1339 | testNames := make([]string, len(test.properties.Srcs)) |
| 1340 | for i, src := range test.properties.Srcs { |
| 1341 | testNames[i] = strings.TrimSuffix(src, filepath.Ext(src)) |
| 1342 | } |
| 1343 | tests := mctx.CreateLocalVariations(testNames...) |
| 1344 | for i, src := range test.properties.Srcs { |
| 1345 | tests[i].(*ccTest).properties.Srcs = []string{src} |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1346 | tests[i].(*ccTest).BinaryProperties.Stem = testNames[i] |
Colin Cross | 6b29069 | 2015-03-19 14:05:33 -0700 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | // |
| 1353 | // Static library |
| 1354 | // |
| 1355 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1356 | func CCLibraryStaticFactory() (blueprint.Module, []interface{}) { |
| 1357 | module := &CCLibrary{} |
| 1358 | module.LibraryProperties.BuildStatic = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1359 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1360 | return NewCCLibrary(module, module, common.HostAndDeviceSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | // |
| 1364 | // Shared libraries |
| 1365 | // |
| 1366 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1367 | func CCLibrarySharedFactory() (blueprint.Module, []interface{}) { |
| 1368 | module := &CCLibrary{} |
| 1369 | module.LibraryProperties.BuildShared = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1370 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1371 | return NewCCLibrary(module, module, common.HostAndDeviceSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // |
| 1375 | // Host static library |
| 1376 | // |
| 1377 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1378 | func CCLibraryHostStaticFactory() (blueprint.Module, []interface{}) { |
| 1379 | module := &CCLibrary{} |
| 1380 | module.LibraryProperties.BuildStatic = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1381 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1382 | return NewCCLibrary(module, module, common.HostSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | // |
| 1386 | // Host Shared libraries |
| 1387 | // |
| 1388 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1389 | func CCLibraryHostSharedFactory() (blueprint.Module, []interface{}) { |
| 1390 | module := &CCLibrary{} |
| 1391 | module.LibraryProperties.BuildShared = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1392 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1393 | return NewCCLibrary(module, module, common.HostSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | // |
| 1397 | // Host Binaries |
| 1398 | // |
| 1399 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1400 | func CCBinaryHostFactory() (blueprint.Module, []interface{}) { |
| 1401 | module := &CCBinary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1402 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1403 | return NewCCBinary(module, module, common.HostSupported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | // |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 1407 | // Host Tests |
| 1408 | // |
| 1409 | |
| 1410 | func CCTestHostFactory() (blueprint.Module, []interface{}) { |
| 1411 | module := &ccTest{} |
| 1412 | return NewCCBinary(&module.CCBinary, module, common.HostSupported, |
| 1413 | &module.testProperties) |
| 1414 | } |
| 1415 | |
| 1416 | // |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1417 | // Device libraries shipped with gcc |
| 1418 | // |
| 1419 | |
| 1420 | type toolchainLibrary struct { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1421 | CCLibrary |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | func (*toolchainLibrary) AndroidDynamicDependencies(ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1425 | // toolchain libraries can't have any dependencies |
| 1426 | return nil |
| 1427 | } |
| 1428 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1429 | func (*toolchainLibrary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1430 | // toolchain libraries can't have any dependencies |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1431 | return CCDeps{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1434 | func ToolchainLibraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1435 | module := &toolchainLibrary{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1436 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1437 | module.LibraryProperties.BuildStatic = true |
| 1438 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1439 | return newCCBase(&module.ccBase, module, common.DeviceSupported, common.MultilibBoth, |
| 1440 | &module.LibraryProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | func (c *toolchainLibrary) compileModule(ctx common.AndroidModuleContext, |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1444 | flags CCFlags, deps CCDeps, objFiles []string) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1445 | |
| 1446 | libName := ctx.ModuleName() + staticLibraryExtension |
| 1447 | outputFile := filepath.Join(common.ModuleOutDir(ctx), libName) |
| 1448 | |
| 1449 | CopyGccLib(ctx, libName, ccFlagsToBuilderFlags(flags), outputFile) |
| 1450 | |
| 1451 | c.out = outputFile |
| 1452 | |
| 1453 | ctx.CheckbuildFile(outputFile) |
| 1454 | } |
| 1455 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1456 | func (c *toolchainLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) { |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1457 | // Toolchain libraries do not get installed. |
| 1458 | } |
| 1459 | |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 1460 | // NDK prebuilt libraries. |
| 1461 | // |
| 1462 | // These differ from regular prebuilts in that they aren't stripped and usually aren't installed |
| 1463 | // either (with the exception of the shared STLs, which are installed to the app's directory rather |
| 1464 | // than to the system image). |
| 1465 | |
| 1466 | func getNdkLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, version string) string { |
| 1467 | return fmt.Sprintf("%s/prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib", |
| 1468 | ctx.Config().(Config).SrcDir(), version, toolchain.Name()) |
| 1469 | } |
| 1470 | |
| 1471 | type ndkPrebuiltLibrary struct { |
| 1472 | CCLibrary |
| 1473 | } |
| 1474 | |
| 1475 | func (*ndkPrebuiltLibrary) AndroidDynamicDependencies( |
| 1476 | ctx common.AndroidDynamicDependerModuleContext) []string { |
| 1477 | |
| 1478 | // NDK libraries can't have any dependencies |
| 1479 | return nil |
| 1480 | } |
| 1481 | |
| 1482 | func (*ndkPrebuiltLibrary) DepNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps { |
| 1483 | // NDK libraries can't have any dependencies |
| 1484 | return CCDeps{} |
| 1485 | } |
| 1486 | |
| 1487 | func NdkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) { |
| 1488 | module := &ndkPrebuiltLibrary{} |
| 1489 | module.LibraryProperties.BuildShared = true |
| 1490 | return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported) |
| 1491 | } |
| 1492 | |
| 1493 | func (c *ndkPrebuiltLibrary) compileModule(ctx common.AndroidModuleContext, flags CCFlags, |
| 1494 | deps CCDeps, objFiles []string) { |
| 1495 | // A null build step, but it sets up the output path. |
| 1496 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { |
| 1497 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") |
| 1498 | } |
| 1499 | |
| 1500 | c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs, |
| 1501 | common.ModuleSrcDir(ctx)) |
| 1502 | |
| 1503 | // NDK prebuilt libraries are named like: ndk_LIBNAME.SDK_VERSION. |
| 1504 | // We want to translate to just LIBNAME. |
| 1505 | libName := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0] |
| 1506 | libDir := getNdkLibDir(ctx, flags.Toolchain, c.properties.Sdk_version) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1507 | c.out = filepath.Join(libDir, libName+sharedLibraryExtension) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | func (c *ndkPrebuiltLibrary) installModule(ctx common.AndroidModuleContext, flags CCFlags) { |
| 1511 | // Toolchain libraries do not get installed. |
| 1512 | } |
| 1513 | |
| 1514 | // The NDK STLs are slightly different from the prebuilt system libraries: |
| 1515 | // * Are not specific to each platform version. |
| 1516 | // * The libraries are not in a predictable location for each STL. |
| 1517 | |
| 1518 | type ndkPrebuiltStl struct { |
| 1519 | ndkPrebuiltLibrary |
| 1520 | } |
| 1521 | |
| 1522 | type ndkPrebuiltStaticStl struct { |
| 1523 | ndkPrebuiltStl |
| 1524 | } |
| 1525 | |
| 1526 | type ndkPrebuiltSharedStl struct { |
| 1527 | ndkPrebuiltStl |
| 1528 | } |
| 1529 | |
| 1530 | func NdkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) { |
| 1531 | module := &ndkPrebuiltSharedStl{} |
| 1532 | module.LibraryProperties.BuildShared = true |
| 1533 | return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported) |
| 1534 | } |
| 1535 | |
| 1536 | func NdkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) { |
| 1537 | module := &ndkPrebuiltStaticStl{} |
| 1538 | module.LibraryProperties.BuildStatic = true |
| 1539 | return NewCCLibrary(&module.CCLibrary, module, common.DeviceSupported) |
| 1540 | } |
| 1541 | |
| 1542 | func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl string) string { |
| 1543 | gccVersion := toolchain.GccVersion() |
| 1544 | var libDir string |
| 1545 | switch stl { |
| 1546 | case "libstlport": |
| 1547 | libDir = "cxx-stl/stlport/libs" |
| 1548 | case "libc++": |
| 1549 | libDir = "cxx-stl/llvm-libc++/libs" |
| 1550 | case "libgnustl": |
| 1551 | libDir = fmt.Sprintf("cxx-stl/gnu-libstdc++/%s/libs", gccVersion) |
| 1552 | } |
| 1553 | |
| 1554 | if libDir != "" { |
| 1555 | ndkSrcRoot := ctx.Config().(Config).SrcDir() + "/prebuilts/ndk/current/sources" |
| 1556 | return fmt.Sprintf("%s/%s/%s", ndkSrcRoot, libDir, ctx.Arch().Abi) |
| 1557 | } |
| 1558 | |
| 1559 | ctx.ModuleErrorf("Unknown NDK STL: %s", stl) |
| 1560 | return "" |
| 1561 | } |
| 1562 | |
| 1563 | func (c *ndkPrebuiltStl) compileModule(ctx common.AndroidModuleContext, flags CCFlags, |
| 1564 | deps CCDeps, objFiles []string) { |
| 1565 | // A null build step, but it sets up the output path. |
| 1566 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { |
| 1567 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") |
| 1568 | } |
| 1569 | |
| 1570 | c.exportIncludeDirs = pathtools.PrefixPaths(c.properties.Export_include_dirs, |
| 1571 | common.ModuleSrcDir(ctx)) |
| 1572 | |
| 1573 | libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_") |
| 1574 | libExt := sharedLibraryExtension |
| 1575 | if c.LibraryProperties.BuildStatic { |
| 1576 | libExt = staticLibraryExtension |
| 1577 | } |
| 1578 | |
| 1579 | stlName := strings.TrimSuffix(libName, "_shared") |
| 1580 | stlName = strings.TrimSuffix(stlName, "_static") |
| 1581 | libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName) |
| 1582 | c.out = libDir + "/" + libName + libExt |
| 1583 | } |
| 1584 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1585 | func LinkageMutator(mctx blueprint.EarlyMutatorContext) { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1586 | if c, ok := mctx.Module().(ccLinkedInterface); ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1587 | var modules []blueprint.Module |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1588 | if c.buildStatic() && c.buildShared() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1589 | modules = mctx.CreateLocalVariations("static", "shared") |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1590 | modules[0].(ccLinkedInterface).setStatic() |
| 1591 | modules[1].(ccLinkedInterface).setShared() |
| 1592 | } else if c.buildStatic() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1593 | modules = mctx.CreateLocalVariations("static") |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1594 | modules[0].(ccLinkedInterface).setStatic() |
| 1595 | } else if c.buildShared() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1596 | modules = mctx.CreateLocalVariations("shared") |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1597 | modules[0].(ccLinkedInterface).setShared() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1598 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1599 | panic(fmt.Errorf("ccLibrary %q not static or shared", mctx.ModuleName())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1600 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1601 | |
| 1602 | if _, ok := c.(ccLibraryInterface); ok { |
| 1603 | reuseFrom := modules[0].(ccLibraryInterface) |
| 1604 | for _, m := range modules { |
| 1605 | m.(ccLibraryInterface).setReuseFrom(reuseFrom) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1606 | } |
| 1607 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1608 | } |
| 1609 | } |