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