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 | |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 853 | c.Properties.AndroidMkSharedLibs = append([]string(nil), deps.SharedLibs...) |
| 854 | |
| 855 | if ctx.sdk() { |
| 856 | version := "." + ctx.sdkVersion() |
| 857 | |
| 858 | rewriteNdkLibs := func(list []string) []string { |
| 859 | for i, entry := range list { |
| 860 | if inList(entry, ndkPrebuiltSharedLibraries) { |
| 861 | list[i] = "ndk_" + entry + version |
| 862 | } |
| 863 | } |
| 864 | return list |
| 865 | } |
| 866 | |
| 867 | deps.SharedLibs = rewriteNdkLibs(deps.SharedLibs) |
| 868 | deps.LateSharedLibs = rewriteNdkLibs(deps.LateSharedLibs) |
| 869 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 870 | |
| 871 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag, |
| 872 | deps.WholeStaticLibs...) |
| 873 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 874 | for _, lib := range deps.StaticLibs { |
| 875 | depTag := staticDepTag |
| 876 | if inList(lib, deps.ReexportStaticLibHeaders) { |
| 877 | depTag = staticExportDepTag |
| 878 | } |
| 879 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, |
| 880 | deps.StaticLibs...) |
| 881 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 882 | |
| 883 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag, |
| 884 | deps.LateStaticLibs...) |
| 885 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 886 | for _, lib := range deps.SharedLibs { |
| 887 | depTag := sharedDepTag |
| 888 | if inList(lib, deps.ReexportSharedLibHeaders) { |
| 889 | depTag = sharedExportDepTag |
| 890 | } |
| 891 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, |
| 892 | deps.SharedLibs...) |
| 893 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 894 | |
| 895 | actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag, |
| 896 | deps.LateSharedLibs...) |
| 897 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 898 | actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) |
| 899 | actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 900 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 901 | actx.AddDependency(c, objDepTag, deps.ObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 902 | |
| 903 | if deps.CrtBegin != "" { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 904 | actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 905 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 906 | if deps.CrtEnd != "" { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 907 | actx.AddDependency(c, crtEndDepTag, deps.CrtEnd) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 908 | } |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 909 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 910 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 911 | func depsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 912 | if c, ok := ctx.Module().(*Module); ok { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 913 | c.depsMutator(ctx) |
| 914 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 917 | func (c *Module) clang(ctx BaseModuleContext) bool { |
| 918 | clang := Bool(c.Properties.Clang) |
| 919 | |
| 920 | if c.Properties.Clang == nil { |
| 921 | if ctx.Host() { |
| 922 | clang = true |
| 923 | } |
| 924 | |
| 925 | if ctx.Device() && ctx.AConfig().DeviceUsesClang() { |
| 926 | clang = true |
| 927 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 928 | } |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 929 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 930 | if !c.toolchain(ctx).ClangSupported() { |
| 931 | clang = false |
| 932 | } |
| 933 | |
| 934 | return clang |
| 935 | } |
| 936 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 937 | // Convert dependencies to paths. Returns a PathDeps containing paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 938 | func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 939 | var depPaths PathDeps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 940 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 941 | // Whether a module can link to another module, taking into |
| 942 | // account NDK linking. |
| 943 | linkTypeOk := func(from, to *Module) bool { |
| 944 | if from.Target().Os != android.Android { |
| 945 | // Host code is not restricted |
| 946 | return true |
| 947 | } |
| 948 | if from.Properties.Sdk_version == "" { |
| 949 | // Platform code can link to anything |
| 950 | return true |
| 951 | } |
| 952 | if _, ok := to.linker.(*toolchainLibraryLinker); ok { |
| 953 | // These are always allowed |
| 954 | return true |
| 955 | } |
| 956 | if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok { |
| 957 | // These are allowed, but don't set sdk_version |
| 958 | return true |
| 959 | } |
Dan Willemsen | 3c316bc | 2016-07-07 20:41:36 -0700 | [diff] [blame] | 960 | if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok { |
| 961 | // These are allowed, but don't set sdk_version |
| 962 | return true |
| 963 | } |
| 964 | return to.Properties.Sdk_version != "" |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 967 | ctx.VisitDirectDeps(func(m blueprint.Module) { |
| 968 | name := ctx.OtherModuleName(m) |
| 969 | tag := ctx.OtherModuleDependencyTag(m) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 970 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 971 | a, _ := m.(android.Module) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 972 | if a == nil { |
| 973 | ctx.ModuleErrorf("module %q not an android module", name) |
| 974 | return |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 975 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 976 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 977 | cc, _ := m.(*Module) |
| 978 | if cc == nil { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 979 | switch tag { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 980 | case android.DefaultsDepTag: |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 981 | case genSourceDepTag: |
| 982 | if genRule, ok := m.(genrule.SourceFileGenerator); ok { |
| 983 | depPaths.GeneratedSources = append(depPaths.GeneratedSources, |
| 984 | genRule.GeneratedSourceFiles()...) |
| 985 | } else { |
| 986 | ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name) |
| 987 | } |
| 988 | case genHeaderDepTag: |
| 989 | if genRule, ok := m.(genrule.SourceFileGenerator); ok { |
| 990 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, |
| 991 | genRule.GeneratedSourceFiles()...) |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame^] | 992 | depPaths.Flags = append(depPaths.Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 993 | includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 994 | } else { |
| 995 | ctx.ModuleErrorf("module %q is not a genrule", name) |
| 996 | } |
| 997 | default: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 998 | ctx.ModuleErrorf("depends on non-cc module %q", name) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 999 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1000 | return |
| 1001 | } |
| 1002 | |
| 1003 | if !a.Enabled() { |
| 1004 | ctx.ModuleErrorf("depends on disabled module %q", name) |
| 1005 | return |
| 1006 | } |
| 1007 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1008 | if a.Target().Os != ctx.Os() { |
| 1009 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name) |
| 1010 | return |
| 1011 | } |
| 1012 | |
| 1013 | if a.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1014 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1015 | return |
| 1016 | } |
| 1017 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1018 | if !cc.outputFile.Valid() { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1019 | ctx.ModuleErrorf("module %q missing output file", name) |
| 1020 | return |
| 1021 | } |
| 1022 | |
| 1023 | if tag == reuseObjTag { |
| 1024 | depPaths.ObjFiles = append(depPaths.ObjFiles, |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1025 | cc.compiler.(*libraryCompiler).reuseObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1026 | return |
| 1027 | } |
| 1028 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1029 | if t, ok := tag.(dependencyTag); ok && t.library { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1030 | if i, ok := cc.linker.(exportedFlagsProducer); ok { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame^] | 1031 | flags := i.exportedFlags() |
| 1032 | depPaths.Flags = append(depPaths.Flags, flags...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1033 | |
| 1034 | if t.reexportFlags { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame^] | 1035 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1036 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1037 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1038 | |
| 1039 | if !linkTypeOk(c, cc) { |
| 1040 | ctx.ModuleErrorf("depends on non-NDK-built library %q", name) |
| 1041 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1044 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1045 | |
| 1046 | switch tag { |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1047 | case sharedDepTag, sharedExportDepTag: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1048 | depPtr = &depPaths.SharedLibs |
| 1049 | case lateSharedDepTag: |
| 1050 | depPtr = &depPaths.LateSharedLibs |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1051 | case staticDepTag, staticExportDepTag: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1052 | depPtr = &depPaths.StaticLibs |
| 1053 | case lateStaticDepTag: |
| 1054 | depPtr = &depPaths.LateStaticLibs |
| 1055 | case wholeStaticDepTag: |
| 1056 | depPtr = &depPaths.WholeStaticLibs |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1057 | staticLib, _ := cc.linker.(*libraryLinker) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1058 | if staticLib == nil || !staticLib.static() { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1059 | ctx.ModuleErrorf("module %q not a static library", name) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1060 | return |
| 1061 | } |
| 1062 | |
| 1063 | if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { |
| 1064 | postfix := " (required by " + ctx.OtherModuleName(m) + ")" |
| 1065 | for i := range missingDeps { |
| 1066 | missingDeps[i] += postfix |
| 1067 | } |
| 1068 | ctx.AddMissingDependencies(missingDeps) |
| 1069 | } |
| 1070 | depPaths.WholeStaticLibObjFiles = |
| 1071 | append(depPaths.WholeStaticLibObjFiles, staticLib.objFiles...) |
| 1072 | case objDepTag: |
| 1073 | depPtr = &depPaths.ObjFiles |
| 1074 | case crtBeginDepTag: |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1075 | depPaths.CrtBegin = cc.outputFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1076 | case crtEndDepTag: |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1077 | depPaths.CrtEnd = cc.outputFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1078 | default: |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1079 | panic(fmt.Errorf("unknown dependency tag: %s", tag)) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | if depPtr != nil { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1083 | *depPtr = append(*depPtr, cc.outputFile.Path()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1084 | } |
| 1085 | }) |
| 1086 | |
| 1087 | return depPaths |
| 1088 | } |
| 1089 | |
| 1090 | func (c *Module) InstallInData() bool { |
| 1091 | if c.installer == nil { |
| 1092 | return false |
| 1093 | } |
| 1094 | return c.installer.inData() |
| 1095 | } |
| 1096 | |
| 1097 | // Compiler |
| 1098 | |
| 1099 | type baseCompiler struct { |
| 1100 | Properties BaseCompilerProperties |
| 1101 | } |
| 1102 | |
| 1103 | var _ compiler = (*baseCompiler)(nil) |
| 1104 | |
| 1105 | func (compiler *baseCompiler) props() []interface{} { |
| 1106 | return []interface{}{&compiler.Properties} |
| 1107 | } |
| 1108 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1109 | func (compiler *baseCompiler) begin(ctx BaseModuleContext) {} |
| 1110 | |
| 1111 | func (compiler *baseCompiler) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1112 | deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...) |
| 1113 | deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...) |
| 1114 | |
| 1115 | return deps |
| 1116 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1117 | |
| 1118 | // Create a Flags struct that collects the compile flags from global values, |
| 1119 | // per-target values, module type values, and per-module Blueprints properties |
| 1120 | func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags { |
| 1121 | toolchain := ctx.toolchain() |
| 1122 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1123 | CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags) |
| 1124 | CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags) |
| 1125 | CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags) |
| 1126 | CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags) |
| 1127 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1128 | flags.CFlags = append(flags.CFlags, compiler.Properties.Cflags...) |
| 1129 | flags.CppFlags = append(flags.CppFlags, compiler.Properties.Cppflags...) |
| 1130 | flags.ConlyFlags = append(flags.ConlyFlags, compiler.Properties.Conlyflags...) |
| 1131 | flags.AsFlags = append(flags.AsFlags, compiler.Properties.Asflags...) |
| 1132 | flags.YaccFlags = append(flags.YaccFlags, compiler.Properties.Yaccflags...) |
| 1133 | |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1134 | // Include dir cflags |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1135 | rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs) |
| 1136 | localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs) |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1137 | flags.GlobalFlags = append(flags.GlobalFlags, |
Dan Willemsen | 1e898b9 | 2015-09-23 15:26:32 -0700 | [diff] [blame] | 1138 | includeDirsToFlags(localIncludeDirs), |
| 1139 | includeDirsToFlags(rootIncludeDirs)) |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1140 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1141 | if !ctx.noDefaultCompilerFlags() { |
| 1142 | if !ctx.sdk() || ctx.Host() { |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1143 | flags.GlobalFlags = append(flags.GlobalFlags, |
| 1144 | "${commonGlobalIncludes}", |
| 1145 | toolchain.IncludeFlags(), |
Dan Willemsen | e0378dd | 2016-01-07 17:42:34 -0800 | [diff] [blame] | 1146 | "${commonNativehelperInclude}") |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | flags.GlobalFlags = append(flags.GlobalFlags, []string{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1150 | "-I" + android.PathForModuleSrc(ctx).String(), |
| 1151 | "-I" + android.PathForModuleOut(ctx).String(), |
| 1152 | "-I" + android.PathForModuleGen(ctx).String(), |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1153 | }...) |
| 1154 | } |
| 1155 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1156 | instructionSet := compiler.Properties.Instruction_set |
| 1157 | if flags.RequiredInstructionSet != "" { |
| 1158 | instructionSet = flags.RequiredInstructionSet |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1159 | } |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 1160 | instructionSetFlags, err := toolchain.InstructionSetFlags(instructionSet) |
| 1161 | if flags.Clang { |
| 1162 | instructionSetFlags, err = toolchain.ClangInstructionSetFlags(instructionSet) |
| 1163 | } |
| 1164 | if err != nil { |
| 1165 | ctx.ModuleErrorf("%s", err) |
| 1166 | } |
| 1167 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1168 | CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) |
| 1169 | |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 1170 | // TODO: debug |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1171 | flags.CFlags = append(flags.CFlags, compiler.Properties.Release.Cflags...) |
Dan Willemsen | 6d11dd8 | 2015-11-03 14:27:00 -0800 | [diff] [blame] | 1172 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1173 | if flags.Clang { |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1174 | CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags) |
| 1175 | CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags) |
| 1176 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1177 | flags.CFlags = clangFilterUnknownCflags(flags.CFlags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1178 | flags.CFlags = append(flags.CFlags, compiler.Properties.Clang_cflags...) |
| 1179 | flags.AsFlags = append(flags.AsFlags, compiler.Properties.Clang_asflags...) |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1180 | flags.CppFlags = clangFilterUnknownCflags(flags.CppFlags) |
| 1181 | flags.ConlyFlags = clangFilterUnknownCflags(flags.ConlyFlags) |
| 1182 | flags.LdFlags = clangFilterUnknownCflags(flags.LdFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1183 | |
| 1184 | target := "-target " + toolchain.ClangTriple() |
Dan Willemsen | 3772da1 | 2016-05-16 18:01:46 -0700 | [diff] [blame] | 1185 | var gccPrefix string |
| 1186 | if !ctx.Darwin() { |
| 1187 | gccPrefix = "-B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin") |
| 1188 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1189 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1190 | flags.CFlags = append(flags.CFlags, target, gccPrefix) |
| 1191 | flags.AsFlags = append(flags.AsFlags, target, gccPrefix) |
| 1192 | flags.LdFlags = append(flags.LdFlags, target, gccPrefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1195 | hod := "host" |
| 1196 | if ctx.Os().Class == android.Device { |
| 1197 | hod = "device" |
| 1198 | } |
| 1199 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1200 | if !ctx.noDefaultCompilerFlags() { |
Colin Cross | 56b4d45 | 2015-04-21 17:38:44 -0700 | [diff] [blame] | 1201 | flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) |
| 1202 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1203 | if flags.Clang { |
Dan Willemsen | 32968a2 | 2016-01-12 22:25:34 -0800 | [diff] [blame] | 1204 | flags.AsFlags = append(flags.AsFlags, toolchain.ClangAsflags()) |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1205 | flags.CppFlags = append(flags.CppFlags, "${commonClangGlobalCppflags}") |
Colin Cross | 56b4d45 | 2015-04-21 17:38:44 -0700 | [diff] [blame] | 1206 | flags.GlobalFlags = append(flags.GlobalFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1207 | toolchain.ClangCflags(), |
| 1208 | "${commonClangGlobalCflags}", |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1209 | fmt.Sprintf("${%sClangGlobalCflags}", hod)) |
Dan Willemsen | ac5e1cb | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 1210 | |
| 1211 | flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1212 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1213 | flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}") |
Colin Cross | 56b4d45 | 2015-04-21 17:38:44 -0700 | [diff] [blame] | 1214 | flags.GlobalFlags = append(flags.GlobalFlags, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1215 | toolchain.Cflags(), |
| 1216 | "${commonGlobalCflags}", |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1217 | fmt.Sprintf("${%sGlobalCflags}", hod)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
Colin Cross | 7b66f15 | 2015-12-15 16:07:43 -0800 | [diff] [blame] | 1220 | if Bool(ctx.AConfig().ProductVariables.Brillo) { |
| 1221 | flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__") |
| 1222 | } |
| 1223 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1224 | if ctx.Device() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1225 | if Bool(compiler.Properties.Rtti) { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1226 | flags.CppFlags = append(flags.CppFlags, "-frtti") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1227 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1228 | flags.CppFlags = append(flags.CppFlags, "-fno-rtti") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1232 | flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1233 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1234 | if flags.Clang { |
| 1235 | flags.CppFlags = append(flags.CppFlags, toolchain.ClangCppflags()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1236 | } else { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1237 | flags.CppFlags = append(flags.CppFlags, toolchain.Cppflags()) |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 1238 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 1241 | if flags.Clang { |
| 1242 | flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainClangCflags()) |
| 1243 | } else { |
| 1244 | flags.GlobalFlags = append(flags.GlobalFlags, toolchain.ToolchainCflags()) |
Colin Cross | c4bde76 | 2015-11-23 16:11:30 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1247 | if !ctx.sdk() { |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 1248 | if ctx.Host() && !flags.Clang { |
| 1249 | // The host GCC doesn't support C++14 (and is deprecated, so likely |
| 1250 | // never will). Build these modules with C++11. |
| 1251 | flags.CppFlags = append(flags.CppFlags, "-std=gnu++11") |
| 1252 | } else { |
| 1253 | flags.CppFlags = append(flags.CppFlags, "-std=gnu++14") |
| 1254 | } |
| 1255 | } |
| 1256 | |
Dan Willemsen | 52b1cd2 | 2016-03-01 13:36:34 -0800 | [diff] [blame] | 1257 | // We can enforce some rules more strictly in the code we own. strict |
| 1258 | // indicates if this is code that we can be stricter with. If we have |
| 1259 | // rules that we want to apply to *our* code (but maybe can't for |
| 1260 | // vendor/device specific things), we could extend this to be a ternary |
| 1261 | // value. |
| 1262 | strict := true |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1263 | if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { |
Dan Willemsen | 52b1cd2 | 2016-03-01 13:36:34 -0800 | [diff] [blame] | 1264 | strict = false |
| 1265 | } |
| 1266 | |
| 1267 | // Can be used to make some annotations stricter for code we can fix |
| 1268 | // (such as when we mark functions as deprecated). |
| 1269 | if strict { |
| 1270 | flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT") |
| 1271 | } |
| 1272 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1273 | return flags |
| 1274 | } |
| 1275 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1276 | func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1277 | // Compile files listed in c.Properties.Srcs into objects |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1278 | objFiles := compiler.compileObjs(ctx, flags, "", |
| 1279 | compiler.Properties.Srcs, compiler.Properties.Exclude_srcs, |
| 1280 | deps.GeneratedSources, deps.GeneratedHeaders) |
| 1281 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1282 | if ctx.Failed() { |
| 1283 | return nil |
| 1284 | } |
| 1285 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1286 | return objFiles |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | // Compile a list of source files into objects a specified subdirectory |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1290 | func (compiler *baseCompiler) compileObjs(ctx android.ModuleContext, flags Flags, |
| 1291 | subdir string, srcFiles, excludes []string, extraSrcs, deps android.Paths) android.Paths { |
Colin Cross | 581c189 | 2015-04-07 16:50:10 -0700 | [diff] [blame] | 1292 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1293 | buildFlags := flagsToBuilderFlags(flags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1294 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1295 | inputFiles := ctx.ExpandSources(srcFiles, excludes) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1296 | inputFiles = append(inputFiles, extraSrcs...) |
| 1297 | srcPaths, gendeps := genSources(ctx, inputFiles, buildFlags) |
| 1298 | |
| 1299 | deps = append(deps, gendeps...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1300 | deps = append(deps, flags.CFlagsDeps...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1301 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1302 | return TransformSourceToObj(ctx, subdir, srcPaths, buildFlags, deps) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1303 | } |
| 1304 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1305 | // baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties |
| 1306 | type baseLinker struct { |
| 1307 | Properties BaseLinkerProperties |
| 1308 | dynamicProperties struct { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1309 | VariantIsShared bool `blueprint:"mutated"` |
| 1310 | VariantIsStatic bool `blueprint:"mutated"` |
| 1311 | VariantIsStaticBinary bool `blueprint:"mutated"` |
| 1312 | RunPaths []string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1313 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1316 | func (linker *baseLinker) begin(ctx BaseModuleContext) { |
| 1317 | if ctx.toolchain().Is64Bit() { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1318 | linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"} |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1319 | } else { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1320 | linker.dynamicProperties.RunPaths = []string{"../lib", "lib"} |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1321 | } |
| 1322 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1323 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1324 | func (linker *baseLinker) props() []interface{} { |
| 1325 | return []interface{}{&linker.Properties, &linker.dynamicProperties} |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1328 | func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1329 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...) |
| 1330 | deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...) |
| 1331 | deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1332 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1333 | deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...) |
| 1334 | deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...) |
| 1335 | |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1336 | if !ctx.sdk() && ctx.ModuleName() != "libcompiler_rt-extras" { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1337 | deps.StaticLibs = append(deps.StaticLibs, "libcompiler_rt-extras") |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1340 | if ctx.Device() { |
Colin Cross | 77b00fa | 2015-03-16 16:15:49 -0700 | [diff] [blame] | 1341 | // libgcc and libatomic have to be last on the command line |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1342 | deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic") |
| 1343 | if !Bool(linker.Properties.No_libgcc) { |
| 1344 | deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc") |
Dan Willemsen | d67be22 | 2015-09-16 15:19:33 -0700 | [diff] [blame] | 1345 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1346 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1347 | if !linker.static() { |
| 1348 | if linker.Properties.System_shared_libs != nil { |
| 1349 | deps.LateSharedLibs = append(deps.LateSharedLibs, |
| 1350 | linker.Properties.System_shared_libs...) |
| 1351 | } else if !ctx.sdk() { |
| 1352 | deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm") |
| 1353 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1354 | } |
Colin Cross | 577f6e4 | 2015-03-27 18:23:34 -0700 | [diff] [blame] | 1355 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1356 | if ctx.sdk() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1357 | deps.SharedLibs = append(deps.SharedLibs, |
Dan Willemsen | 97704ed | 2016-07-07 21:40:39 -0700 | [diff] [blame] | 1358 | "libc", |
| 1359 | "libm", |
Colin Cross | 577f6e4 | 2015-03-27 18:23:34 -0700 | [diff] [blame] | 1360 | ) |
| 1361 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1364 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1367 | func (linker *baseLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 1368 | toolchain := ctx.toolchain() |
| 1369 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1370 | if !ctx.noDefaultCompilerFlags() { |
| 1371 | if ctx.Device() && !Bool(linker.Properties.Allow_undefined_symbols) { |
| 1372 | flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") |
| 1373 | } |
| 1374 | |
| 1375 | if flags.Clang { |
| 1376 | flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags()) |
| 1377 | } else { |
| 1378 | flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags()) |
| 1379 | } |
| 1380 | |
| 1381 | if ctx.Host() { |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1382 | CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs) |
| 1383 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1384 | flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...) |
| 1385 | } |
| 1386 | } |
| 1387 | |
Dan Willemsen | 20acc5c | 2016-05-25 14:47:21 -0700 | [diff] [blame] | 1388 | CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags) |
| 1389 | |
Dan Willemsen | 00ced76 | 2016-05-10 17:31:21 -0700 | [diff] [blame] | 1390 | flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...) |
| 1391 | |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1392 | if ctx.Host() && !linker.static() { |
| 1393 | rpath_prefix := `\$$ORIGIN/` |
| 1394 | if ctx.Darwin() { |
| 1395 | rpath_prefix = "@loader_path/" |
| 1396 | } |
| 1397 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1398 | for _, rpath := range linker.dynamicProperties.RunPaths { |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 1399 | flags.LdFlags = append(flags.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath) |
| 1400 | } |
| 1401 | } |
| 1402 | |
Dan Willemsen | e717492 | 2016-03-30 17:33:52 -0700 | [diff] [blame] | 1403 | if flags.Clang { |
| 1404 | flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainClangLdflags()) |
| 1405 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1406 | flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainLdflags()) |
| 1407 | } |
| 1408 | |
| 1409 | return flags |
| 1410 | } |
| 1411 | |
| 1412 | func (linker *baseLinker) static() bool { |
| 1413 | return linker.dynamicProperties.VariantIsStatic |
| 1414 | } |
| 1415 | |
| 1416 | func (linker *baseLinker) staticBinary() bool { |
| 1417 | return linker.dynamicProperties.VariantIsStaticBinary |
| 1418 | } |
| 1419 | |
| 1420 | func (linker *baseLinker) setStatic(static bool) { |
| 1421 | linker.dynamicProperties.VariantIsStatic = static |
| 1422 | } |
| 1423 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1424 | func (linker *baseLinker) isDependencyRoot() bool { |
| 1425 | return false |
| 1426 | } |
| 1427 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1428 | type baseLinkerInterface interface { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1429 | // Returns true if the build options for the module have selected a static or shared build |
| 1430 | buildStatic() bool |
| 1431 | buildShared() bool |
| 1432 | |
| 1433 | // Sets whether a specific variant is static or shared |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1434 | setStatic(bool) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1435 | |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1436 | // Returns whether a specific variant is a static library or binary |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1437 | static() bool |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1438 | |
| 1439 | // Returns whether a module is a static binary |
| 1440 | staticBinary() bool |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1441 | |
| 1442 | // Returns true for dependency roots (binaries) |
| 1443 | // TODO(ccross): also handle dlopenable libraries |
| 1444 | isDependencyRoot() bool |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1447 | type baseInstaller struct { |
| 1448 | Properties InstallerProperties |
| 1449 | |
| 1450 | dir string |
| 1451 | dir64 string |
| 1452 | data bool |
| 1453 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1454 | path android.OutputPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | var _ installer = (*baseInstaller)(nil) |
| 1458 | |
| 1459 | func (installer *baseInstaller) props() []interface{} { |
| 1460 | return []interface{}{&installer.Properties} |
| 1461 | } |
| 1462 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1463 | func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1464 | subDir := installer.dir |
| 1465 | if ctx.toolchain().Is64Bit() && installer.dir64 != "" { |
| 1466 | subDir = installer.dir64 |
| 1467 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1468 | if !ctx.Host() && !ctx.Arch().Native { |
| 1469 | subDir = filepath.Join(subDir, ctx.Arch().ArchType.String()) |
| 1470 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1471 | dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1472 | installer.path = ctx.InstallFile(dir, file) |
| 1473 | } |
| 1474 | |
| 1475 | func (installer *baseInstaller) inData() bool { |
| 1476 | return installer.data |
| 1477 | } |
| 1478 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1479 | // |
| 1480 | // Combined static+shared libraries |
| 1481 | // |
| 1482 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1483 | type flagExporter struct { |
| 1484 | Properties FlagExporterProperties |
| 1485 | |
| 1486 | flags []string |
| 1487 | } |
| 1488 | |
| 1489 | func (f *flagExporter) exportIncludes(ctx ModuleContext, inc string) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1490 | includeDirs := android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs) |
| 1491 | f.flags = append(f.flags, android.JoinWithPrefix(includeDirs.Strings(), inc)) |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | func (f *flagExporter) reexportFlags(flags []string) { |
| 1495 | f.flags = append(f.flags, flags...) |
| 1496 | } |
| 1497 | |
| 1498 | func (f *flagExporter) exportedFlags() []string { |
| 1499 | return f.flags |
| 1500 | } |
| 1501 | |
| 1502 | type exportedFlagsProducer interface { |
| 1503 | exportedFlags() []string |
| 1504 | } |
| 1505 | |
| 1506 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 1507 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1508 | type libraryCompiler struct { |
| 1509 | baseCompiler |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 1510 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1511 | linker *libraryLinker |
| 1512 | Properties LibraryCompilerProperties |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1513 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1514 | // For reusing static library objects for shared library |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1515 | reuseObjFiles android.Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1518 | var _ compiler = (*libraryCompiler)(nil) |
| 1519 | |
| 1520 | func (library *libraryCompiler) props() []interface{} { |
| 1521 | props := library.baseCompiler.props() |
| 1522 | return append(props, &library.Properties) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1525 | func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags { |
| 1526 | flags = library.baseCompiler.flags(ctx, flags) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1527 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1528 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 1529 | // all code is position independent, and then those warnings get promoted to |
| 1530 | // errors. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1531 | if ctx.Os() != android.Windows { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1532 | flags.CFlags = append(flags.CFlags, "-fPIC") |
| 1533 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1534 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1535 | if library.linker.static() { |
| 1536 | flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...) |
Colin Cross | d8e780d | 2015-04-28 17:39:43 -0700 | [diff] [blame] | 1537 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1538 | flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...) |
Colin Cross | d8e780d | 2015-04-28 17:39:43 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1541 | return flags |
| 1542 | } |
| 1543 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1544 | func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths { |
| 1545 | var objFiles android.Paths |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1546 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1547 | objFiles = library.baseCompiler.compile(ctx, flags, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1548 | library.reuseObjFiles = objFiles |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1549 | |
| 1550 | if library.linker.static() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1551 | objFiles = append(objFiles, library.compileObjs(ctx, flags, android.DeviceStaticLibrary, |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1552 | library.Properties.Static.Srcs, library.Properties.Static.Exclude_srcs, |
| 1553 | nil, deps.GeneratedHeaders)...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1554 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1555 | objFiles = append(objFiles, library.compileObjs(ctx, flags, android.DeviceSharedLibrary, |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1556 | library.Properties.Shared.Srcs, library.Properties.Shared.Exclude_srcs, |
| 1557 | nil, deps.GeneratedHeaders)...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | return objFiles |
| 1561 | } |
| 1562 | |
| 1563 | type libraryLinker struct { |
| 1564 | baseLinker |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1565 | flagExporter |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1566 | stripper |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1567 | |
| 1568 | Properties LibraryLinkerProperties |
| 1569 | |
| 1570 | dynamicProperties struct { |
| 1571 | BuildStatic bool `blueprint:"mutated"` |
| 1572 | BuildShared bool `blueprint:"mutated"` |
| 1573 | } |
| 1574 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1575 | // If we're used as a whole_static_lib, our missing dependencies need |
| 1576 | // to be given |
| 1577 | wholeStaticMissingDeps []string |
| 1578 | |
| 1579 | // For whole_static_libs |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1580 | objFiles android.Paths |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | var _ linker = (*libraryLinker)(nil) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1584 | |
| 1585 | func (library *libraryLinker) props() []interface{} { |
| 1586 | props := library.baseLinker.props() |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1587 | return append(props, |
| 1588 | &library.Properties, |
| 1589 | &library.dynamicProperties, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1590 | &library.flagExporter.Properties, |
| 1591 | &library.stripper.StripProperties) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 1595 | flags = library.baseLinker.flags(ctx, flags) |
| 1596 | |
| 1597 | flags.Nocrt = Bool(library.Properties.Nocrt) |
| 1598 | |
| 1599 | if !library.static() { |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1600 | libName := ctx.ModuleName() + library.Properties.VariantName |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1601 | // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead |
| 1602 | sharedFlag := "-Wl,-shared" |
Dan Willemsen | dd0e2c3 | 2015-10-20 14:29:35 -0700 | [diff] [blame] | 1603 | if flags.Clang || ctx.Host() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1604 | sharedFlag = "-shared" |
| 1605 | } |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1606 | if ctx.Device() { |
Dan Willemsen | 99db8c3 | 2016-03-03 18:05:38 -0800 | [diff] [blame] | 1607 | flags.LdFlags = append(flags.LdFlags, |
| 1608 | "-nostdlib", |
| 1609 | "-Wl,--gc-sections", |
| 1610 | ) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1611 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1612 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1613 | if ctx.Darwin() { |
| 1614 | flags.LdFlags = append(flags.LdFlags, |
| 1615 | "-dynamiclib", |
| 1616 | "-single_module", |
| 1617 | //"-read_only_relocs suppress", |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1618 | "-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(), |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1619 | ) |
| 1620 | } else { |
| 1621 | flags.LdFlags = append(flags.LdFlags, |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1622 | sharedFlag, |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1623 | "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix(), |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1624 | ) |
| 1625 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1626 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1627 | |
| 1628 | return flags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1629 | } |
| 1630 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1631 | func (library *libraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1632 | deps = library.baseLinker.deps(ctx, deps) |
| 1633 | if library.static() { |
| 1634 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Static.Whole_static_libs...) |
| 1635 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...) |
| 1636 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...) |
| 1637 | } else { |
| 1638 | if ctx.Device() && !Bool(library.Properties.Nocrt) { |
| 1639 | if !ctx.sdk() { |
| 1640 | deps.CrtBegin = "crtbegin_so" |
| 1641 | deps.CrtEnd = "crtend_so" |
| 1642 | } else { |
| 1643 | deps.CrtBegin = "ndk_crtbegin_so." + ctx.sdkVersion() |
| 1644 | deps.CrtEnd = "ndk_crtend_so." + ctx.sdkVersion() |
| 1645 | } |
| 1646 | } |
| 1647 | deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...) |
| 1648 | deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...) |
| 1649 | deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...) |
| 1650 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1651 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1652 | return deps |
| 1653 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1654 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1655 | func (library *libraryLinker) linkStatic(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1656 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1657 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1658 | library.objFiles = append(android.Paths{}, deps.WholeStaticLibObjFiles...) |
Dan Willemsen | 025b480 | 2016-05-11 17:25:48 -0700 | [diff] [blame] | 1659 | library.objFiles = append(library.objFiles, objFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1660 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1661 | outputFile := android.PathForModuleOut(ctx, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1662 | ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1663 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1664 | if ctx.Darwin() { |
Dan Willemsen | 025b480 | 2016-05-11 17:25:48 -0700 | [diff] [blame] | 1665 | TransformDarwinObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1666 | } else { |
Dan Willemsen | 025b480 | 2016-05-11 17:25:48 -0700 | [diff] [blame] | 1667 | TransformObjToStaticLib(ctx, library.objFiles, flagsToBuilderFlags(flags), outputFile) |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1668 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1669 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1670 | library.wholeStaticMissingDeps = ctx.GetMissingDependencies() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1671 | |
| 1672 | ctx.CheckbuildFile(outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1673 | |
| 1674 | return outputFile |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1675 | } |
| 1676 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1677 | func (library *libraryLinker) linkShared(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1678 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1679 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1680 | var linkerDeps android.Paths |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 1681 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1682 | versionScript := android.OptionalPathForModuleSrc(ctx, library.Properties.Version_script) |
| 1683 | unexportedSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Unexported_symbols_list) |
| 1684 | forceNotWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_not_weak_list) |
| 1685 | forceWeakSymbols := android.OptionalPathForModuleSrc(ctx, library.Properties.Force_symbols_weak_list) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1686 | if !ctx.Darwin() { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1687 | if versionScript.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1688 | flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1689 | linkerDeps = append(linkerDeps, versionScript.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1690 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1691 | if unexportedSymbols.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1692 | ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin") |
| 1693 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1694 | if forceNotWeakSymbols.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1695 | ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin") |
| 1696 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1697 | if forceWeakSymbols.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1698 | ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin") |
| 1699 | } |
| 1700 | } else { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1701 | if versionScript.Valid() { |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1702 | ctx.PropertyErrorf("version_script", "Not supported on Darwin") |
| 1703 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1704 | if unexportedSymbols.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1705 | flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1706 | linkerDeps = append(linkerDeps, unexportedSymbols.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1707 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1708 | if forceNotWeakSymbols.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1709 | 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] | 1710 | linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1711 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1712 | if forceWeakSymbols.Valid() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1713 | flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String()) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1714 | linkerDeps = append(linkerDeps, forceWeakSymbols.Path()) |
Dan Willemsen | 93c2831 | 2015-12-04 14:59:08 -0800 | [diff] [blame] | 1715 | } |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1718 | fileName := ctx.ModuleName() + library.Properties.VariantName + flags.Toolchain.ShlibSuffix() |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1719 | outputFile := android.PathForModuleOut(ctx, fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1720 | ret := outputFile |
| 1721 | |
| 1722 | builderFlags := flagsToBuilderFlags(flags) |
| 1723 | |
| 1724 | if library.stripper.needsStrip(ctx) { |
| 1725 | strippedOutputFile := outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1726 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1727 | library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 1728 | } |
| 1729 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1730 | sharedLibs := deps.SharedLibs |
| 1731 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1732 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1733 | TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, |
| 1734 | deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1735 | linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1736 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1737 | return ret |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1738 | } |
| 1739 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1740 | func (library *libraryLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1741 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1742 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1743 | objFiles = append(objFiles, deps.ObjFiles...) |
| 1744 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1745 | var out android.Path |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1746 | if library.static() { |
| 1747 | out = library.linkStatic(ctx, flags, deps, objFiles) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1748 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1749 | out = library.linkShared(ctx, flags, deps, objFiles) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1750 | } |
| 1751 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1752 | library.exportIncludes(ctx, "-I") |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame^] | 1753 | library.reexportFlags(deps.ReexportedFlags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1754 | |
| 1755 | return out |
| 1756 | } |
| 1757 | |
| 1758 | func (library *libraryLinker) buildStatic() bool { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1759 | return library.dynamicProperties.BuildStatic && |
| 1760 | (library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | func (library *libraryLinker) buildShared() bool { |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1764 | return library.dynamicProperties.BuildShared && |
| 1765 | (library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | func (library *libraryLinker) getWholeStaticMissingDeps() []string { |
| 1769 | return library.wholeStaticMissingDeps |
| 1770 | } |
| 1771 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1772 | func (library *libraryLinker) installable() bool { |
| 1773 | return !library.static() |
| 1774 | } |
| 1775 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1776 | type libraryInstaller struct { |
| 1777 | baseInstaller |
| 1778 | |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1779 | linker *libraryLinker |
| 1780 | sanitize *sanitize |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1781 | } |
| 1782 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1783 | func (library *libraryInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1784 | if !library.linker.static() { |
| 1785 | library.baseInstaller.install(ctx, file) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1789 | func (library *libraryInstaller) inData() bool { |
| 1790 | return library.baseInstaller.inData() || library.sanitize.inData() |
| 1791 | } |
| 1792 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1793 | func NewLibrary(hod android.HostOrDeviceSupported, shared, static bool) *Module { |
| 1794 | module := newModule(hod, android.MultilibBoth) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1795 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1796 | linker := &libraryLinker{} |
| 1797 | linker.dynamicProperties.BuildShared = shared |
| 1798 | linker.dynamicProperties.BuildStatic = static |
| 1799 | module.linker = linker |
| 1800 | |
| 1801 | module.compiler = &libraryCompiler{ |
| 1802 | linker: linker, |
| 1803 | } |
| 1804 | module.installer = &libraryInstaller{ |
| 1805 | baseInstaller: baseInstaller{ |
| 1806 | dir: "lib", |
| 1807 | dir64: "lib64", |
| 1808 | }, |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 1809 | linker: linker, |
| 1810 | sanitize: module.sanitize, |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1813 | return module |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1816 | func libraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1817 | module := NewLibrary(android.HostAndDeviceSupported, true, true) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1818 | return module.Init() |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1821 | // |
| 1822 | // Objects (for crt*.o) |
| 1823 | // |
| 1824 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1825 | type objectLinker struct { |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 1826 | Properties ObjectLinkerProperties |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1829 | func objectFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1830 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1831 | module.compiler = &baseCompiler{} |
| 1832 | module.linker = &objectLinker{} |
| 1833 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1834 | } |
| 1835 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 1836 | func (object *objectLinker) props() []interface{} { |
| 1837 | return []interface{}{&object.Properties} |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1840 | func (*objectLinker) begin(ctx BaseModuleContext) {} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1841 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 1842 | func (object *objectLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1843 | deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1844 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1845 | } |
| 1846 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1847 | func (*objectLinker) flags(ctx ModuleContext, flags Flags) Flags { |
Dan Willemsen | e717492 | 2016-03-30 17:33:52 -0700 | [diff] [blame] | 1848 | if flags.Clang { |
| 1849 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags()) |
| 1850 | } else { |
| 1851 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags()) |
| 1852 | } |
| 1853 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1854 | return flags |
| 1855 | } |
| 1856 | |
| 1857 | func (object *objectLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1858 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1859 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 1860 | objFiles = append(objFiles, deps.ObjFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1861 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1862 | var outputFile android.Path |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1863 | if len(objFiles) == 1 { |
| 1864 | outputFile = objFiles[0] |
| 1865 | } else { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1866 | output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1867 | TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1868 | outputFile = output |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1869 | } |
| 1870 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1871 | ctx.CheckbuildFile(outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1872 | return outputFile |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1873 | } |
| 1874 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1875 | func (*objectLinker) installable() bool { |
| 1876 | return false |
| 1877 | } |
| 1878 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1879 | // |
| 1880 | // Executables |
| 1881 | // |
| 1882 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1883 | type binaryLinker struct { |
| 1884 | baseLinker |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1885 | stripper |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1886 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1887 | Properties BinaryLinkerProperties |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1888 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1889 | hostToolPath android.OptionalPath |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1892 | var _ linker = (*binaryLinker)(nil) |
| 1893 | |
| 1894 | func (binary *binaryLinker) props() []interface{} { |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1895 | return append(binary.baseLinker.props(), |
| 1896 | &binary.Properties, |
| 1897 | &binary.stripper.StripProperties) |
| 1898 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1899 | } |
| 1900 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1901 | func (binary *binaryLinker) buildStatic() bool { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1902 | return binary.baseLinker.staticBinary() |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1905 | func (binary *binaryLinker) buildShared() bool { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1906 | return !binary.baseLinker.staticBinary() |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1909 | func (binary *binaryLinker) getStem(ctx BaseModuleContext) string { |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1910 | stem := ctx.ModuleName() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1911 | if binary.Properties.Stem != "" { |
| 1912 | stem = binary.Properties.Stem |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1913 | } |
Colin Cross | 4ae185c | 2015-03-26 15:12:10 -0700 | [diff] [blame] | 1914 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1915 | return stem + binary.Properties.Suffix |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1918 | func (binary *binaryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 1919 | deps = binary.baseLinker.deps(ctx, deps) |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 1920 | if ctx.Device() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1921 | if !ctx.sdk() { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1922 | if binary.buildStatic() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1923 | deps.CrtBegin = "crtbegin_static" |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1924 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1925 | deps.CrtBegin = "crtbegin_dynamic" |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1926 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1927 | deps.CrtEnd = "crtend_android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1928 | } else { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1929 | if binary.buildStatic() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1930 | deps.CrtBegin = "ndk_crtbegin_static." + ctx.sdkVersion() |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1931 | } else { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1932 | deps.CrtBegin = "ndk_crtbegin_dynamic." + ctx.sdkVersion() |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 1933 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1934 | deps.CrtEnd = "ndk_crtend_android." + ctx.sdkVersion() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1935 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1936 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1937 | if binary.buildStatic() { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1938 | if inList("libc++_static", deps.StaticLibs) { |
| 1939 | deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl") |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 1940 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1941 | // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with |
| 1942 | // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs, |
| 1943 | // move them to the beginning of deps.LateStaticLibs |
| 1944 | var groupLibs []string |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1945 | deps.StaticLibs, groupLibs = filterList(deps.StaticLibs, |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1946 | []string{"libc", "libc_nomalloc", "libcompiler_rt"}) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1947 | deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...) |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 1948 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1949 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1950 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1951 | if binary.buildShared() && inList("libc", deps.StaticLibs) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1952 | ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" + |
| 1953 | "from static libs or set static_executable: true") |
| 1954 | } |
| 1955 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1956 | } |
| 1957 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1958 | func (*binaryLinker) installable() bool { |
| 1959 | return true |
| 1960 | } |
| 1961 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1962 | func (binary *binaryLinker) isDependencyRoot() bool { |
| 1963 | return true |
| 1964 | } |
| 1965 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1966 | func NewBinary(hod android.HostOrDeviceSupported) *Module { |
| 1967 | module := newModule(hod, android.MultilibFirst) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1968 | module.compiler = &baseCompiler{} |
| 1969 | module.linker = &binaryLinker{} |
| 1970 | module.installer = &baseInstaller{ |
| 1971 | dir: "bin", |
| 1972 | } |
| 1973 | return module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1974 | } |
| 1975 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1976 | func binaryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1977 | module := NewBinary(android.HostAndDeviceSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1978 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1979 | } |
| 1980 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1981 | func (binary *binaryLinker) begin(ctx BaseModuleContext) { |
| 1982 | binary.baseLinker.begin(ctx) |
| 1983 | |
| 1984 | static := Bool(binary.Properties.Static_executable) |
| 1985 | if ctx.Host() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1986 | if ctx.Os() == android.Linux { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1987 | if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) { |
| 1988 | static = true |
| 1989 | } |
| 1990 | } else { |
| 1991 | // Static executables are not supported on Darwin or Windows |
| 1992 | static = false |
| 1993 | } |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 1994 | } |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 1995 | if static { |
| 1996 | binary.dynamicProperties.VariantIsStatic = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1997 | binary.dynamicProperties.VariantIsStaticBinary = true |
Colin Cross | 18b6dc5 | 2015-04-28 13:20:37 -0700 | [diff] [blame] | 1998 | } |
| 1999 | } |
| 2000 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2001 | func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 2002 | flags = binary.baseLinker.flags(ctx, flags) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 2003 | |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2004 | if ctx.Host() && !binary.staticBinary() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2005 | flags.LdFlags = append(flags.LdFlags, "-pie") |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2006 | if ctx.Os() == android.Windows { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2007 | flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup") |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 2012 | // all code is position independent, and then those warnings get promoted to |
| 2013 | // errors. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2014 | if ctx.Os() != android.Windows { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2015 | flags.CFlags = append(flags.CFlags, "-fpie") |
| 2016 | } |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2017 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2018 | if ctx.Device() { |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2019 | if binary.buildStatic() { |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2020 | // Clang driver needs -static to create static executable. |
| 2021 | // However, bionic/linker uses -shared to overwrite. |
| 2022 | // Linker for x86 targets does not allow coexistance of -static and -shared, |
| 2023 | // so we add -static only if -shared is not used. |
| 2024 | if !inList("-shared", flags.LdFlags) { |
| 2025 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 2026 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2027 | |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2028 | flags.LdFlags = append(flags.LdFlags, |
| 2029 | "-nostdlib", |
| 2030 | "-Bstatic", |
| 2031 | "-Wl,--gc-sections", |
| 2032 | ) |
| 2033 | |
| 2034 | } else { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2035 | if flags.DynamicLinker == "" { |
| 2036 | flags.DynamicLinker = "/system/bin/linker" |
| 2037 | if flags.Toolchain.Is64Bit() { |
| 2038 | flags.DynamicLinker += "64" |
| 2039 | } |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | flags.LdFlags = append(flags.LdFlags, |
Colin Cross | 979422c | 2015-12-01 14:09:48 -0800 | [diff] [blame] | 2043 | "-pie", |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2044 | "-nostdlib", |
| 2045 | "-Bdynamic", |
Colin Cross | ed4cf0b | 2015-03-26 14:43:45 -0700 | [diff] [blame] | 2046 | "-Wl,--gc-sections", |
| 2047 | "-Wl,-z,nocopyreloc", |
| 2048 | ) |
| 2049 | } |
Dan Willemsen | 36cff8b | 2016-05-17 16:35:02 -0700 | [diff] [blame] | 2050 | } else { |
| 2051 | if binary.staticBinary() { |
| 2052 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 2053 | } |
| 2054 | if ctx.Darwin() { |
| 2055 | flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names") |
| 2056 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2059 | return flags |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2062 | func (binary *binaryLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2063 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2064 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2065 | fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2066 | outputFile := android.PathForModuleOut(ctx, fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2067 | ret := outputFile |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2068 | if ctx.Os().Class == android.Host { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2069 | binary.hostToolPath = android.OptionalPathForPath(outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2070 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2071 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2072 | var linkerDeps android.Paths |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 2073 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2074 | sharedLibs := deps.SharedLibs |
| 2075 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
| 2076 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2077 | if flags.DynamicLinker != "" { |
| 2078 | flags.LdFlags = append(flags.LdFlags, " -Wl,-dynamic-linker,"+flags.DynamicLinker) |
| 2079 | } |
| 2080 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2081 | builderFlags := flagsToBuilderFlags(flags) |
| 2082 | |
| 2083 | if binary.stripper.needsStrip(ctx) { |
| 2084 | strippedOutputFile := outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2085 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2086 | binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 2087 | } |
| 2088 | |
| 2089 | if binary.Properties.Prefix_symbols != "" { |
| 2090 | afterPrefixSymbols := outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2091 | outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName) |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2092 | TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile, |
| 2093 | flagsToBuilderFlags(flags), afterPrefixSymbols) |
| 2094 | } |
| 2095 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2096 | TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs, |
Colin Cross | aee540a | 2015-07-06 17:48:31 -0700 | [diff] [blame] | 2097 | deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2098 | builderFlags, outputFile) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2099 | |
| 2100 | return ret |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2101 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2102 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2103 | func (binary *binaryLinker) HostToolPath() android.OptionalPath { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2104 | return binary.hostToolPath |
Colin Cross | d350ecd | 2015-04-28 13:25:36 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2107 | type stripper struct { |
| 2108 | StripProperties StripProperties |
| 2109 | } |
| 2110 | |
| 2111 | func (stripper *stripper) needsStrip(ctx ModuleContext) bool { |
| 2112 | return !ctx.AConfig().EmbeddedInMake() && !stripper.StripProperties.Strip.None |
| 2113 | } |
| 2114 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2115 | func (stripper *stripper) strip(ctx ModuleContext, in, out android.ModuleOutPath, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2116 | flags builderFlags) { |
Colin Cross | b8ecdfe | 2016-05-03 15:10:29 -0700 | [diff] [blame] | 2117 | if ctx.Darwin() { |
| 2118 | TransformDarwinStrip(ctx, in, out) |
| 2119 | } else { |
| 2120 | flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols |
| 2121 | // TODO(ccross): don't add gnu debuglink for user builds |
| 2122 | flags.stripAddGnuDebuglink = true |
| 2123 | TransformStrip(ctx, in, out, flags) |
| 2124 | } |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2127 | func testPerSrcMutator(mctx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2128 | if m, ok := mctx.Module().(*Module); ok { |
| 2129 | if test, ok := m.linker.(*testLinker); ok { |
| 2130 | if Bool(test.Properties.Test_per_src) { |
| 2131 | testNames := make([]string, len(m.compiler.(*baseCompiler).Properties.Srcs)) |
| 2132 | for i, src := range m.compiler.(*baseCompiler).Properties.Srcs { |
| 2133 | testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) |
| 2134 | } |
| 2135 | tests := mctx.CreateLocalVariations(testNames...) |
| 2136 | for i, src := range m.compiler.(*baseCompiler).Properties.Srcs { |
| 2137 | tests[i].(*Module).compiler.(*baseCompiler).Properties.Srcs = []string{src} |
| 2138 | tests[i].(*Module).linker.(*testLinker).binaryLinker.Properties.Stem = testNames[i] |
| 2139 | } |
Colin Cross | 6002e05 | 2015-09-16 16:00:08 -0700 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | } |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2145 | type testLinker struct { |
| 2146 | binaryLinker |
| 2147 | Properties TestLinkerProperties |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 2150 | func (test *testLinker) begin(ctx BaseModuleContext) { |
| 2151 | test.binaryLinker.begin(ctx) |
| 2152 | |
| 2153 | runpath := "../../lib" |
| 2154 | if ctx.toolchain().Is64Bit() { |
| 2155 | runpath += "64" |
| 2156 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2157 | test.dynamicProperties.RunPaths = append([]string{runpath}, test.dynamicProperties.RunPaths...) |
Dan Willemsen | d30e610 | 2016-03-30 17:35:50 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2160 | func (test *testLinker) props() []interface{} { |
| 2161 | return append(test.binaryLinker.props(), &test.Properties) |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2164 | func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags { |
| 2165 | flags = test.binaryLinker.flags(ctx, flags) |
| 2166 | |
| 2167 | if !test.Properties.Gtest { |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2168 | return flags |
| 2169 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2170 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2171 | flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING") |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 2172 | if ctx.Host() { |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 2173 | flags.CFlags = append(flags.CFlags, "-O0", "-g") |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2174 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2175 | switch ctx.Os() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2176 | case android.Windows: |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2177 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS") |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2178 | case android.Linux: |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2179 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX") |
| 2180 | flags.LdFlags = append(flags.LdFlags, "-lpthread") |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2181 | case android.Darwin: |
Dan Willemsen | 4a94683 | 2016-05-13 14:13:01 -0700 | [diff] [blame] | 2182 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC") |
| 2183 | flags.LdFlags = append(flags.LdFlags, "-lpthread") |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2184 | } |
| 2185 | } else { |
| 2186 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID") |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 2189 | return flags |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2192 | func (test *testLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 2193 | if test.Properties.Gtest { |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 2194 | if ctx.sdk() && ctx.Device() { |
| 2195 | switch ctx.selectedStl() { |
| 2196 | case "ndk_libc++_shared", "ndk_libc++_static": |
| 2197 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_libcxx", "libgtest_ndk_libcxx") |
| 2198 | case "ndk_libgnustl_static": |
| 2199 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_gnustl", "libgtest_ndk_gnustl") |
| 2200 | default: |
| 2201 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk", "libgtest_ndk") |
| 2202 | } |
| 2203 | } else { |
| 2204 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest") |
| 2205 | } |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2206 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2207 | deps = test.binaryLinker.deps(ctx, deps) |
| 2208 | return deps |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2211 | type testInstaller struct { |
| 2212 | baseInstaller |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 2213 | } |
| 2214 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2215 | func (installer *testInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2216 | installer.dir = filepath.Join(installer.dir, ctx.ModuleName()) |
| 2217 | installer.dir64 = filepath.Join(installer.dir64, ctx.ModuleName()) |
| 2218 | installer.baseInstaller.install(ctx, file) |
| 2219 | } |
| 2220 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2221 | func NewTest(hod android.HostOrDeviceSupported) *Module { |
| 2222 | module := newModule(hod, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2223 | module.compiler = &baseCompiler{} |
| 2224 | linker := &testLinker{} |
| 2225 | linker.Properties.Gtest = true |
| 2226 | module.linker = linker |
| 2227 | module.installer = &testInstaller{ |
| 2228 | baseInstaller: baseInstaller{ |
| 2229 | dir: "nativetest", |
| 2230 | dir64: "nativetest64", |
| 2231 | data: true, |
| 2232 | }, |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2233 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2234 | return module |
Dan Willemsen | 10d52fd | 2015-12-21 15:25:58 -0800 | [diff] [blame] | 2235 | } |
| 2236 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2237 | func testFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2238 | module := NewTest(android.HostAndDeviceSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2239 | return module.Init() |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2242 | type benchmarkLinker struct { |
| 2243 | binaryLinker |
Colin Cross | 9ffb4f5 | 2015-04-24 17:48:09 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2246 | func (benchmark *benchmarkLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 2247 | deps = benchmark.binaryLinker.deps(ctx, deps) |
| 2248 | deps.StaticLibs = append(deps.StaticLibs, "libbenchmark", "libbase") |
| 2249 | return deps |
Colin Cross | 9ffb4f5 | 2015-04-24 17:48:09 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2252 | func NewBenchmark(hod android.HostOrDeviceSupported) *Module { |
| 2253 | module := newModule(hod, android.MultilibFirst) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2254 | module.compiler = &baseCompiler{} |
| 2255 | module.linker = &benchmarkLinker{} |
| 2256 | module.installer = &baseInstaller{ |
| 2257 | dir: "nativetest", |
| 2258 | dir64: "nativetest64", |
| 2259 | data: true, |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2260 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2261 | return module |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2264 | func benchmarkFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2265 | module := NewBenchmark(android.HostAndDeviceSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2266 | return module.Init() |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2269 | // |
| 2270 | // Static library |
| 2271 | // |
| 2272 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2273 | func libraryStaticFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2274 | module := NewLibrary(android.HostAndDeviceSupported, false, true) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2275 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | // |
| 2279 | // Shared libraries |
| 2280 | // |
| 2281 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2282 | func librarySharedFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2283 | module := NewLibrary(android.HostAndDeviceSupported, true, false) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2284 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | // |
| 2288 | // Host static library |
| 2289 | // |
| 2290 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2291 | func libraryHostStaticFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2292 | module := NewLibrary(android.HostSupported, false, true) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2293 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | // |
| 2297 | // Host Shared libraries |
| 2298 | // |
| 2299 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2300 | func libraryHostSharedFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2301 | module := NewLibrary(android.HostSupported, true, false) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2302 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | // |
| 2306 | // Host Binaries |
| 2307 | // |
| 2308 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2309 | func binaryHostFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2310 | module := NewBinary(android.HostSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2311 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | // |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 2315 | // Host Tests |
| 2316 | // |
| 2317 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2318 | func testHostFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2319 | module := NewTest(android.HostSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2320 | return module.Init() |
Colin Cross | 1f8f234 | 2015-03-26 16:09:47 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | // |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2324 | // Host Benchmarks |
| 2325 | // |
| 2326 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2327 | func benchmarkHostFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2328 | module := NewBenchmark(android.HostSupported) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2329 | return module.Init() |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2333 | // Defaults |
| 2334 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2335 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2336 | android.ModuleBase |
| 2337 | android.DefaultsModule |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2340 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2341 | } |
| 2342 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2343 | func defaultsFactory() (blueprint.Module, []interface{}) { |
| 2344 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2345 | |
| 2346 | propertyStructs := []interface{}{ |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2347 | &BaseProperties{}, |
| 2348 | &BaseCompilerProperties{}, |
| 2349 | &BaseLinkerProperties{}, |
| 2350 | &LibraryCompilerProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2351 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2352 | &LibraryLinkerProperties{}, |
| 2353 | &BinaryLinkerProperties{}, |
| 2354 | &TestLinkerProperties{}, |
| 2355 | &UnusedProperties{}, |
| 2356 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2357 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2358 | &StripProperties{}, |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2359 | } |
| 2360 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2361 | _, propertyStructs = android.InitAndroidArchModule(module, android.HostAndDeviceDefault, |
| 2362 | android.MultilibDefault, propertyStructs...) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2363 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2364 | return android.InitDefaultsModule(module, module, propertyStructs...) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | // |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2368 | // Device libraries shipped with gcc |
| 2369 | // |
| 2370 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2371 | type toolchainLibraryLinker struct { |
| 2372 | baseLinker |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2375 | var _ baseLinkerInterface = (*toolchainLibraryLinker)(nil) |
| 2376 | |
| 2377 | func (*toolchainLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2378 | // toolchain libraries can't have any dependencies |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2379 | return deps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2380 | } |
| 2381 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2382 | func (*toolchainLibraryLinker) buildStatic() bool { |
| 2383 | return true |
| 2384 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2385 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2386 | func (*toolchainLibraryLinker) buildShared() bool { |
| 2387 | return false |
| 2388 | } |
| 2389 | |
| 2390 | func toolchainLibraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2391 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2392 | module.compiler = &baseCompiler{} |
| 2393 | module.linker = &toolchainLibraryLinker{} |
Dan Willemsen | fc9c28c | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 2394 | module.Properties.Clang = proptools.BoolPtr(false) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2395 | return module.Init() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2396 | } |
| 2397 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2398 | func (library *toolchainLibraryLinker) link(ctx ModuleContext, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2399 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2400 | |
| 2401 | libName := ctx.ModuleName() + staticLibraryExtension |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2402 | outputFile := android.PathForModuleOut(ctx, libName) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2403 | |
Dan Willemsen | fc9c28c | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 2404 | if flags.Clang { |
| 2405 | ctx.ModuleErrorf("toolchain_library must use GCC, not Clang") |
| 2406 | } |
| 2407 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2408 | CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2409 | |
| 2410 | ctx.CheckbuildFile(outputFile) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2411 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2412 | return outputFile |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2415 | func (*toolchainLibraryLinker) installable() bool { |
| 2416 | return false |
| 2417 | } |
| 2418 | |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2419 | // NDK prebuilt libraries. |
| 2420 | // |
| 2421 | // These differ from regular prebuilts in that they aren't stripped and usually aren't installed |
| 2422 | // either (with the exception of the shared STLs, which are installed to the app's directory rather |
| 2423 | // than to the system image). |
| 2424 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2425 | func getNdkLibDir(ctx android.ModuleContext, toolchain Toolchain, version string) android.SourcePath { |
Colin Cross | c7fd91a | 2016-05-17 13:15:15 -0700 | [diff] [blame] | 2426 | suffix := "" |
| 2427 | // Most 64-bit NDK prebuilts store libraries in "lib64", except for arm64 which is not a |
| 2428 | // multilib toolchain and stores the libraries in "lib". |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2429 | if toolchain.Is64Bit() && ctx.Arch().ArchType != android.Arm64 { |
Colin Cross | c7fd91a | 2016-05-17 13:15:15 -0700 | [diff] [blame] | 2430 | suffix = "64" |
| 2431 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2432 | 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] | 2433 | version, toolchain.Name(), suffix)) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2436 | func ndkPrebuiltModuleToPath(ctx android.ModuleContext, toolchain Toolchain, |
| 2437 | ext string, version string) android.Path { |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2438 | |
| 2439 | // NDK prebuilts are named like: ndk_NAME.EXT.SDK_VERSION. |
| 2440 | // We want to translate to just NAME.EXT |
| 2441 | name := strings.Split(strings.TrimPrefix(ctx.ModuleName(), "ndk_"), ".")[0] |
| 2442 | dir := getNdkLibDir(ctx, toolchain, version) |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2443 | return dir.Join(ctx, name+ext) |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2446 | type ndkPrebuiltObjectLinker struct { |
| 2447 | objectLinker |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2450 | func (*ndkPrebuiltObjectLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2451 | // NDK objects can't have any dependencies |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2452 | return deps |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2455 | func ndkPrebuiltObjectFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2456 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2457 | module.linker = &ndkPrebuiltObjectLinker{} |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2458 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2459 | return module.Init() |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2462 | func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2463 | deps PathDeps, objFiles android.Paths) android.Path { |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2464 | // A null build step, but it sets up the output path. |
| 2465 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") { |
| 2466 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name") |
| 2467 | } |
| 2468 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2469 | return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion()) |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2472 | type ndkPrebuiltLibraryLinker struct { |
| 2473 | libraryLinker |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2476 | var _ baseLinkerInterface = (*ndkPrebuiltLibraryLinker)(nil) |
| 2477 | var _ exportedFlagsProducer = (*libraryLinker)(nil) |
Dan Albert | c3144b1 | 2015-04-28 18:17:56 -0700 | [diff] [blame] | 2478 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2479 | func (ndk *ndkPrebuiltLibraryLinker) props() []interface{} { |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2480 | return append(ndk.libraryLinker.props(), &ndk.Properties, &ndk.flagExporter.Properties) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2483 | func (*ndkPrebuiltLibraryLinker) deps(ctx BaseModuleContext, deps Deps) Deps { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2484 | // NDK libraries can't have any dependencies |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2485 | return deps |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2488 | func ndkPrebuiltLibraryFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2489 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2490 | linker := &ndkPrebuiltLibraryLinker{} |
| 2491 | linker.dynamicProperties.BuildShared = true |
| 2492 | module.linker = linker |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2493 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2494 | return module.Init() |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2497 | func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2498 | deps PathDeps, objFiles android.Paths) android.Path { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2499 | // A null build step, but it sets up the output path. |
| 2500 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { |
| 2501 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") |
| 2502 | } |
| 2503 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2504 | ndk.exportIncludes(ctx, "-isystem") |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2505 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2506 | return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(), |
| 2507 | ctx.sdkVersion()) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | // The NDK STLs are slightly different from the prebuilt system libraries: |
| 2511 | // * Are not specific to each platform version. |
| 2512 | // * The libraries are not in a predictable location for each STL. |
| 2513 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2514 | type ndkPrebuiltStlLinker struct { |
| 2515 | ndkPrebuiltLibraryLinker |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2518 | func ndkPrebuiltSharedStlFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2519 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2520 | linker := &ndkPrebuiltStlLinker{} |
| 2521 | linker.dynamicProperties.BuildShared = true |
| 2522 | module.linker = linker |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2523 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2524 | return module.Init() |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2527 | func ndkPrebuiltStaticStlFactory() (blueprint.Module, []interface{}) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2528 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2529 | linker := &ndkPrebuiltStlLinker{} |
| 2530 | linker.dynamicProperties.BuildStatic = true |
| 2531 | module.linker = linker |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2532 | module.Properties.HideFromMake = true |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2533 | return module.Init() |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2536 | func getNdkStlLibDir(ctx android.ModuleContext, toolchain Toolchain, stl string) android.SourcePath { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2537 | gccVersion := toolchain.GccVersion() |
| 2538 | var libDir string |
| 2539 | switch stl { |
| 2540 | case "libstlport": |
| 2541 | libDir = "cxx-stl/stlport/libs" |
| 2542 | case "libc++": |
| 2543 | libDir = "cxx-stl/llvm-libc++/libs" |
| 2544 | case "libgnustl": |
| 2545 | libDir = fmt.Sprintf("cxx-stl/gnu-libstdc++/%s/libs", gccVersion) |
| 2546 | } |
| 2547 | |
| 2548 | if libDir != "" { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 2549 | ndkSrcRoot := "prebuilts/ndk/current/sources" |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2550 | return android.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0]) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | ctx.ModuleErrorf("Unknown NDK STL: %s", stl) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2554 | return android.PathForSource(ctx, "") |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2557 | func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2558 | deps PathDeps, objFiles android.Paths) android.Path { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2559 | // A null build step, but it sets up the output path. |
| 2560 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { |
| 2561 | ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") |
| 2562 | } |
| 2563 | |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2564 | ndk.exportIncludes(ctx, "-I") |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2565 | |
| 2566 | libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 2567 | libExt := flags.Toolchain.ShlibSuffix() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2568 | if ndk.dynamicProperties.BuildStatic { |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2569 | libExt = staticLibraryExtension |
| 2570 | } |
| 2571 | |
| 2572 | stlName := strings.TrimSuffix(libName, "_shared") |
| 2573 | stlName = strings.TrimSuffix(stlName, "_static") |
| 2574 | libDir := getNdkStlLibDir(ctx, flags.Toolchain, stlName) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2575 | return libDir.Join(ctx, libName+libExt) |
Dan Albert | be96168 | 2015-03-18 23:38:50 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2578 | func linkageMutator(mctx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2579 | if m, ok := mctx.Module().(*Module); ok { |
| 2580 | if m.linker != nil { |
| 2581 | if linker, ok := m.linker.(baseLinkerInterface); ok { |
| 2582 | var modules []blueprint.Module |
| 2583 | if linker.buildStatic() && linker.buildShared() { |
| 2584 | modules = mctx.CreateLocalVariations("static", "shared") |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2585 | static := modules[0].(*Module) |
| 2586 | shared := modules[1].(*Module) |
| 2587 | |
| 2588 | static.linker.(baseLinkerInterface).setStatic(true) |
| 2589 | shared.linker.(baseLinkerInterface).setStatic(false) |
| 2590 | |
| 2591 | if staticCompiler, ok := static.compiler.(*libraryCompiler); ok { |
| 2592 | sharedCompiler := shared.compiler.(*libraryCompiler) |
| 2593 | if len(staticCompiler.Properties.Static.Cflags) == 0 && |
| 2594 | len(sharedCompiler.Properties.Shared.Cflags) == 0 { |
| 2595 | // Optimize out compiling common .o files twice for static+shared libraries |
| 2596 | mctx.AddInterVariantDependency(reuseObjTag, shared, static) |
| 2597 | sharedCompiler.baseCompiler.Properties.Srcs = nil |
| 2598 | } |
| 2599 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2600 | } else if linker.buildStatic() { |
| 2601 | modules = mctx.CreateLocalVariations("static") |
| 2602 | modules[0].(*Module).linker.(baseLinkerInterface).setStatic(true) |
| 2603 | } else if linker.buildShared() { |
| 2604 | modules = mctx.CreateLocalVariations("shared") |
| 2605 | modules[0].(*Module).linker.(baseLinkerInterface).setStatic(false) |
| 2606 | } else { |
| 2607 | panic(fmt.Errorf("library %q not static or shared", mctx.ModuleName())) |
| 2608 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2609 | } |
| 2610 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2611 | } |
| 2612 | } |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 2613 | |
| 2614 | // lastUniqueElements returns all unique elements of a slice, keeping the last copy of each |
| 2615 | // modifies the slice contents in place, and returns a subslice of the original slice |
| 2616 | func lastUniqueElements(list []string) []string { |
| 2617 | totalSkip := 0 |
| 2618 | for i := len(list) - 1; i >= totalSkip; i-- { |
| 2619 | skip := 0 |
| 2620 | for j := i - 1; j >= totalSkip; j-- { |
| 2621 | if list[i] == list[j] { |
| 2622 | skip++ |
| 2623 | } else { |
| 2624 | list[j+skip] = list[j] |
| 2625 | } |
| 2626 | } |
| 2627 | totalSkip += skip |
| 2628 | } |
| 2629 | return list[totalSkip:] |
| 2630 | } |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 2631 | |
| 2632 | var Bool = proptools.Bool |