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