blob: 58bb57ca4cfc4564f3fd792342c5546b6d5d53ef [file] [log] [blame]
Dan Willemsen218f6562015-07-08 18:13:11 -07001// Copyright 2015 Google Inc. All rights reserved.
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
15package cc
16
17import (
Inseob Kimbf1b63f2022-01-21 18:12:48 +090018 "github.com/google/blueprint/proptools"
19
Dan Willemsen97750522016-02-09 17:43:51 -080020 "fmt"
Dan Willemsen218f6562015-07-08 18:13:11 -070021 "io"
Colin Crossa2344662016-03-24 13:14:12 -070022 "path/filepath"
Dan Willemsen218f6562015-07-08 18:13:11 -070023 "strings"
24
Colin Cross635c3b02016-05-18 15:37:25 -070025 "android/soong/android"
Kiyoung Kim835c5892022-08-17 16:40:16 +090026 "android/soong/multitree"
Dan Willemsen218f6562015-07-08 18:13:11 -070027)
28
Jiyong Park27b188b2017-07-18 13:23:39 +090029var (
Matthew Maurera61e31f2021-05-27 11:09:11 -070030 NativeBridgeSuffix = ".native_bridge"
Matthew Maurer52af5b02021-05-27 10:01:36 -070031 ProductSuffix = ".product"
Ivan Lozanoe6d30982021-02-05 10:57:43 -050032 VendorSuffix = ".vendor"
Matthew Maurerc6868382021-07-13 14:12:37 -070033 RamdiskSuffix = ".ramdisk"
Ivan Lozanoe6d30982021-02-05 10:57:43 -050034 VendorRamdiskSuffix = ".vendor_ramdisk"
Matthew Maurer460ee942021-02-11 12:31:46 -080035 RecoverySuffix = ".recovery"
Yifan Hong60e0cfb2020-10-21 15:17:56 -070036 sdkSuffix = ".sdk"
Jiyong Park27b188b2017-07-18 13:23:39 +090037)
38
Dan Willemsenf2c27d72016-07-13 16:50:22 -070039type AndroidMkContext interface {
Colin Cross0477b422020-10-13 18:43:54 -070040 BaseModuleName() string
Dan Willemsenf2c27d72016-07-13 16:50:22 -070041 Target() android.Target
Colin Crossd80cbca2020-02-24 12:01:37 -080042 subAndroidMk(*android.AndroidMkEntries, interface{})
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +000043 Arch() android.Arch
44 Os() android.OsType
45 Host() bool
Ivan Lozano52767be2019-10-18 14:49:46 -070046 UseVndk() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +090047 VndkVersion() string
Jiyong Parkb0788572018-12-20 22:10:17 +090048 static() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -080049 InRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -070050 InVendorRamdisk() bool
Ivan Lozano52767be2019-10-18 14:49:46 -070051 InRecovery() bool
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +090052 NotInPlatform() bool
Colin Crossb916a382016-07-29 17:28:03 -070053}
54
55type subAndroidMkProvider interface {
Colin Crossd80cbca2020-02-24 12:01:37 -080056 AndroidMkEntries(AndroidMkContext, *android.AndroidMkEntries)
Colin Crossb916a382016-07-29 17:28:03 -070057}
58
Colin Crossd80cbca2020-02-24 12:01:37 -080059func (c *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
Colin Crossb916a382016-07-29 17:28:03 -070060 if c.subAndroidMkOnce == nil {
61 c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
62 }
63 if androidmk, ok := obj.(subAndroidMkProvider); ok {
64 if !c.subAndroidMkOnce[androidmk] {
65 c.subAndroidMkOnce[androidmk] = true
Colin Crossd80cbca2020-02-24 12:01:37 -080066 androidmk.AndroidMkEntries(c, entries)
Colin Crossb916a382016-07-29 17:28:03 -070067 }
68 }
Dan Willemsenf2c27d72016-07-13 16:50:22 -070069}
70
Colin Crossd80cbca2020-02-24 12:01:37 -080071func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
Colin Cross56a83212020-09-15 18:30:11 -070072 if c.hideApexVariantFromMake || c.Properties.HideFromMake {
Colin Crossd80cbca2020-02-24 12:01:37 -080073 return []android.AndroidMkEntries{{
Colin Crossa18e9cf2017-08-10 17:00:19 -070074 Disabled: true,
Colin Crossd80cbca2020-02-24 12:01:37 -080075 }}
Colin Crossbc6fb162016-05-24 15:39:04 -070076 }
77
Colin Crossd80cbca2020-02-24 12:01:37 -080078 entries := android.AndroidMkEntries{
Colin Crossa18e9cf2017-08-10 17:00:19 -070079 OutputFile: c.outputFile,
Martin Stjernholm7f511072020-10-12 15:10:36 +010080 // TODO(jiyong): add the APEXes providing shared libs to the required
81 // modules Currently, adding c.Properties.ApexesProvidingSharedLibs is
82 // causing multiple ART APEXes (com.android.art and com.android.art.debug)
83 // to be installed. And this is breaking some older devices (like marlin)
84 // where system.img is small.
Jiyong Parkb0788572018-12-20 22:10:17 +090085 Required: c.Properties.AndroidMkRuntimeLibs,
Ivan Lozanod06cc742021-11-12 13:27:58 -050086 Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
Logan Chien43d34c32017-12-20 01:17:32 +080087
Colin Crossd80cbca2020-02-24 12:01:37 -080088 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -070089 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Cross5beccee2017-12-07 15:28:59 -080090 if len(c.Properties.Logtags) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -080091 entries.AddStrings("LOCAL_LOGTAGS_FILES", c.Properties.Logtags...)
Colin Cross5beccee2017-12-07 15:28:59 -080092 }
Yo Chiang219968c2020-09-22 18:45:04 +080093 // Note: Pass the exact value of AndroidMkSystemSharedLibs to the Make
94 // world, even if it is an empty list. In the Make world,
95 // LOCAL_SYSTEM_SHARED_LIBRARIES defaults to "none", which is expanded
96 // to the default list of system shared libs by the build system.
97 // Soong computes the exact list of system shared libs, so we have to
98 // override the default value when the list of libs is actually empty.
99 entries.SetString("LOCAL_SYSTEM_SHARED_LIBRARIES", strings.Join(c.Properties.AndroidMkSystemSharedLibs, " "))
Colin Crossa18e9cf2017-08-10 17:00:19 -0700100 if len(c.Properties.AndroidMkSharedLibs) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800101 entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...)
Colin Crossa18e9cf2017-08-10 17:00:19 -0700102 }
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +0000103 if len(c.Properties.AndroidMkStaticLibs) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800104 entries.AddStrings("LOCAL_STATIC_LIBRARIES", c.Properties.AndroidMkStaticLibs...)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +0000105 }
106 if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800107 entries.AddStrings("LOCAL_WHOLE_STATIC_LIBRARIES", c.Properties.AndroidMkWholeStaticLibs...)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +0000108 }
Bill Peckhama46de702020-04-21 17:23:37 -0700109 if len(c.Properties.AndroidMkHeaderLibs) > 0 {
110 entries.AddStrings("LOCAL_HEADER_LIBRARIES", c.Properties.AndroidMkHeaderLibs...)
111 }
yangbill6db86e52022-02-08 16:14:25 +0800112 if len(c.Properties.AndroidMkRuntimeLibs) > 0 {
113 entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...)
114 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800115 entries.SetString("LOCAL_SOONG_LINK_TYPE", c.makeLinkType)
Ivan Lozano52767be2019-10-18 14:49:46 -0700116 if c.UseVndk() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800117 entries.SetBool("LOCAL_USE_VNDK", true)
Ivan Lozano52767be2019-10-18 14:49:46 -0700118 if c.IsVndk() && !c.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800119 entries.SetString("LOCAL_SOONG_VNDK_VERSION", c.VndkVersion())
Jooyung Hanb01c1142019-10-29 05:24:42 +0900120 // VNDK libraries available to vendor are not installed because
121 // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
Ivan Lozanof9e21722020-12-02 09:00:51 -0500122 if !c.IsVndkExt() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800123 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Jooyung Hanb01c1142019-10-29 05:24:42 +0900124 }
Jooyung Han76106d92019-05-20 18:49:10 +0900125 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700126 }
Colin Crossc511bc52020-04-07 16:50:32 +0000127 if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
128 // Make the SDK variant uninstallable so that there are not two rules to install
129 // to the same location.
130 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
131 // Add the unsuffixed name to SOONG_SDK_VARIANT_MODULES so that Make can rewrite
132 // dependencies to the .sdk suffix when building a module that uses the SDK.
133 entries.SetString("SOONG_SDK_VARIANT_MODULES",
134 "$(SOONG_SDK_VARIANT_MODULES) $(patsubst %.sdk,%,$(LOCAL_MODULE))")
135 }
136 },
137 },
138 ExtraFooters: []android.AndroidMkExtraFootersFunc{
Jaewoong Jung02b11a62020-12-07 10:23:54 -0800139 func(w io.Writer, name, prefix, moduleDir string) {
Colin Crossc511bc52020-04-07 16:50:32 +0000140 if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake &&
141 c.CcLibraryInterface() && c.Shared() {
142 // Using the SDK variant as a JNI library needs a copy of the .so that
143 // is not named .sdk.so so that it can be packaged into the APK with
144 // the right name.
145 fmt.Fprintln(w, "$(eval $(call copy-one-file,",
146 "$(LOCAL_BUILT_MODULE),",
147 "$(patsubst %.sdk.so,%.so,$(LOCAL_BUILT_MODULE))))")
148 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700149 },
150 },
151 }
Colin Crossca860ac2016-01-04 14:34:37 -0800152
Colin Crossca860ac2016-01-04 14:34:37 -0800153 for _, feature := range c.features {
Colin Crossd80cbca2020-02-24 12:01:37 -0800154 c.subAndroidMk(&entries, feature)
Colin Crossca860ac2016-01-04 14:34:37 -0800155 }
156
Colin Crossd80cbca2020-02-24 12:01:37 -0800157 c.subAndroidMk(&entries, c.compiler)
158 c.subAndroidMk(&entries, c.linker)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700159 if c.sanitize != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800160 c.subAndroidMk(&entries, c.sanitize)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700161 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800162 c.subAndroidMk(&entries, c.installer)
Colin Crossca860ac2016-01-04 14:34:37 -0800163
Colin Crossd80cbca2020-02-24 12:01:37 -0800164 entries.SubName += c.Properties.SubName
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700165
Colin Crossd80cbca2020-02-24 12:01:37 -0800166 return []android.AndroidMkEntries{entries}
Colin Crossca860ac2016-01-04 14:34:37 -0800167}
168
Dan Shi95d19422020-08-15 12:24:26 -0700169func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) {
170 if len(extraTestConfigs) > 0 {
Colin Crossaa255532020-07-03 13:18:24 -0700171 entries.ExtraEntries = append(entries.ExtraEntries,
172 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
173 entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...)
174 })
Dan Shi95d19422020-08-15 12:24:26 -0700175 }
176}
177
Ivan Lozano9da4aa82021-01-29 12:48:05 -0500178func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) {
Dan Shi31949122020-09-21 12:11:02 -0700179 testFiles := android.AndroidMkDataPaths(data)
Anders Lewisb97e8182017-07-14 15:20:13 -0700180 if len(testFiles) > 0 {
Colin Crossaa255532020-07-03 13:18:24 -0700181 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800182 entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
Anders Lewisb97e8182017-07-14 15:20:13 -0700183 })
184 }
185}
186
dimitrydb417472019-05-20 16:16:47 +0200187func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
188 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
189 var result []string
190 for _, override := range overrides {
Matthew Maurera61e31f2021-05-27 11:09:11 -0700191 result = append(result, override+NativeBridgeSuffix)
dimitrydb417472019-05-20 16:16:47 +0200192 }
193 return result
194 }
195
196 return overrides
197}
198
Colin Crossd80cbca2020-02-24 12:01:37 -0800199func (library *libraryDecorator) androidMkWriteExportedFlags(entries *android.AndroidMkEntries) {
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400200 var exportedFlags []string
201 var includeDirs android.Paths
202 var systemIncludeDirs android.Paths
203 var exportedDeps android.Paths
204
205 if library.flagExporterInfo != nil {
206 exportedFlags = library.flagExporterInfo.Flags
207 includeDirs = library.flagExporterInfo.IncludeDirs
208 systemIncludeDirs = library.flagExporterInfo.SystemIncludeDirs
209 exportedDeps = library.flagExporterInfo.Deps
210 } else {
211 exportedFlags = library.flagExporter.flags
212 includeDirs = library.flagExporter.dirs
213 systemIncludeDirs = library.flagExporter.systemDirs
214 exportedDeps = library.flagExporter.deps
215 }
216 for _, dir := range includeDirs {
Jiyong Park74955042019-10-22 20:19:51 +0900217 exportedFlags = append(exportedFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +0900218 }
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400219 for _, dir := range systemIncludeDirs {
Jiyong Park74955042019-10-22 20:19:51 +0900220 exportedFlags = append(exportedFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +0900221 }
Dan Willemsen58539402017-03-19 13:44:32 -0700222 if len(exportedFlags) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800223 entries.AddStrings("LOCAL_EXPORT_CFLAGS", exportedFlags...)
Dan Willemsend5781342017-02-15 16:15:21 -0800224 }
Inseob Kim69378442019-06-03 19:10:47 +0900225 if len(exportedDeps) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800226 entries.AddStrings("LOCAL_EXPORT_C_INCLUDE_DEPS", exportedDeps.Strings()...)
Dan Willemsen58539402017-03-19 13:44:32 -0700227 }
228}
Dan Willemsend5781342017-02-15 16:15:21 -0800229
Mu-Le Lee0a9005e2022-07-05 09:49:50 +0000230func (library *libraryDecorator) getAbiDiffsForAndroidMkDeps() []string {
231 if library.static() {
232 return nil
Logan Chien41eabe62019-04-10 13:33:58 +0800233 }
Mu-Le Lee0a9005e2022-07-05 09:49:50 +0000234 var abiDiffs []string
235 if library.sAbiDiff.Valid() {
236 abiDiffs = append(abiDiffs, library.sAbiDiff.String())
237 }
238 if library.prevSAbiDiff.Valid() {
239 abiDiffs = append(abiDiffs, library.prevSAbiDiff.String())
240 }
241 return abiDiffs
242}
243
244func (library *libraryDecorator) androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries *android.AndroidMkEntries) {
245 entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", library.getAbiDiffsForAndroidMkDeps()...)
Logan Chien41eabe62019-04-10 13:33:58 +0800246}
247
Colin Crossd80cbca2020-02-24 12:01:37 -0800248// TODO(ccross): remove this once apex/androidmk.go is converted to AndroidMkEntries
249func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
Mu-Le Lee0a9005e2022-07-05 09:49:50 +0000250 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", strings.Join(library.getAbiDiffsForAndroidMkDeps(), " "))
Colin Crossd80cbca2020-02-24 12:01:37 -0800251}
252
253func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Dan Willemsend5781342017-02-15 16:15:21 -0800254 if library.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800255 entries.Class = "STATIC_LIBRARIES"
Dan Willemsend5781342017-02-15 16:15:21 -0800256 } else if library.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800257 entries.Class = "SHARED_LIBRARIES"
Colin Crossaa255532020-07-03 13:18:24 -0700258 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800259 entries.SetString("LOCAL_SOONG_TOC", library.toc().String())
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc3b97c32021-10-05 13:43:23 -0400260 if !library.buildStubs() && library.unstrippedOutputFile != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800261 entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", library.unstrippedOutputFile.String())
Jiyong Park47e4fcb2019-02-05 22:33:10 +0900262 }
dimitryd95964a2018-11-07 13:43:34 +0100263 if len(library.Properties.Overrides) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800264 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " "))
dimitryd95964a2018-11-07 13:43:34 +0100265 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800266 if len(library.postInstallCmds) > 0 {
267 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(library.postInstallCmds, "&& "))
Jiyong Parkf1194352019-02-25 11:05:47 +0900268 }
Colin Crossb60190a2018-09-04 16:28:17 -0700269 })
Dan Willemsend5781342017-02-15 16:15:21 -0800270 } else if library.header() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800271 entries.Class = "HEADER_LIBRARIES"
Dan Willemsend5781342017-02-15 16:15:21 -0800272 }
273
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000274 if library.distFile != nil {
275 entries.DistFiles = android.MakeDefaultDistFiles(library.distFile)
276 }
277
Colin Crossaa255532020-07-03 13:18:24 -0700278 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800279 library.androidMkWriteExportedFlags(entries)
280 library.androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries)
Dan Willemsen218f6562015-07-08 18:13:11 -0700281
Martin Stjernholme65c3ae2021-11-23 01:24:06 +0000282 if entries.OutputFile.Valid() {
283 _, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base())
284 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
285 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700286
Dan Willemsen581341d2017-02-09 16:16:31 -0800287 if library.coverageOutputFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800288 entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", library.coverageOutputFile.String())
Dan Willemsen581341d2017-02-09 16:16:31 -0800289 }
Vic Yangefd249e2018-11-12 20:19:56 -0800290
291 if library.useCoreVariant {
Colin Crossd80cbca2020-02-24 12:01:37 -0800292 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
293 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
294 entries.SetBool("LOCAL_VNDK_DEPEND_ON_CORE_VARIANT", true)
Vic Yangefd249e2018-11-12 20:19:56 -0800295 }
Vic Yangd92090f2020-01-08 14:32:28 -0800296 if library.checkSameCoreVariant {
Colin Crossd80cbca2020-02-24 12:01:37 -0800297 entries.SetBool("LOCAL_CHECK_SAME_VNDK_VARIANTS", true)
Vic Yangd92090f2020-01-08 14:32:28 -0800298 }
Colin Crossca860ac2016-01-04 14:34:37 -0800299 })
Colin Crossb916a382016-07-29 17:28:03 -0700300
Jiyong Parkb0788572018-12-20 22:10:17 +0900301 if library.shared() && !library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800302 ctx.subAndroidMk(entries, library.baseInstaller)
Colin Crossb60190a2018-09-04 16:28:17 -0700303 } else {
Colin Cross127bb8b2020-12-16 16:46:01 -0800304 if library.buildStubs() && library.stubsVersion() != "" {
Jooyung Hanad4c1872020-02-27 17:56:44 +0900305 entries.SubName = "." + library.stubsVersion()
306 }
Colin Crossaa255532020-07-03 13:18:24 -0700307 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800308 // library.makeUninstallable() depends on this to bypass HideFromMake() for
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100309 // static libraries.
Colin Crossd80cbca2020-02-24 12:01:37 -0800310 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Jiyong Parkb0788572018-12-20 22:10:17 +0900311 if library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800312 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
Jiyong Parkb0788572018-12-20 22:10:17 +0900313 }
Colin Crossb60190a2018-09-04 16:28:17 -0700314 })
Colin Crossb916a382016-07-29 17:28:03 -0700315 }
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +0900316 // If a library providing a stub is included in an APEX, the private APIs of the library
317 // is accessible only inside the APEX. From outside of the APEX, clients can only use the
318 // public APIs via the stub. To enforce this, the (latest version of the) stub gets the
319 // name of the library. The impl library instead gets the `.bootstrap` suffix to so that
320 // they can be exceptionally used directly when APEXes are not available (e.g. during the
321 // very early stage in the boot process).
322 if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.NotInPlatform() &&
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700323 !ctx.InRamdisk() && !ctx.InVendorRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.static() {
Jooyung Hanad4c1872020-02-27 17:56:44 +0900324 if library.buildStubs() && library.isLatestStubVersion() {
Jooyung Hanad4c1872020-02-27 17:56:44 +0900325 entries.SubName = ""
326 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900327 if !library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800328 entries.SubName = ".bootstrap"
Jiyong Parkb0788572018-12-20 22:10:17 +0900329 }
330 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700331}
332
Colin Crossd80cbca2020-02-24 12:01:37 -0800333func (object *objectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
334 entries.Class = "STATIC_LIBRARIES"
335 entries.ExtraFooters = append(entries.ExtraFooters,
Jaewoong Jung02b11a62020-12-07 10:23:54 -0800336 func(w io.Writer, name, prefix, moduleDir string) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800337 out := entries.OutputFile.Path()
338 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
Dan Willemsen218f6562015-07-08 18:13:11 -0700339
Colin Crossd80cbca2020-02-24 12:01:37 -0800340 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
341 fmt.Fprintln(w, ".KATI_READONLY: "+varname)
342 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700343}
344
Trevor Radcliffef389cb42022-03-24 21:06:14 +0000345func (test *testDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
346 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
347 if len(test.InstallerProperties.Test_suites) > 0 {
348 entries.AddCompatibilityTestSuites(test.InstallerProperties.Test_suites...)
349 }
350 })
351}
352
Colin Crossd80cbca2020-02-24 12:01:37 -0800353func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
354 ctx.subAndroidMk(entries, binary.baseInstaller)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700355
Colin Crossd80cbca2020-02-24 12:01:37 -0800356 entries.Class = "EXECUTABLES"
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000357 entries.DistFiles = binary.distFiles
Colin Crossaa255532020-07-03 13:18:24 -0700358 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800359 entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile.String())
Colin Cross9b09f242016-12-07 13:37:42 -0800360 if len(binary.symlinks) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800361 entries.AddStrings("LOCAL_MODULE_SYMLINKS", binary.symlinks...)
Colin Cross9b09f242016-12-07 13:37:42 -0800362 }
363
Dan Willemsen581341d2017-02-09 16:16:31 -0800364 if binary.coverageOutputFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800365 entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", binary.coverageOutputFile.String())
Dan Willemsen581341d2017-02-09 16:16:31 -0800366 }
Yifan Hong946e32e2018-04-03 13:22:50 -0700367
368 if len(binary.Properties.Overrides) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800369 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " "))
Yifan Hong946e32e2018-04-03 13:22:50 -0700370 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800371 if len(binary.postInstallCmds) > 0 {
372 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(binary.postInstallCmds, "&& "))
Jiyong Parkf1194352019-02-25 11:05:47 +0900373 }
Colin Crossca860ac2016-01-04 14:34:37 -0800374 })
375}
376
Colin Crossd80cbca2020-02-24 12:01:37 -0800377func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
378 ctx.subAndroidMk(entries, benchmark.binaryDecorator)
379 entries.Class = "NATIVE_TESTS"
Colin Crossaa255532020-07-03 13:18:24 -0700380 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crosse28f4e22017-04-24 18:10:29 -0700381 if len(benchmark.Properties.Test_suites) > 0 {
Liz Kammer57f5b332020-11-24 12:42:58 -0800382 entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
Colin Crosse28f4e22017-04-24 18:10:29 -0700383 }
Colin Cross303e21f2018-08-07 16:49:25 -0700384 if benchmark.testConfig != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800385 entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700386 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800387 entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
Dan Shi2468d012020-01-06 15:47:57 -0800388 if !BoolDefault(benchmark.Properties.Auto_gen_config, true) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800389 entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
Dan Shi2468d012020-01-06 15:47:57 -0800390 }
Colin Crosse28f4e22017-04-24 18:10:29 -0700391 })
Chris Parsons216e10a2020-07-09 17:12:52 -0400392 dataPaths := []android.DataPath{}
393 for _, srcPath := range benchmark.data {
394 dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
395 }
Ivan Lozano9da4aa82021-01-29 12:48:05 -0500396 AndroidMkWriteTestData(dataPaths, entries)
Colin Crossb916a382016-07-29 17:28:03 -0700397}
398
Colin Crossd80cbca2020-02-24 12:01:37 -0800399func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
400 ctx.subAndroidMk(entries, test.binaryDecorator)
Trevor Radcliffef389cb42022-03-24 21:06:14 +0000401 ctx.subAndroidMk(entries, test.testDecorator)
402
Colin Crossd80cbca2020-02-24 12:01:37 -0800403 entries.Class = "NATIVE_TESTS"
Colin Crossb916a382016-07-29 17:28:03 -0700404 if Bool(test.Properties.Test_per_src) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800405 entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
Colin Crossa2344662016-03-24 13:14:12 -0700406 }
Colin Crossaa255532020-07-03 13:18:24 -0700407 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Cross303e21f2018-08-07 16:49:25 -0700408 if test.testConfig != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800409 entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700410 }
Dan Shi2468d012020-01-06 15:47:57 -0800411 if !BoolDefault(test.Properties.Auto_gen_config, true) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800412 entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
Dan Shi2468d012020-01-06 15:47:57 -0800413 }
kellyhung74b00522020-08-17 18:46:00 +0800414 entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...)
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700415
416 entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory))
yangbill22bafec2022-02-11 18:06:07 +0800417 if len(test.Properties.Data_bins) > 0 {
418 entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
419 }
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +0800420
421 test.Properties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
Colin Crossa929db02017-03-27 16:27:50 -0700422 })
423
Ivan Lozano9da4aa82021-01-29 12:48:05 -0500424 AndroidMkWriteTestData(test.data, entries)
Dan Shi95d19422020-08-15 12:24:26 -0700425 androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
Colin Crossa2344662016-03-24 13:14:12 -0700426}
427
Colin Crossd80cbca2020-02-24 12:01:37 -0800428func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
429 ctx.subAndroidMk(entries, fuzz.binaryDecorator)
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700430
431 var fuzzFiles []string
hamzeh41ad8812021-07-07 14:00:07 -0700432 for _, d := range fuzz.fuzzPackagedModule.Corpus {
Mitch Phillips8a2bc0b2019-10-17 15:04:01 -0700433 fuzzFiles = append(fuzzFiles,
hamzeh41ad8812021-07-07 14:00:07 -0700434 filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700435 }
436
hamzeh41ad8812021-07-07 14:00:07 -0700437 for _, d := range fuzz.fuzzPackagedModule.Data {
Tri Voad172d82019-11-27 13:45:45 -0800438 fuzzFiles = append(fuzzFiles,
hamzeh41ad8812021-07-07 14:00:07 -0700439 filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
Tri Voad172d82019-11-27 13:45:45 -0800440 }
441
hamzeh41ad8812021-07-07 14:00:07 -0700442 if fuzz.fuzzPackagedModule.Dictionary != nil {
Mitch Phillips8a2bc0b2019-10-17 15:04:01 -0700443 fuzzFiles = append(fuzzFiles,
hamzeh41ad8812021-07-07 14:00:07 -0700444 filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700445 }
446
hamzeh41ad8812021-07-07 14:00:07 -0700447 if fuzz.fuzzPackagedModule.Config != nil {
Kris Alderf979ee32019-10-22 10:52:01 -0700448 fuzzFiles = append(fuzzFiles,
hamzeh41ad8812021-07-07 14:00:07 -0700449 filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
Kris Alderf979ee32019-10-22 10:52:01 -0700450 }
451
Colin Crossaa255532020-07-03 13:18:24 -0700452 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800453 entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
Mitch Phillipse1ee1a12019-10-17 19:20:41 -0700454 if len(fuzzFiles) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800455 entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
Mitch Phillipse1ee1a12019-10-17 19:20:41 -0700456 }
457 if fuzz.installedSharedDeps != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800458 entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
Mitch Phillipse1ee1a12019-10-17 19:20:41 -0700459 }
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700460 })
461}
462
Colin Crossd80cbca2020-02-24 12:01:37 -0800463func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
464 ctx.subAndroidMk(entries, test.libraryDecorator)
Trevor Radcliffef389cb42022-03-24 21:06:14 +0000465 ctx.subAndroidMk(entries, test.testDecorator)
Colin Crossb916a382016-07-29 17:28:03 -0700466}
Dan Willemsene7932e82016-05-16 15:56:53 -0700467
Colin Crossd80cbca2020-02-24 12:01:37 -0800468func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Colin Crossc511bc52020-04-07 16:50:32 +0000469 if installer.path == (android.InstallPath{}) {
470 return
471 }
Dan Willemsen03ce63e2016-09-29 12:17:49 -0700472
Colin Crossaa255532020-07-03 13:18:24 -0700473 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800474 path, file := filepath.Split(installer.path.String())
Ivan Lozano022a73b2019-09-09 20:29:31 -0700475 stem, suffix, _ := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800476 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
477 entries.SetString("LOCAL_MODULE_PATH", path)
478 entries.SetString("LOCAL_MODULE_STEM", stem)
Colin Crossa2344662016-03-24 13:14:12 -0700479 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700480}
Dan Albert914449f2016-06-17 16:45:24 -0700481
Colin Crossd80cbca2020-02-24 12:01:37 -0800482func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Dan Albert1a246272020-07-06 14:49:35 -0700483 entries.SubName = ndkLibrarySuffix + "." + c.apiLevel.String()
Colin Crossd80cbca2020-02-24 12:01:37 -0800484 entries.Class = "SHARED_LIBRARIES"
Dan Albert914449f2016-06-17 16:45:24 -0700485
Colin Cross5ec407b2020-09-30 11:41:33 -0700486 if !c.buildStubs() {
487 entries.Disabled = true
488 return
489 }
490
Colin Crossaa255532020-07-03 13:18:24 -0700491 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Cross0875c522017-11-28 17:34:01 -0800492 path, file := filepath.Split(c.installPath.String())
Ivan Lozano022a73b2019-09-09 20:29:31 -0700493 stem, suffix, _ := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800494 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
495 entries.SetString("LOCAL_MODULE_PATH", path)
496 entries.SetString("LOCAL_MODULE_STEM", stem)
497 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
sophiez58cabb72020-05-29 13:37:12 -0700498 if c.parsedCoverageXmlPath.String() != "" {
499 entries.SetString("SOONG_NDK_API_XML", "$(SOONG_NDK_API_XML) "+c.parsedCoverageXmlPath.String())
500 }
Dan Albert914449f2016-06-17 16:45:24 -0700501 })
502}
Dan Willemsenb916b802017-03-19 13:44:32 -0700503
Colin Crossd80cbca2020-02-24 12:01:37 -0800504func (c *vndkPrebuiltLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
505 entries.Class = "SHARED_LIBRARIES"
Justin Yun71549282017-11-17 12:10:28 +0900506
Colin Crossd80cbca2020-02-24 12:01:37 -0800507 entries.SubName = c.androidMkSuffix
Justin Yun71549282017-11-17 12:10:28 +0900508
Colin Crossaa255532020-07-03 13:18:24 -0700509 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800510 c.libraryDecorator.androidMkWriteExportedFlags(entries)
Justin Yun71549282017-11-17 12:10:28 +0900511
Inseob Kim81235ff2020-10-23 14:36:11 +0900512 // Specifying stem is to pass check_elf_files when vendor modules link against vndk prebuilt.
513 // We can't use install path because VNDKs are not installed. Instead, Srcs is directly used.
514 _, file := filepath.Split(c.properties.Srcs[0])
515 stem, suffix, ext := android.SplitFileExt(file)
516 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
517 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
518 entries.SetString("LOCAL_MODULE_STEM", stem)
519
Inseob Kimeec88e12020-01-22 11:11:29 +0900520 if c.tocFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800521 entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
Inseob Kimeec88e12020-01-22 11:11:29 +0900522 }
Inseob Kim81235ff2020-10-23 14:36:11 +0900523
524 // VNDK libraries available to vendor are not installed because
525 // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
526 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Inseob Kimeec88e12020-01-22 11:11:29 +0900527 })
528}
529
Jose Galmesf7294582020-11-13 12:07:36 -0800530func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900531 // Each vendor snapshot is exported to androidMk only when BOARD_VNDK_VERSION != current
532 // and the version of the prebuilt is same as BOARD_VNDK_VERSION.
533 if c.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800534 entries.Class = "SHARED_LIBRARIES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900535 } else if c.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800536 entries.Class = "STATIC_LIBRARIES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900537 } else if c.header() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800538 entries.Class = "HEADER_LIBRARIES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900539 }
540
Inseob Kimc42f2f22020-07-29 20:32:10 +0900541 entries.SubName = ""
542
543 if c.sanitizerProperties.CfiEnabled {
544 entries.SubName += ".cfi"
545 }
546
Colin Crossa8890802021-01-22 14:06:33 -0800547 entries.SubName += c.baseProperties.Androidmk_suffix
Inseob Kimeec88e12020-01-22 11:11:29 +0900548
Inseob Kima1888ce2022-10-04 14:42:02 +0900549 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800550 c.libraryDecorator.androidMkWriteExportedFlags(entries)
Inseob Kimeec88e12020-01-22 11:11:29 +0900551
Inseob Kimc3b1a162020-02-18 12:42:54 +0900552 if c.shared() || c.static() {
Inseob Kimbf1b63f2022-01-21 18:12:48 +0900553 src := c.path.String()
554 // For static libraries which aren't installed, directly use Src to extract filename.
555 // This is safe: generated snapshot modules have a real path as Src, not a module
556 if c.static() {
557 src = proptools.String(c.properties.Src)
558 }
559 path, file := filepath.Split(src)
Inseob Kimeec88e12020-01-22 11:11:29 +0900560 stem, suffix, ext := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800561 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
562 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
563 entries.SetString("LOCAL_MODULE_STEM", stem)
Inseob Kimeec88e12020-01-22 11:11:29 +0900564 if c.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800565 entries.SetString("LOCAL_MODULE_PATH", path)
Inseob Kimeec88e12020-01-22 11:11:29 +0900566 }
567 if c.tocFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800568 entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
Inseob Kimeec88e12020-01-22 11:11:29 +0900569 }
Inseob Kima1888ce2022-10-04 14:42:02 +0900570
571 if c.shared() && len(c.Properties.Overrides) > 0 {
572 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, c.Properties.Overrides), " "))
573 }
Inseob Kimc3b1a162020-02-18 12:42:54 +0900574 }
575
576 if !c.shared() { // static or header
Colin Crossd80cbca2020-02-24 12:01:37 -0800577 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Inseob Kimeec88e12020-01-22 11:11:29 +0900578 }
579 })
580}
581
Jose Galmesf7294582020-11-13 12:07:36 -0800582func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800583 entries.Class = "EXECUTABLES"
Colin Crossa8890802021-01-22 14:06:33 -0800584 entries.SubName = c.baseProperties.Androidmk_suffix
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800585}
Dan Albert8ba131b2017-12-14 13:23:15 -0800586
Jose Galmesf7294582020-11-13 12:07:36 -0800587func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Inseob Kim1042d292020-06-01 23:23:05 +0900588 entries.Class = "STATIC_LIBRARIES"
Colin Crossa8890802021-01-22 14:06:33 -0800589 entries.SubName = c.baseProperties.Androidmk_suffix
Inseob Kim1042d292020-06-01 23:23:05 +0900590
591 entries.ExtraFooters = append(entries.ExtraFooters,
Jaewoong Jung02b11a62020-12-07 10:23:54 -0800592 func(w io.Writer, name, prefix, moduleDir string) {
Inseob Kim1042d292020-06-01 23:23:05 +0900593 out := entries.OutputFile.Path()
594 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
595
596 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
597 fmt.Fprintln(w, ".KATI_READONLY: "+varname)
598 })
599}
600
Colin Crossd80cbca2020-02-24 12:01:37 -0800601func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
602 entries.Class = "SHARED_LIBRARIES"
Dan Albert8ba131b2017-12-14 13:23:15 -0800603}
Jiyong Park374510b2018-03-19 18:23:01 +0900604
Colin Crossd80cbca2020-02-24 12:01:37 -0800605func (p *prebuiltLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Colin Crossaa255532020-07-03 13:18:24 -0700606 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Logan Chien4fcea3d2018-11-20 11:59:08 +0800607 if p.properties.Check_elf_files != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800608 entries.SetBool("LOCAL_CHECK_ELF_FILES", *p.properties.Check_elf_files)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800609 } else {
Ivan Lozanod06cc742021-11-12 13:27:58 -0500610 // soong_cc_rust_prebuilt.mk does not include check_elf_file.mk by default
611 // because cc_library_shared and cc_binary use soong_cc_rust_prebuilt.mk as well.
Logan Chien4fcea3d2018-11-20 11:59:08 +0800612 // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to
613 // true if `p.properties.Check_elf_files` is not specified.
Colin Crossd80cbca2020-02-24 12:01:37 -0800614 entries.SetBool("LOCAL_CHECK_ELF_FILES", true)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800615 }
616 })
617}
618
Colin Crossd80cbca2020-02-24 12:01:37 -0800619func (p *prebuiltLibraryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
620 ctx.subAndroidMk(entries, p.libraryDecorator)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800621 if p.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800622 ctx.subAndroidMk(entries, &p.prebuiltLinker)
623 androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800624 }
625}
626
Colin Crossd80cbca2020-02-24 12:01:37 -0800627func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
628 ctx.subAndroidMk(entries, p.binaryDecorator)
629 ctx.subAndroidMk(entries, &p.prebuiltLinker)
630 androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800631}
632
Kiyoung Kim835c5892022-08-17 16:40:16 +0900633func (a *apiLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
634 entries.Class = "SHARED_LIBRARIES"
635 entries.SubName += multitree.GetApiImportSuffix()
636
637 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
638 a.libraryDecorator.androidMkWriteExportedFlags(entries)
639 src := *a.properties.Src
640 path, file := filepath.Split(src)
641 stem, suffix, ext := android.SplitFileExt(file)
642 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
643 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
644 entries.SetString("LOCAL_MODULE_STEM", stem)
645 entries.SetString("LOCAL_MODULE_PATH", path)
646 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
647 entries.SetString("LOCAL_SOONG_TOC", a.toc().String())
648 })
649}
650
Kiyoung Kim51279d32022-08-24 14:10:46 +0900651func (a *apiHeadersDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
652 entries.Class = "HEADER_LIBRARIES"
653 entries.SubName += multitree.GetApiImportSuffix()
654
655 entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
656 a.libraryDecorator.androidMkWriteExportedFlags(entries)
657 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
658 })
659}
660
Colin Crossd80cbca2020-02-24 12:01:37 -0800661func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, entries *android.AndroidMkEntries) {
662 allow := linker.Properties.Allow_undefined_symbols
663 if allow != nil {
Colin Crossaa255532020-07-03 13:18:24 -0700664 entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800665 entries.SetBool("LOCAL_ALLOW_UNDEFINED_SYMBOLS", *allow)
666 })
667 }
Logan Chien4fcea3d2018-11-20 11:59:08 +0800668}