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