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