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