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