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