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