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