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