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