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