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