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