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