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