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