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