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