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