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