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