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