blob: ef695b003e7765dc119b5a59514b953a386fabbd [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 (
Dan Willemsen97750522016-02-09 17:43:51 -080018 "fmt"
Dan Willemsen218f6562015-07-08 18:13:11 -070019 "io"
Colin Crossa2344662016-03-24 13:14:12 -070020 "path/filepath"
Dan Willemsen218f6562015-07-08 18:13:11 -070021 "strings"
22
Colin Cross635c3b02016-05-18 15:37:25 -070023 "android/soong/android"
Dan Willemsen218f6562015-07-08 18:13:11 -070024)
25
Jiyong Park27b188b2017-07-18 13:23:39 +090026var (
dimitry43204492019-05-23 13:24:38 +020027 nativeBridgeSuffix = ".native_bridge"
Justin Yun5f7f7e82019-11-18 19:52:14 +090028 productSuffix = ".product"
dimitry43204492019-05-23 13:24:38 +020029 vendorSuffix = ".vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -080030 ramdiskSuffix = ".ramdisk"
dimitry43204492019-05-23 13:24:38 +020031 recoverySuffix = ".recovery"
Jiyong Park27b188b2017-07-18 13:23:39 +090032)
33
Dan Willemsenf2c27d72016-07-13 16:50:22 -070034type AndroidMkContext interface {
Jiyong Parkb0788572018-12-20 22:10:17 +090035 Name() string
Dan Willemsenf2c27d72016-07-13 16:50:22 -070036 Target() android.Target
Colin Crossd80cbca2020-02-24 12:01:37 -080037 subAndroidMk(*android.AndroidMkEntries, interface{})
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +000038 Arch() android.Arch
39 Os() android.OsType
40 Host() bool
Ivan Lozano52767be2019-10-18 14:49:46 -070041 UseVndk() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +090042 VndkVersion() string
Jiyong Parkb0788572018-12-20 22:10:17 +090043 static() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -080044 InRamdisk() bool
Ivan Lozano52767be2019-10-18 14:49:46 -070045 InRecovery() bool
Colin Crossb916a382016-07-29 17:28:03 -070046}
47
48type subAndroidMkProvider interface {
Colin Crossd80cbca2020-02-24 12:01:37 -080049 AndroidMkEntries(AndroidMkContext, *android.AndroidMkEntries)
Colin Crossb916a382016-07-29 17:28:03 -070050}
51
Colin Crossd80cbca2020-02-24 12:01:37 -080052func (c *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
Colin Crossb916a382016-07-29 17:28:03 -070053 if c.subAndroidMkOnce == nil {
54 c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
55 }
56 if androidmk, ok := obj.(subAndroidMkProvider); ok {
57 if !c.subAndroidMkOnce[androidmk] {
58 c.subAndroidMkOnce[androidmk] = true
Colin Crossd80cbca2020-02-24 12:01:37 -080059 androidmk.AndroidMkEntries(c, entries)
Colin Crossb916a382016-07-29 17:28:03 -070060 }
61 }
Dan Willemsenf2c27d72016-07-13 16:50:22 -070062}
63
Colin Crossd80cbca2020-02-24 12:01:37 -080064func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
Jiyong Park9d452992018-10-03 00:38:19 +090065 if c.Properties.HideFromMake || !c.IsForPlatform() {
Colin Crossd80cbca2020-02-24 12:01:37 -080066 return []android.AndroidMkEntries{{
Colin Crossa18e9cf2017-08-10 17:00:19 -070067 Disabled: true,
Colin Crossd80cbca2020-02-24 12:01:37 -080068 }}
Colin Crossbc6fb162016-05-24 15:39:04 -070069 }
70
Colin Crossd80cbca2020-02-24 12:01:37 -080071 entries := android.AndroidMkEntries{
Colin Crossa18e9cf2017-08-10 17:00:19 -070072 OutputFile: c.outputFile,
Jiyong Parkb0788572018-12-20 22:10:17 +090073 // TODO(jiyong): add the APEXes providing shared libs to the required modules
74 // Currently, adding c.Properties.ApexesProvidingSharedLibs is causing multiple
Martin Stjernholmcc4b0ad2019-07-05 22:38:25 +010075 // ART APEXes (com.android.art.debug|release) to be installed. And this
Jiyong Parkb0788572018-12-20 22:10:17 +090076 // is breaking some older devices (like marlin) where system.img is small.
77 Required: c.Properties.AndroidMkRuntimeLibs,
78 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Logan Chien43d34c32017-12-20 01:17:32 +080079
Colin Crossd80cbca2020-02-24 12:01:37 -080080 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
81 func(entries *android.AndroidMkEntries) {
Colin Cross5beccee2017-12-07 15:28:59 -080082 if len(c.Properties.Logtags) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -080083 entries.AddStrings("LOCAL_LOGTAGS_FILES", c.Properties.Logtags...)
Colin Cross5beccee2017-12-07 15:28:59 -080084 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070085 if len(c.Properties.AndroidMkSharedLibs) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -080086 entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...)
Colin Crossa18e9cf2017-08-10 17:00:19 -070087 }
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +000088 if len(c.Properties.AndroidMkStaticLibs) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -080089 entries.AddStrings("LOCAL_STATIC_LIBRARIES", c.Properties.AndroidMkStaticLibs...)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +000090 }
91 if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -080092 entries.AddStrings("LOCAL_WHOLE_STATIC_LIBRARIES", c.Properties.AndroidMkWholeStaticLibs...)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +000093 }
Colin Crossd80cbca2020-02-24 12:01:37 -080094 entries.SetString("LOCAL_SOONG_LINK_TYPE", c.makeLinkType)
Ivan Lozano52767be2019-10-18 14:49:46 -070095 if c.UseVndk() {
Colin Crossd80cbca2020-02-24 12:01:37 -080096 entries.SetBool("LOCAL_USE_VNDK", true)
Ivan Lozano52767be2019-10-18 14:49:46 -070097 if c.IsVndk() && !c.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -080098 entries.SetString("LOCAL_SOONG_VNDK_VERSION", c.VndkVersion())
Jooyung Hanb01c1142019-10-29 05:24:42 +090099 // VNDK libraries available to vendor are not installed because
100 // they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
101 if !c.isVndkExt() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800102 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Jooyung Hanb01c1142019-10-29 05:24:42 +0900103 }
Jooyung Han76106d92019-05-20 18:49:10 +0900104 }
Colin Crossa18e9cf2017-08-10 17:00:19 -0700105 }
106 },
107 },
108 }
Colin Crossca860ac2016-01-04 14:34:37 -0800109
Colin Crossca860ac2016-01-04 14:34:37 -0800110 for _, feature := range c.features {
Colin Crossd80cbca2020-02-24 12:01:37 -0800111 c.subAndroidMk(&entries, feature)
Colin Crossca860ac2016-01-04 14:34:37 -0800112 }
113
Colin Crossd80cbca2020-02-24 12:01:37 -0800114 c.subAndroidMk(&entries, c.compiler)
115 c.subAndroidMk(&entries, c.linker)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700116 if c.sanitize != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800117 c.subAndroidMk(&entries, c.sanitize)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700118 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800119 c.subAndroidMk(&entries, c.installer)
Colin Crossca860ac2016-01-04 14:34:37 -0800120
Colin Crossd80cbca2020-02-24 12:01:37 -0800121 entries.SubName += c.Properties.SubName
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700122
Colin Crossd80cbca2020-02-24 12:01:37 -0800123 return []android.AndroidMkEntries{entries}
Colin Crossca860ac2016-01-04 14:34:37 -0800124}
125
Colin Crossd80cbca2020-02-24 12:01:37 -0800126func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Anders Lewisb97e8182017-07-14 15:20:13 -0700127 var testFiles []string
128 for _, d := range data {
129 rel := d.Rel()
130 path := d.String()
131 if !strings.HasSuffix(path, rel) {
132 panic(fmt.Errorf("path %q does not end with %q", path, rel))
133 }
134 path = strings.TrimSuffix(path, rel)
135 testFiles = append(testFiles, path+":"+rel)
136 }
137 if len(testFiles) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800138 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
139 entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
Anders Lewisb97e8182017-07-14 15:20:13 -0700140 })
141 }
142}
143
dimitrydb417472019-05-20 16:16:47 +0200144func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
145 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
146 var result []string
147 for _, override := range overrides {
148 result = append(result, override+nativeBridgeSuffix)
149 }
150 return result
151 }
152
153 return overrides
154}
155
Colin Crossd80cbca2020-02-24 12:01:37 -0800156func (library *libraryDecorator) androidMkWriteExportedFlags(entries *android.AndroidMkEntries) {
Dan Willemsen58539402017-03-19 13:44:32 -0700157 exportedFlags := library.exportedFlags()
Inseob Kim69378442019-06-03 19:10:47 +0900158 for _, dir := range library.exportedDirs() {
Jiyong Park74955042019-10-22 20:19:51 +0900159 exportedFlags = append(exportedFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +0900160 }
161 for _, dir := range library.exportedSystemDirs() {
Jiyong Park74955042019-10-22 20:19:51 +0900162 exportedFlags = append(exportedFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +0900163 }
Dan Willemsen58539402017-03-19 13:44:32 -0700164 if len(exportedFlags) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800165 entries.AddStrings("LOCAL_EXPORT_CFLAGS", exportedFlags...)
Dan Willemsend5781342017-02-15 16:15:21 -0800166 }
Inseob Kim69378442019-06-03 19:10:47 +0900167 exportedDeps := library.exportedDeps()
168 if len(exportedDeps) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800169 entries.AddStrings("LOCAL_EXPORT_C_INCLUDE_DEPS", exportedDeps.Strings()...)
Dan Willemsen58539402017-03-19 13:44:32 -0700170 }
171}
Dan Willemsend5781342017-02-15 16:15:21 -0800172
Colin Crossd80cbca2020-02-24 12:01:37 -0800173func (library *libraryDecorator) androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries *android.AndroidMkEntries) {
Logan Chien41eabe62019-04-10 13:33:58 +0800174 if library.sAbiOutputFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800175 entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES",
176 "$(LOCAL_ADDITIONAL_DEPENDENCIES) "+library.sAbiOutputFile.String())
Logan Chien41eabe62019-04-10 13:33:58 +0800177 if library.sAbiDiff.Valid() && !library.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800178 entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES",
179 "$(LOCAL_ADDITIONAL_DEPENDENCIES) "+library.sAbiDiff.String())
180 entries.SetString("HEADER_ABI_DIFFS",
181 "$(HEADER_ABI_DIFFS) "+library.sAbiDiff.String())
Logan Chien41eabe62019-04-10 13:33:58 +0800182 }
183 }
184}
185
Colin Crossd80cbca2020-02-24 12:01:37 -0800186// TODO(ccross): remove this once apex/androidmk.go is converted to AndroidMkEntries
187func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
188 if library.sAbiOutputFile.Valid() {
189 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_ADDITIONAL_DEPENDENCIES) ",
190 library.sAbiOutputFile.String())
191 if library.sAbiDiff.Valid() && !library.static() {
192 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_ADDITIONAL_DEPENDENCIES) ",
193 library.sAbiDiff.String())
194 fmt.Fprintln(w, "HEADER_ABI_DIFFS := $(HEADER_ABI_DIFFS) ",
195 library.sAbiDiff.String())
196 }
197 }
198}
199
200func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Dan Willemsend5781342017-02-15 16:15:21 -0800201 if library.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800202 entries.Class = "STATIC_LIBRARIES"
Dan Willemsend5781342017-02-15 16:15:21 -0800203 } else if library.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800204 entries.Class = "SHARED_LIBRARIES"
205 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
206 entries.SetString("LOCAL_SOONG_TOC", library.toc().String())
Jiyong Park47e4fcb2019-02-05 22:33:10 +0900207 if !library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800208 entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", library.unstrippedOutputFile.String())
Jiyong Park47e4fcb2019-02-05 22:33:10 +0900209 }
dimitryd95964a2018-11-07 13:43:34 +0100210 if len(library.Properties.Overrides) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800211 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " "))
dimitryd95964a2018-11-07 13:43:34 +0100212 }
Jiyong Parkf1194352019-02-25 11:05:47 +0900213 if len(library.post_install_cmds) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800214 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(library.post_install_cmds, "&& "))
Jiyong Parkf1194352019-02-25 11:05:47 +0900215 }
Colin Crossb60190a2018-09-04 16:28:17 -0700216 })
Dan Willemsend5781342017-02-15 16:15:21 -0800217 } else if library.header() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800218 entries.Class = "HEADER_LIBRARIES"
Dan Willemsend5781342017-02-15 16:15:21 -0800219 }
220
Colin Crossd80cbca2020-02-24 12:01:37 -0800221 entries.DistFile = library.distFile
222 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
223 library.androidMkWriteExportedFlags(entries)
224 library.androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries)
Dan Willemsen218f6562015-07-08 18:13:11 -0700225
Colin Crossd80cbca2020-02-24 12:01:37 -0800226 _, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base())
Logan Chien031d2b32018-07-26 00:19:50 +0800227
Colin Crossd80cbca2020-02-24 12:01:37 -0800228 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
Dan Willemsen218f6562015-07-08 18:13:11 -0700229
Dan Willemsen581341d2017-02-09 16:16:31 -0800230 if library.coverageOutputFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800231 entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", library.coverageOutputFile.String())
Dan Willemsen581341d2017-02-09 16:16:31 -0800232 }
Vic Yangefd249e2018-11-12 20:19:56 -0800233
234 if library.useCoreVariant {
Colin Crossd80cbca2020-02-24 12:01:37 -0800235 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
236 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
237 entries.SetBool("LOCAL_VNDK_DEPEND_ON_CORE_VARIANT", true)
Vic Yangefd249e2018-11-12 20:19:56 -0800238 }
Vic Yangd92090f2020-01-08 14:32:28 -0800239 if library.checkSameCoreVariant {
Colin Crossd80cbca2020-02-24 12:01:37 -0800240 entries.SetBool("LOCAL_CHECK_SAME_VNDK_VARIANTS", true)
Vic Yangd92090f2020-01-08 14:32:28 -0800241 }
Colin Crossca860ac2016-01-04 14:34:37 -0800242 })
Colin Crossb916a382016-07-29 17:28:03 -0700243
Jiyong Parkb0788572018-12-20 22:10:17 +0900244 if library.shared() && !library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800245 ctx.subAndroidMk(entries, library.baseInstaller)
Colin Crossb60190a2018-09-04 16:28:17 -0700246 } else {
Jooyung Hanad4c1872020-02-27 17:56:44 +0900247 if library.buildStubs() {
248 entries.SubName = "." + library.stubsVersion()
249 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800250 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
251 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Jiyong Parkb0788572018-12-20 22:10:17 +0900252 if library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800253 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
Jiyong Parkb0788572018-12-20 22:10:17 +0900254 }
Colin Crossb60190a2018-09-04 16:28:17 -0700255 })
Colin Crossb916a382016-07-29 17:28:03 -0700256 }
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000257 if len(library.Properties.Stubs.Versions) > 0 &&
Yifan Hong1b3348d2020-01-21 15:53:22 -0800258 android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() &&
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000259 !ctx.static() {
Jooyung Hanad4c1872020-02-27 17:56:44 +0900260 if library.buildStubs() && library.isLatestStubVersion() {
261 // reference the latest version via its name without suffix when it is provided by apex
262 entries.SubName = ""
263 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900264 if !library.buildStubs() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800265 entries.SubName = ".bootstrap"
Jiyong Parkb0788572018-12-20 22:10:17 +0900266 }
267 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700268}
269
Colin Crossd80cbca2020-02-24 12:01:37 -0800270func (object *objectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
271 entries.Class = "STATIC_LIBRARIES"
272 entries.ExtraFooters = append(entries.ExtraFooters,
273 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
274 out := entries.OutputFile.Path()
275 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
Dan Willemsen218f6562015-07-08 18:13:11 -0700276
Colin Crossd80cbca2020-02-24 12:01:37 -0800277 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
278 fmt.Fprintln(w, ".KATI_READONLY: "+varname)
279 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700280}
281
Colin Crossd80cbca2020-02-24 12:01:37 -0800282func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
283 ctx.subAndroidMk(entries, binary.baseInstaller)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700284
Colin Crossd80cbca2020-02-24 12:01:37 -0800285 entries.Class = "EXECUTABLES"
286 entries.DistFile = binary.distFile
287 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
288 entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile.String())
Colin Cross9b09f242016-12-07 13:37:42 -0800289 if len(binary.symlinks) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800290 entries.AddStrings("LOCAL_MODULE_SYMLINKS", binary.symlinks...)
Colin Cross9b09f242016-12-07 13:37:42 -0800291 }
292
Dan Willemsen581341d2017-02-09 16:16:31 -0800293 if binary.coverageOutputFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800294 entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", binary.coverageOutputFile.String())
Dan Willemsen581341d2017-02-09 16:16:31 -0800295 }
Yifan Hong946e32e2018-04-03 13:22:50 -0700296
297 if len(binary.Properties.Overrides) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800298 entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " "))
Yifan Hong946e32e2018-04-03 13:22:50 -0700299 }
Jiyong Parkf1194352019-02-25 11:05:47 +0900300 if len(binary.post_install_cmds) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800301 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(binary.post_install_cmds, "&& "))
Jiyong Parkf1194352019-02-25 11:05:47 +0900302 }
Colin Crossca860ac2016-01-04 14:34:37 -0800303 })
304}
305
Colin Crossd80cbca2020-02-24 12:01:37 -0800306func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
307 ctx.subAndroidMk(entries, benchmark.binaryDecorator)
308 entries.Class = "NATIVE_TESTS"
309 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
Colin Crosse28f4e22017-04-24 18:10:29 -0700310 if len(benchmark.Properties.Test_suites) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800311 entries.SetString("LOCAL_COMPATIBILITY_SUITE",
Colin Crosse28f4e22017-04-24 18:10:29 -0700312 strings.Join(benchmark.Properties.Test_suites, " "))
313 }
Colin Cross303e21f2018-08-07 16:49:25 -0700314 if benchmark.testConfig != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800315 entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700316 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800317 entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
Dan Shi2468d012020-01-06 15:47:57 -0800318 if !BoolDefault(benchmark.Properties.Auto_gen_config, true) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800319 entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
Dan Shi2468d012020-01-06 15:47:57 -0800320 }
Colin Crosse28f4e22017-04-24 18:10:29 -0700321 })
Anders Lewisb97e8182017-07-14 15:20:13 -0700322
Colin Crossd80cbca2020-02-24 12:01:37 -0800323 androidMkWriteTestData(benchmark.data, ctx, entries)
Colin Crossb916a382016-07-29 17:28:03 -0700324}
325
Colin Crossd80cbca2020-02-24 12:01:37 -0800326func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
327 ctx.subAndroidMk(entries, test.binaryDecorator)
328 entries.Class = "NATIVE_TESTS"
Colin Crossb916a382016-07-29 17:28:03 -0700329 if Bool(test.Properties.Test_per_src) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800330 entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
Colin Crossa2344662016-03-24 13:14:12 -0700331 }
Colin Crossd80cbca2020-02-24 12:01:37 -0800332 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
Colin Crossa929db02017-03-27 16:27:50 -0700333 if len(test.Properties.Test_suites) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800334 entries.SetString("LOCAL_COMPATIBILITY_SUITE",
Colin Crossa929db02017-03-27 16:27:50 -0700335 strings.Join(test.Properties.Test_suites, " "))
336 }
Colin Cross303e21f2018-08-07 16:49:25 -0700337 if test.testConfig != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800338 entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700339 }
Dan Shi2468d012020-01-06 15:47:57 -0800340 if !BoolDefault(test.Properties.Auto_gen_config, true) {
Colin Crossd80cbca2020-02-24 12:01:37 -0800341 entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
Dan Shi2468d012020-01-06 15:47:57 -0800342 }
Colin Crossa929db02017-03-27 16:27:50 -0700343 })
344
Colin Crossd80cbca2020-02-24 12:01:37 -0800345 androidMkWriteTestData(test.data, ctx, entries)
Colin Crossa2344662016-03-24 13:14:12 -0700346}
347
Colin Crossd80cbca2020-02-24 12:01:37 -0800348func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
349 ctx.subAndroidMk(entries, fuzz.binaryDecorator)
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700350
351 var fuzzFiles []string
352 for _, d := range fuzz.corpus {
Mitch Phillips8a2bc0b2019-10-17 15:04:01 -0700353 fuzzFiles = append(fuzzFiles,
354 filepath.Dir(fuzz.corpusIntermediateDir.String())+":corpus/"+d.Base())
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700355 }
356
Tri Voad172d82019-11-27 13:45:45 -0800357 for _, d := range fuzz.data {
358 fuzzFiles = append(fuzzFiles,
359 filepath.Dir(fuzz.dataIntermediateDir.String())+":data/"+d.Rel())
360 }
361
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700362 if fuzz.dictionary != nil {
Mitch Phillips8a2bc0b2019-10-17 15:04:01 -0700363 fuzzFiles = append(fuzzFiles,
364 filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base())
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700365 }
366
Kris Alderf979ee32019-10-22 10:52:01 -0700367 if fuzz.config != nil {
368 fuzzFiles = append(fuzzFiles,
369 filepath.Dir(fuzz.config.String())+":config.json")
370 }
371
Colin Crossd80cbca2020-02-24 12:01:37 -0800372 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
373 entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
Mitch Phillipse1ee1a12019-10-17 19:20:41 -0700374 if len(fuzzFiles) > 0 {
Colin Crossd80cbca2020-02-24 12:01:37 -0800375 entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
Mitch Phillipse1ee1a12019-10-17 19:20:41 -0700376 }
377 if fuzz.installedSharedDeps != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800378 entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
Mitch Phillipse1ee1a12019-10-17 19:20:41 -0700379 }
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -0700380 })
381}
382
Colin Crossd80cbca2020-02-24 12:01:37 -0800383func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
384 ctx.subAndroidMk(entries, test.libraryDecorator)
Colin Crossb916a382016-07-29 17:28:03 -0700385}
Dan Willemsene7932e82016-05-16 15:56:53 -0700386
Colin Crossd80cbca2020-02-24 12:01:37 -0800387func (library *toolchainLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
388 entries.Class = "STATIC_LIBRARIES"
389 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
390 _, suffix, _ := android.SplitFileExt(entries.OutputFile.Path().Base())
391 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700392 })
393}
394
Colin Crossd80cbca2020-02-24 12:01:37 -0800395func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Dan Willemsen03ce63e2016-09-29 12:17:49 -0700396 // Soong installation is only supported for host modules. Have Make
397 // installation trigger Soong installation.
398 if ctx.Target().Os.Class == android.Host {
Colin Crossd80cbca2020-02-24 12:01:37 -0800399 entries.OutputFile = android.OptionalPathForPath(installer.path)
Dan Willemsen03ce63e2016-09-29 12:17:49 -0700400 }
401
Colin Crossd80cbca2020-02-24 12:01:37 -0800402 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
Colin Crossff6c33d2019-10-02 16:01:35 -0700403 path, file := filepath.Split(installer.path.ToMakePath().String())
Ivan Lozano022a73b2019-09-09 20:29:31 -0700404 stem, suffix, _ := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800405 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
406 entries.SetString("LOCAL_MODULE_PATH", path)
407 entries.SetString("LOCAL_MODULE_STEM", stem)
Colin Crossa2344662016-03-24 13:14:12 -0700408 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700409}
Dan Albert914449f2016-06-17 16:45:24 -0700410
Colin Crossd80cbca2020-02-24 12:01:37 -0800411func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
412 entries.SubName = ndkLibrarySuffix + "." + c.properties.ApiLevel
413 entries.Class = "SHARED_LIBRARIES"
Dan Albert914449f2016-06-17 16:45:24 -0700414
Colin Crossd80cbca2020-02-24 12:01:37 -0800415 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
Colin Cross0875c522017-11-28 17:34:01 -0800416 path, file := filepath.Split(c.installPath.String())
Ivan Lozano022a73b2019-09-09 20:29:31 -0700417 stem, suffix, _ := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800418 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
419 entries.SetString("LOCAL_MODULE_PATH", path)
420 entries.SetString("LOCAL_MODULE_STEM", stem)
421 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
Dan Albert914449f2016-06-17 16:45:24 -0700422 })
423}
Dan Willemsenb916b802017-03-19 13:44:32 -0700424
Colin Crossd80cbca2020-02-24 12:01:37 -0800425func (c *llndkStubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
426 entries.Class = "SHARED_LIBRARIES"
Dan Willemsenb916b802017-03-19 13:44:32 -0700427
Colin Crossd80cbca2020-02-24 12:01:37 -0800428 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
429 c.libraryDecorator.androidMkWriteExportedFlags(entries)
430 _, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base())
Dan Willemsenb916b802017-03-19 13:44:32 -0700431
Colin Crossd80cbca2020-02-24 12:01:37 -0800432 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
433 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
434 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
435 entries.SetString("LOCAL_SOONG_TOC", c.toc().String())
Dan Willemsenb916b802017-03-19 13:44:32 -0700436 })
437}
Justin Yun71549282017-11-17 12:10:28 +0900438
Colin Crossd80cbca2020-02-24 12:01:37 -0800439func (c *vndkPrebuiltLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
440 entries.Class = "SHARED_LIBRARIES"
Justin Yun71549282017-11-17 12:10:28 +0900441
Colin Crossd80cbca2020-02-24 12:01:37 -0800442 entries.SubName = c.androidMkSuffix
Justin Yun71549282017-11-17 12:10:28 +0900443
Colin Crossd80cbca2020-02-24 12:01:37 -0800444 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
445 c.libraryDecorator.androidMkWriteExportedFlags(entries)
Justin Yun71549282017-11-17 12:10:28 +0900446
Colin Crossff6c33d2019-10-02 16:01:35 -0700447 path, file := filepath.Split(c.path.ToMakePath().String())
Ivan Lozano022a73b2019-09-09 20:29:31 -0700448 stem, suffix, ext := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800449 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
450 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
451 entries.SetString("LOCAL_MODULE_PATH", path)
452 entries.SetString("LOCAL_MODULE_STEM", stem)
Inseob Kimeec88e12020-01-22 11:11:29 +0900453 if c.tocFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800454 entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
Inseob Kimeec88e12020-01-22 11:11:29 +0900455 }
456 })
457}
458
Colin Crossd80cbca2020-02-24 12:01:37 -0800459func (c *vendorSnapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
Inseob Kimeec88e12020-01-22 11:11:29 +0900460 // Each vendor snapshot is exported to androidMk only when BOARD_VNDK_VERSION != current
461 // and the version of the prebuilt is same as BOARD_VNDK_VERSION.
462 if c.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800463 entries.Class = "SHARED_LIBRARIES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900464 } else if c.static() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800465 entries.Class = "STATIC_LIBRARIES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900466 } else if c.header() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800467 entries.Class = "HEADER_LIBRARIES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900468 }
469
470 if c.androidMkVendorSuffix {
Colin Crossd80cbca2020-02-24 12:01:37 -0800471 entries.SubName = vendorSuffix
Inseob Kimeec88e12020-01-22 11:11:29 +0900472 } else {
Colin Crossd80cbca2020-02-24 12:01:37 -0800473 entries.SubName = ""
Inseob Kimeec88e12020-01-22 11:11:29 +0900474 }
475
Colin Crossd80cbca2020-02-24 12:01:37 -0800476 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
477 c.libraryDecorator.androidMkWriteExportedFlags(entries)
Inseob Kimeec88e12020-01-22 11:11:29 +0900478
Inseob Kimc3b1a162020-02-18 12:42:54 +0900479 if c.shared() || c.static() {
Inseob Kimeec88e12020-01-22 11:11:29 +0900480 path, file := filepath.Split(c.path.ToMakePath().String())
481 stem, suffix, ext := android.SplitFileExt(file)
Colin Crossd80cbca2020-02-24 12:01:37 -0800482 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
483 entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
484 entries.SetString("LOCAL_MODULE_STEM", stem)
Inseob Kimeec88e12020-01-22 11:11:29 +0900485 if c.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800486 entries.SetString("LOCAL_MODULE_PATH", path)
Inseob Kimeec88e12020-01-22 11:11:29 +0900487 }
488 if c.tocFile.Valid() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800489 entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
Inseob Kimeec88e12020-01-22 11:11:29 +0900490 }
Inseob Kimc3b1a162020-02-18 12:42:54 +0900491 }
492
493 if !c.shared() { // static or header
Colin Crossd80cbca2020-02-24 12:01:37 -0800494 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
Inseob Kimeec88e12020-01-22 11:11:29 +0900495 }
496 })
497}
498
Colin Crossd80cbca2020-02-24 12:01:37 -0800499func (c *vendorSnapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
500 entries.Class = "EXECUTABLES"
Inseob Kimeec88e12020-01-22 11:11:29 +0900501
502 if c.androidMkVendorSuffix {
Colin Crossd80cbca2020-02-24 12:01:37 -0800503 entries.SubName = vendorSuffix
Inseob Kimeec88e12020-01-22 11:11:29 +0900504 } else {
Colin Crossd80cbca2020-02-24 12:01:37 -0800505 entries.SubName = ""
Inseob Kimeec88e12020-01-22 11:11:29 +0900506 }
507
Colin Crossd80cbca2020-02-24 12:01:37 -0800508 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
509 entries.AddStrings("LOCAL_MODULE_SYMLINKS", c.Properties.Symlinks...)
Justin Yun71549282017-11-17 12:10:28 +0900510 })
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800511}
Dan Albert8ba131b2017-12-14 13:23:15 -0800512
Colin Crossd80cbca2020-02-24 12:01:37 -0800513func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
514 entries.Class = "SHARED_LIBRARIES"
Dan Albert8ba131b2017-12-14 13:23:15 -0800515}
Jiyong Park374510b2018-03-19 18:23:01 +0900516
Colin Crossd80cbca2020-02-24 12:01:37 -0800517func (c *vendorPublicLibraryStubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
518 entries.Class = "SHARED_LIBRARIES"
519 entries.SubName = vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +0900520
Colin Crossd80cbca2020-02-24 12:01:37 -0800521 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
522 c.libraryDecorator.androidMkWriteExportedFlags(entries)
523 _, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base())
Jiyong Park374510b2018-03-19 18:23:01 +0900524
Colin Crossd80cbca2020-02-24 12:01:37 -0800525 entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
526 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
527 entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
Jiyong Park374510b2018-03-19 18:23:01 +0900528 })
529}
Logan Chien4fcea3d2018-11-20 11:59:08 +0800530
Colin Crossd80cbca2020-02-24 12:01:37 -0800531func (p *prebuiltLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
532 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
Logan Chien4fcea3d2018-11-20 11:59:08 +0800533 if p.properties.Check_elf_files != nil {
Colin Crossd80cbca2020-02-24 12:01:37 -0800534 entries.SetBool("LOCAL_CHECK_ELF_FILES", *p.properties.Check_elf_files)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800535 } else {
536 // soong_cc_prebuilt.mk does not include check_elf_file.mk by default
537 // because cc_library_shared and cc_binary use soong_cc_prebuilt.mk as well.
538 // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to
539 // true if `p.properties.Check_elf_files` is not specified.
Colin Crossd80cbca2020-02-24 12:01:37 -0800540 entries.SetBool("LOCAL_CHECK_ELF_FILES", true)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800541 }
542 })
543}
544
Colin Crossd80cbca2020-02-24 12:01:37 -0800545func (p *prebuiltLibraryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
546 ctx.subAndroidMk(entries, p.libraryDecorator)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800547 if p.shared() {
Colin Crossd80cbca2020-02-24 12:01:37 -0800548 ctx.subAndroidMk(entries, &p.prebuiltLinker)
549 androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800550 }
551}
552
Colin Crossd80cbca2020-02-24 12:01:37 -0800553func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
554 ctx.subAndroidMk(entries, p.binaryDecorator)
555 ctx.subAndroidMk(entries, &p.prebuiltLinker)
556 androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
Logan Chien4fcea3d2018-11-20 11:59:08 +0800557}
558
Colin Crossd80cbca2020-02-24 12:01:37 -0800559func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, entries *android.AndroidMkEntries) {
560 allow := linker.Properties.Allow_undefined_symbols
561 if allow != nil {
562 entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
563 entries.SetBool("LOCAL_ALLOW_UNDEFINED_SYMBOLS", *allow)
564 })
565 }
Logan Chien4fcea3d2018-11-20 11:59:08 +0800566}