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