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