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