• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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 (
18	"github.com/google/blueprint/proptools"
19
20	"fmt"
21	"io"
22	"path/filepath"
23	"strings"
24
25	"android/soong/android"
26)
27
28var (
29	NativeBridgeSuffix  = ".native_bridge"
30	ProductSuffix       = ".product"
31	VendorSuffix        = ".vendor"
32	RamdiskSuffix       = ".ramdisk"
33	VendorRamdiskSuffix = ".vendor_ramdisk"
34	RecoverySuffix      = ".recovery"
35	sdkSuffix           = ".sdk"
36)
37
38type AndroidMkContext interface {
39	BaseModuleName() string
40	Target() android.Target
41	subAndroidMk(*android.AndroidMkEntries, interface{})
42	Arch() android.Arch
43	Os() android.OsType
44	Host() bool
45	UseVndk() bool
46	VndkVersion() string
47	static() bool
48	InRamdisk() bool
49	InVendorRamdisk() bool
50	InRecovery() bool
51	NotInPlatform() bool
52}
53
54type subAndroidMkProvider interface {
55	AndroidMkEntries(AndroidMkContext, *android.AndroidMkEntries)
56}
57
58func (c *Module) subAndroidMk(entries *android.AndroidMkEntries, obj interface{}) {
59	if c.subAndroidMkOnce == nil {
60		c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
61	}
62	if androidmk, ok := obj.(subAndroidMkProvider); ok {
63		if !c.subAndroidMkOnce[androidmk] {
64			c.subAndroidMkOnce[androidmk] = true
65			androidmk.AndroidMkEntries(c, entries)
66		}
67	}
68}
69
70func (c *Module) AndroidMkEntries() []android.AndroidMkEntries {
71	if c.hideApexVariantFromMake || c.Properties.HideFromMake {
72		return []android.AndroidMkEntries{{
73			Disabled: true,
74		}}
75	}
76
77	entries := android.AndroidMkEntries{
78		OutputFile: c.outputFile,
79		// TODO(jiyong): add the APEXes providing shared libs to the required
80		// modules Currently, adding c.Properties.ApexesProvidingSharedLibs is
81		// causing multiple ART APEXes (com.android.art and com.android.art.debug)
82		// to be installed. And this is breaking some older devices (like marlin)
83		// where system.img is small.
84		Required: c.Properties.AndroidMkRuntimeLibs,
85		Include:  "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
86
87		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
88			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
89				if len(c.Properties.Logtags) > 0 {
90					entries.AddStrings("LOCAL_LOGTAGS_FILES", c.Properties.Logtags...)
91				}
92				// Note: Pass the exact value of AndroidMkSystemSharedLibs to the Make
93				// world, even if it is an empty list. In the Make world,
94				// LOCAL_SYSTEM_SHARED_LIBRARIES defaults to "none", which is expanded
95				// to the default list of system shared libs by the build system.
96				// Soong computes the exact list of system shared libs, so we have to
97				// override the default value when the list of libs is actually empty.
98				entries.SetString("LOCAL_SYSTEM_SHARED_LIBRARIES", strings.Join(c.Properties.AndroidMkSystemSharedLibs, " "))
99				if len(c.Properties.AndroidMkSharedLibs) > 0 {
100					entries.AddStrings("LOCAL_SHARED_LIBRARIES", c.Properties.AndroidMkSharedLibs...)
101				}
102				if len(c.Properties.AndroidMkStaticLibs) > 0 {
103					entries.AddStrings("LOCAL_STATIC_LIBRARIES", c.Properties.AndroidMkStaticLibs...)
104				}
105				if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
106					entries.AddStrings("LOCAL_WHOLE_STATIC_LIBRARIES", c.Properties.AndroidMkWholeStaticLibs...)
107				}
108				if len(c.Properties.AndroidMkHeaderLibs) > 0 {
109					entries.AddStrings("LOCAL_HEADER_LIBRARIES", c.Properties.AndroidMkHeaderLibs...)
110				}
111				if len(c.Properties.AndroidMkRuntimeLibs) > 0 {
112					entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...)
113				}
114				entries.SetString("LOCAL_SOONG_LINK_TYPE", c.makeLinkType)
115				if c.UseVndk() {
116					entries.SetBool("LOCAL_USE_VNDK", true)
117					if c.IsVndk() && !c.static() {
118						entries.SetString("LOCAL_SOONG_VNDK_VERSION", c.VndkVersion())
119						// VNDK libraries available to vendor are not installed because
120						// they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
121						if !c.IsVndkExt() {
122							entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
123						}
124					}
125				}
126				if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
127					// Make the SDK variant uninstallable so that there are not two rules to install
128					// to the same location.
129					entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
130					// Add the unsuffixed name to SOONG_SDK_VARIANT_MODULES so that Make can rewrite
131					// dependencies to the .sdk suffix when building a module that uses the SDK.
132					entries.SetString("SOONG_SDK_VARIANT_MODULES",
133						"$(SOONG_SDK_VARIANT_MODULES) $(patsubst %.sdk,%,$(LOCAL_MODULE))")
134				}
135			},
136		},
137		ExtraFooters: []android.AndroidMkExtraFootersFunc{
138			func(w io.Writer, name, prefix, moduleDir string) {
139				if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake &&
140					c.CcLibraryInterface() && c.Shared() {
141					// Using the SDK variant as a JNI library needs a copy of the .so that
142					// is not named .sdk.so so that it can be packaged into the APK with
143					// the right name.
144					fmt.Fprintln(w, "$(eval $(call copy-one-file,",
145						"$(LOCAL_BUILT_MODULE),",
146						"$(patsubst %.sdk.so,%.so,$(LOCAL_BUILT_MODULE))))")
147				}
148			},
149		},
150	}
151
152	for _, feature := range c.features {
153		c.subAndroidMk(&entries, feature)
154	}
155
156	c.subAndroidMk(&entries, c.compiler)
157	c.subAndroidMk(&entries, c.linker)
158	if c.sanitize != nil {
159		c.subAndroidMk(&entries, c.sanitize)
160	}
161	c.subAndroidMk(&entries, c.installer)
162
163	entries.SubName += c.Properties.SubName
164
165	return []android.AndroidMkEntries{entries}
166}
167
168func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *android.AndroidMkEntries) {
169	if len(extraTestConfigs) > 0 {
170		entries.ExtraEntries = append(entries.ExtraEntries,
171			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
172				entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", extraTestConfigs.Strings()...)
173			})
174	}
175}
176
177func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) {
178	testFiles := android.AndroidMkDataPaths(data)
179	if len(testFiles) > 0 {
180		entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
181			entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
182		})
183	}
184}
185
186func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
187	if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
188		var result []string
189		for _, override := range overrides {
190			result = append(result, override+NativeBridgeSuffix)
191		}
192		return result
193	}
194
195	return overrides
196}
197
198func (library *libraryDecorator) androidMkWriteExportedFlags(entries *android.AndroidMkEntries) {
199	var exportedFlags []string
200	var includeDirs android.Paths
201	var systemIncludeDirs android.Paths
202	var exportedDeps android.Paths
203
204	if library.flagExporterInfo != nil {
205		exportedFlags = library.flagExporterInfo.Flags
206		includeDirs = library.flagExporterInfo.IncludeDirs
207		systemIncludeDirs = library.flagExporterInfo.SystemIncludeDirs
208		exportedDeps = library.flagExporterInfo.Deps
209	} else {
210		exportedFlags = library.flagExporter.flags
211		includeDirs = library.flagExporter.dirs
212		systemIncludeDirs = library.flagExporter.systemDirs
213		exportedDeps = library.flagExporter.deps
214	}
215	for _, dir := range includeDirs {
216		exportedFlags = append(exportedFlags, "-I"+dir.String())
217	}
218	for _, dir := range systemIncludeDirs {
219		exportedFlags = append(exportedFlags, "-isystem "+dir.String())
220	}
221	if len(exportedFlags) > 0 {
222		entries.AddStrings("LOCAL_EXPORT_CFLAGS", exportedFlags...)
223	}
224	if len(exportedDeps) > 0 {
225		entries.AddStrings("LOCAL_EXPORT_C_INCLUDE_DEPS", exportedDeps.Strings()...)
226	}
227}
228
229func (library *libraryDecorator) androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries *android.AndroidMkEntries) {
230	if library.sAbiDiff.Valid() && !library.static() {
231		entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", library.sAbiDiff.String())
232	}
233}
234
235// TODO(ccross): remove this once apex/androidmk.go is converted to AndroidMkEntries
236func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
237	if library.sAbiDiff.Valid() && !library.static() {
238		fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", library.sAbiDiff.String())
239	}
240}
241
242func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
243	if library.static() {
244		entries.Class = "STATIC_LIBRARIES"
245	} else if library.shared() {
246		entries.Class = "SHARED_LIBRARIES"
247		entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
248			entries.SetString("LOCAL_SOONG_TOC", library.toc().String())
249			if !library.buildStubs() && library.unstrippedOutputFile != nil {
250				entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", library.unstrippedOutputFile.String())
251			}
252			if len(library.Properties.Overrides) > 0 {
253				entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " "))
254			}
255			if len(library.postInstallCmds) > 0 {
256				entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(library.postInstallCmds, "&& "))
257			}
258		})
259	} else if library.header() {
260		entries.Class = "HEADER_LIBRARIES"
261	}
262
263	if library.distFile != nil {
264		entries.DistFiles = android.MakeDefaultDistFiles(library.distFile)
265	}
266
267	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
268		library.androidMkWriteExportedFlags(entries)
269		library.androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries)
270
271		if entries.OutputFile.Valid() {
272			_, _, ext := android.SplitFileExt(entries.OutputFile.Path().Base())
273			entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
274		}
275
276		if library.coverageOutputFile.Valid() {
277			entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", library.coverageOutputFile.String())
278		}
279
280		if library.useCoreVariant {
281			entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
282			entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
283			entries.SetBool("LOCAL_VNDK_DEPEND_ON_CORE_VARIANT", true)
284		}
285		if library.checkSameCoreVariant {
286			entries.SetBool("LOCAL_CHECK_SAME_VNDK_VARIANTS", true)
287		}
288	})
289
290	if library.shared() && !library.buildStubs() {
291		ctx.subAndroidMk(entries, library.baseInstaller)
292	} else {
293		if library.buildStubs() && library.stubsVersion() != "" {
294			entries.SubName = "." + library.stubsVersion()
295		}
296		entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
297			// library.makeUninstallable() depends on this to bypass HideFromMake() for
298			// static libraries.
299			entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
300			if library.buildStubs() {
301				entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
302			}
303		})
304	}
305	// If a library providing a stub is included in an APEX, the private APIs of the library
306	// is accessible only inside the APEX. From outside of the APEX, clients can only use the
307	// public APIs via the stub. To enforce this, the (latest version of the) stub gets the
308	// name of the library. The impl library instead gets the `.bootstrap` suffix to so that
309	// they can be exceptionally used directly when APEXes are not available (e.g. during the
310	// very early stage in the boot process).
311	if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.NotInPlatform() &&
312		!ctx.InRamdisk() && !ctx.InVendorRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.static() {
313		if library.buildStubs() && library.isLatestStubVersion() {
314			entries.SubName = ""
315		}
316		if !library.buildStubs() {
317			entries.SubName = ".bootstrap"
318		}
319	}
320}
321
322func (object *objectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
323	entries.Class = "STATIC_LIBRARIES"
324	entries.ExtraFooters = append(entries.ExtraFooters,
325		func(w io.Writer, name, prefix, moduleDir string) {
326			out := entries.OutputFile.Path()
327			varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
328
329			fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
330			fmt.Fprintln(w, ".KATI_READONLY: "+varname)
331		})
332}
333
334func (test *testDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
335	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
336		if len(test.InstallerProperties.Test_suites) > 0 {
337			entries.AddCompatibilityTestSuites(test.InstallerProperties.Test_suites...)
338		}
339	})
340}
341
342func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
343	ctx.subAndroidMk(entries, binary.baseInstaller)
344
345	entries.Class = "EXECUTABLES"
346	entries.DistFiles = binary.distFiles
347	entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
348		entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile.String())
349		if len(binary.symlinks) > 0 {
350			entries.AddStrings("LOCAL_MODULE_SYMLINKS", binary.symlinks...)
351		}
352
353		if binary.coverageOutputFile.Valid() {
354			entries.SetString("LOCAL_PREBUILT_COVERAGE_ARCHIVE", binary.coverageOutputFile.String())
355		}
356
357		if len(binary.Properties.Overrides) > 0 {
358			entries.SetString("LOCAL_OVERRIDES_MODULES", strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " "))
359		}
360		if len(binary.postInstallCmds) > 0 {
361			entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(binary.postInstallCmds, "&& "))
362		}
363	})
364}
365
366func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
367	ctx.subAndroidMk(entries, benchmark.binaryDecorator)
368	entries.Class = "NATIVE_TESTS"
369	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
370		if len(benchmark.Properties.Test_suites) > 0 {
371			entries.AddCompatibilityTestSuites(benchmark.Properties.Test_suites...)
372		}
373		if benchmark.testConfig != nil {
374			entries.SetString("LOCAL_FULL_TEST_CONFIG", benchmark.testConfig.String())
375		}
376		entries.SetBool("LOCAL_NATIVE_BENCHMARK", true)
377		if !BoolDefault(benchmark.Properties.Auto_gen_config, true) {
378			entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
379		}
380	})
381	dataPaths := []android.DataPath{}
382	for _, srcPath := range benchmark.data {
383		dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
384	}
385	AndroidMkWriteTestData(dataPaths, entries)
386}
387
388func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
389	ctx.subAndroidMk(entries, test.binaryDecorator)
390	ctx.subAndroidMk(entries, test.testDecorator)
391
392	entries.Class = "NATIVE_TESTS"
393	if Bool(test.Properties.Test_per_src) {
394		entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
395	}
396	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
397		if test.testConfig != nil {
398			entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
399		}
400		if !BoolDefault(test.Properties.Auto_gen_config, true) {
401			entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
402		}
403		entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...)
404		if Bool(test.Properties.Test_options.Unit_test) {
405			entries.SetBool("LOCAL_IS_UNIT_TEST", true)
406		}
407
408		entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory))
409		if len(test.Properties.Data_bins) > 0 {
410			entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
411		}
412	})
413
414	AndroidMkWriteTestData(test.data, entries)
415	androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
416}
417
418func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
419	ctx.subAndroidMk(entries, fuzz.binaryDecorator)
420
421	var fuzzFiles []string
422	for _, d := range fuzz.fuzzPackagedModule.Corpus {
423		fuzzFiles = append(fuzzFiles,
424			filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
425	}
426
427	for _, d := range fuzz.fuzzPackagedModule.Data {
428		fuzzFiles = append(fuzzFiles,
429			filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
430	}
431
432	if fuzz.fuzzPackagedModule.Dictionary != nil {
433		fuzzFiles = append(fuzzFiles,
434			filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
435	}
436
437	if fuzz.fuzzPackagedModule.Config != nil {
438		fuzzFiles = append(fuzzFiles,
439			filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
440	}
441
442	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
443		entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
444		if len(fuzzFiles) > 0 {
445			entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
446		}
447		if fuzz.installedSharedDeps != nil {
448			entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
449		}
450	})
451}
452
453func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
454	ctx.subAndroidMk(entries, test.libraryDecorator)
455	ctx.subAndroidMk(entries, test.testDecorator)
456}
457
458func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
459	if installer.path == (android.InstallPath{}) {
460		return
461	}
462
463	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
464		path, file := filepath.Split(installer.path.String())
465		stem, suffix, _ := android.SplitFileExt(file)
466		entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
467		entries.SetString("LOCAL_MODULE_PATH", path)
468		entries.SetString("LOCAL_MODULE_STEM", stem)
469	})
470}
471
472func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
473	entries.SubName = ndkLibrarySuffix + "." + c.apiLevel.String()
474	entries.Class = "SHARED_LIBRARIES"
475
476	if !c.buildStubs() {
477		entries.Disabled = true
478		return
479	}
480
481	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
482		path, file := filepath.Split(c.installPath.String())
483		stem, suffix, _ := android.SplitFileExt(file)
484		entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
485		entries.SetString("LOCAL_MODULE_PATH", path)
486		entries.SetString("LOCAL_MODULE_STEM", stem)
487		entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
488		if c.parsedCoverageXmlPath.String() != "" {
489			entries.SetString("SOONG_NDK_API_XML", "$(SOONG_NDK_API_XML) "+c.parsedCoverageXmlPath.String())
490		}
491	})
492}
493
494func (c *vndkPrebuiltLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
495	entries.Class = "SHARED_LIBRARIES"
496
497	entries.SubName = c.androidMkSuffix
498
499	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
500		c.libraryDecorator.androidMkWriteExportedFlags(entries)
501
502		// Specifying stem is to pass check_elf_files when vendor modules link against vndk prebuilt.
503		// We can't use install path because VNDKs are not installed. Instead, Srcs is directly used.
504		_, file := filepath.Split(c.properties.Srcs[0])
505		stem, suffix, ext := android.SplitFileExt(file)
506		entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
507		entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
508		entries.SetString("LOCAL_MODULE_STEM", stem)
509
510		if c.tocFile.Valid() {
511			entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
512		}
513
514		// VNDK libraries available to vendor are not installed because
515		// they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
516		entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
517	})
518}
519
520func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
521	// Each vendor snapshot is exported to androidMk only when BOARD_VNDK_VERSION != current
522	// and the version of the prebuilt is same as BOARD_VNDK_VERSION.
523	if c.shared() {
524		entries.Class = "SHARED_LIBRARIES"
525	} else if c.static() {
526		entries.Class = "STATIC_LIBRARIES"
527	} else if c.header() {
528		entries.Class = "HEADER_LIBRARIES"
529	}
530
531	entries.SubName = ""
532
533	if c.sanitizerProperties.CfiEnabled {
534		entries.SubName += ".cfi"
535	}
536
537	entries.SubName += c.baseProperties.Androidmk_suffix
538
539	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
540		c.libraryDecorator.androidMkWriteExportedFlags(entries)
541
542		if c.shared() || c.static() {
543			src := c.path.String()
544			// For static libraries which aren't installed, directly use Src to extract filename.
545			// This is safe: generated snapshot modules have a real path as Src, not a module
546			if c.static() {
547				src = proptools.String(c.properties.Src)
548			}
549			path, file := filepath.Split(src)
550			stem, suffix, ext := android.SplitFileExt(file)
551			entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext)
552			entries.SetString("LOCAL_MODULE_SUFFIX", suffix)
553			entries.SetString("LOCAL_MODULE_STEM", stem)
554			if c.shared() {
555				entries.SetString("LOCAL_MODULE_PATH", path)
556			}
557			if c.tocFile.Valid() {
558				entries.SetString("LOCAL_SOONG_TOC", c.tocFile.String())
559			}
560		}
561
562		if !c.shared() { // static or header
563			entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
564		}
565	})
566}
567
568func (c *snapshotBinaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
569	entries.Class = "EXECUTABLES"
570	entries.SubName = c.baseProperties.Androidmk_suffix
571}
572
573func (c *snapshotObjectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
574	entries.Class = "STATIC_LIBRARIES"
575	entries.SubName = c.baseProperties.Androidmk_suffix
576
577	entries.ExtraFooters = append(entries.ExtraFooters,
578		func(w io.Writer, name, prefix, moduleDir string) {
579			out := entries.OutputFile.Path()
580			varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, entries.SubName)
581
582			fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
583			fmt.Fprintln(w, ".KATI_READONLY: "+varname)
584		})
585}
586
587func (c *ndkPrebuiltStlLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
588	entries.Class = "SHARED_LIBRARIES"
589}
590
591func (p *prebuiltLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
592	entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
593		if p.properties.Check_elf_files != nil {
594			entries.SetBool("LOCAL_CHECK_ELF_FILES", *p.properties.Check_elf_files)
595		} else {
596			// soong_cc_rust_prebuilt.mk does not include check_elf_file.mk by default
597			// because cc_library_shared and cc_binary use soong_cc_rust_prebuilt.mk as well.
598			// In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to
599			// true if `p.properties.Check_elf_files` is not specified.
600			entries.SetBool("LOCAL_CHECK_ELF_FILES", true)
601		}
602	})
603}
604
605func (p *prebuiltLibraryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
606	ctx.subAndroidMk(entries, p.libraryDecorator)
607	if p.shared() {
608		ctx.subAndroidMk(entries, &p.prebuiltLinker)
609		androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
610	}
611}
612
613func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
614	ctx.subAndroidMk(entries, p.binaryDecorator)
615	ctx.subAndroidMk(entries, &p.prebuiltLinker)
616	androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
617}
618
619func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, entries *android.AndroidMkEntries) {
620	allow := linker.Properties.Allow_undefined_symbols
621	if allow != nil {
622		entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
623			entries.SetBool("LOCAL_ALLOW_UNDEFINED_SYMBOLS", *allow)
624		})
625	}
626}
627