blob: 0e4245ef09d861dbe1a571c85afb63a04d37f5ce [file] [log] [blame]
Dan Willemsen218f6562015-07-08 18:13:11 -07001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Dan Willemsen97750522016-02-09 17:43:51 -080018 "fmt"
Dan Willemsen218f6562015-07-08 18:13:11 -070019 "io"
Colin Crossa2344662016-03-24 13:14:12 -070020 "path/filepath"
Dan Willemsen218f6562015-07-08 18:13:11 -070021 "strings"
22
Colin Cross635c3b02016-05-18 15:37:25 -070023 "android/soong/android"
Dan Willemsen218f6562015-07-08 18:13:11 -070024)
25
Jiyong Park27b188b2017-07-18 13:23:39 +090026var (
Jiyong Parkf9332f12018-02-01 00:54:12 +090027 vendorSuffix = ".vendor"
28 recoverySuffix = ".recovery"
Jiyong Park27b188b2017-07-18 13:23:39 +090029)
30
Dan Willemsenf2c27d72016-07-13 16:50:22 -070031type AndroidMkContext interface {
Jiyong Parkb0788572018-12-20 22:10:17 +090032 Name() string
Dan Willemsenf2c27d72016-07-13 16:50:22 -070033 Target() android.Target
Colin Crossb916a382016-07-29 17:28:03 -070034 subAndroidMk(*android.AndroidMkData, interface{})
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +000035 Arch() android.Arch
36 Os() android.OsType
37 Host() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070038 useVndk() bool
Jiyong Parkb0788572018-12-20 22:10:17 +090039 static() bool
40 inRecovery() bool
Colin Crossb916a382016-07-29 17:28:03 -070041}
42
43type subAndroidMkProvider interface {
44 AndroidMk(AndroidMkContext, *android.AndroidMkData)
45}
46
47func (c *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
48 if c.subAndroidMkOnce == nil {
49 c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
50 }
51 if androidmk, ok := obj.(subAndroidMkProvider); ok {
52 if !c.subAndroidMkOnce[androidmk] {
53 c.subAndroidMkOnce[androidmk] = true
54 androidmk.AndroidMk(c, data)
55 }
56 }
Dan Willemsenf2c27d72016-07-13 16:50:22 -070057}
58
Colin Crossa18e9cf2017-08-10 17:00:19 -070059func (c *Module) AndroidMk() android.AndroidMkData {
Jiyong Park9d452992018-10-03 00:38:19 +090060 if c.Properties.HideFromMake || !c.IsForPlatform() {
Colin Crossa18e9cf2017-08-10 17:00:19 -070061 return android.AndroidMkData{
62 Disabled: true,
63 }
Colin Crossbc6fb162016-05-24 15:39:04 -070064 }
65
Colin Crossa18e9cf2017-08-10 17:00:19 -070066 ret := android.AndroidMkData{
67 OutputFile: c.outputFile,
Jiyong Parkb0788572018-12-20 22:10:17 +090068 // TODO(jiyong): add the APEXes providing shared libs to the required modules
69 // Currently, adding c.Properties.ApexesProvidingSharedLibs is causing multiple
70 // runtime APEXes (com.android.runtime.debug|release) to be installed. And this
71 // is breaking some older devices (like marlin) where system.img is small.
72 Required: c.Properties.AndroidMkRuntimeLibs,
73 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Logan Chien43d34c32017-12-20 01:17:32 +080074
Colin Crossa18e9cf2017-08-10 17:00:19 -070075 Extra: []android.AndroidMkExtraFunc{
76 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080077 if len(c.Properties.Logtags) > 0 {
78 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(c.Properties.Logtags, " "))
79 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070080 if len(c.Properties.AndroidMkSharedLibs) > 0 {
81 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
82 }
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +000083 if len(c.Properties.AndroidMkStaticLibs) > 0 {
84 fmt.Fprintln(w, "LOCAL_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkStaticLibs, " "))
85 }
86 if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
87 fmt.Fprintln(w, "LOCAL_WHOLE_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkWholeStaticLibs, " "))
88 }
Colin Crossb60190a2018-09-04 16:28:17 -070089 fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.getMakeLinkType())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070090 if c.useVndk() {
Colin Crossa18e9cf2017-08-10 17:00:19 -070091 fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
92 }
93 },
94 },
95 }
Colin Crossca860ac2016-01-04 14:34:37 -080096
Colin Crossca860ac2016-01-04 14:34:37 -080097 for _, feature := range c.features {
Colin Crossb916a382016-07-29 17:28:03 -070098 c.subAndroidMk(&ret, feature)
Colin Crossca860ac2016-01-04 14:34:37 -080099 }
100
Colin Crossb916a382016-07-29 17:28:03 -0700101 c.subAndroidMk(&ret, c.compiler)
102 c.subAndroidMk(&ret, c.linker)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700103 if c.sanitize != nil {
104 c.subAndroidMk(&ret, c.sanitize)
105 }
Colin Crossb916a382016-07-29 17:28:03 -0700106 c.subAndroidMk(&ret, c.installer)
Colin Crossca860ac2016-01-04 14:34:37 -0800107
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700108 if c.useVndk() && c.hasVendorVariant() {
Jiyong Park27b188b2017-07-18 13:23:39 +0900109 // .vendor suffix is added only when we will have two variants: core and vendor.
110 // The suffix is not added for vendor-only module.
111 ret.SubName += vendorSuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +0900112 } else if c.inRecovery() && !c.onlyInRecovery() {
113 ret.SubName += recoverySuffix
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700114 }
115
Colin Crossa18e9cf2017-08-10 17:00:19 -0700116 return ret
Colin Crossca860ac2016-01-04 14:34:37 -0800117}
118
Anders Lewisb97e8182017-07-14 15:20:13 -0700119func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, ret *android.AndroidMkData) {
120 var testFiles []string
121 for _, d := range data {
122 rel := d.Rel()
123 path := d.String()
124 if !strings.HasSuffix(path, rel) {
125 panic(fmt.Errorf("path %q does not end with %q", path, rel))
126 }
127 path = strings.TrimSuffix(path, rel)
128 testFiles = append(testFiles, path+":"+rel)
129 }
130 if len(testFiles) > 0 {
Colin Cross27a4b052017-08-10 16:32:23 -0700131 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Anders Lewisb97e8182017-07-14 15:20:13 -0700132 fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(testFiles, " "))
Anders Lewisb97e8182017-07-14 15:20:13 -0700133 })
134 }
135}
136
Dan Willemsen58539402017-03-19 13:44:32 -0700137func (library *libraryDecorator) androidMkWriteExportedFlags(w io.Writer) {
138 exportedFlags := library.exportedFlags()
139 if len(exportedFlags) > 0 {
140 fmt.Fprintln(w, "LOCAL_EXPORT_CFLAGS :=", strings.Join(exportedFlags, " "))
Dan Willemsend5781342017-02-15 16:15:21 -0800141 }
Dan Willemsen58539402017-03-19 13:44:32 -0700142 exportedFlagsDeps := library.exportedFlagsDeps()
143 if len(exportedFlagsDeps) > 0 {
144 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DEPS :=", strings.Join(exportedFlagsDeps.Strings(), " "))
145 }
146}
Dan Willemsend5781342017-02-15 16:15:21 -0800147
Dan Willemsen58539402017-03-19 13:44:32 -0700148func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Dan Willemsend5781342017-02-15 16:15:21 -0800149 if library.static() {
150 ret.Class = "STATIC_LIBRARIES"
151 } else if library.shared() {
Dan Willemsend5781342017-02-15 16:15:21 -0800152 ret.Class = "SHARED_LIBRARIES"
Colin Crossb60190a2018-09-04 16:28:17 -0700153 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
154 fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", library.toc().String())
155 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String())
dimitryd95964a2018-11-07 13:43:34 +0100156 if len(library.Properties.Overrides) > 0 {
157 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES := "+strings.Join(library.Properties.Overrides, " "))
158 }
Colin Crossb60190a2018-09-04 16:28:17 -0700159 })
Dan Willemsend5781342017-02-15 16:15:21 -0800160 } else if library.header() {
Colin Crossb60190a2018-09-04 16:28:17 -0700161 ret.Class = "HEADER_LIBRARIES"
Dan Willemsend5781342017-02-15 16:15:21 -0800162 }
163
Dan Willemsen569edc52018-11-19 09:33:29 -0800164 ret.DistFile = library.distFile
Colin Cross27a4b052017-08-10 16:32:23 -0700165 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Dan Willemsen58539402017-03-19 13:44:32 -0700166 library.androidMkWriteExportedFlags(w)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800167 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES := ")
168 if library.sAbiOutputFile.Valid() {
169 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES += ", library.sAbiOutputFile.String())
170 if library.sAbiDiff.Valid() && !library.static() {
171 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES += ", library.sAbiDiff.String())
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700172 fmt.Fprintln(w, "HEADER_ABI_DIFFS += ", library.sAbiDiff.String())
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800173 }
174 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700175
Logan Chien031d2b32018-07-26 00:19:50 +0800176 _, _, ext := splitFileExt(outputFile.Base())
177
178 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
Dan Willemsen218f6562015-07-08 18:13:11 -0700179
Dan Willemsen581341d2017-02-09 16:16:31 -0800180 if library.coverageOutputFile.Valid() {
181 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String())
182 }
Colin Crossca860ac2016-01-04 14:34:37 -0800183 })
Colin Crossb916a382016-07-29 17:28:03 -0700184
Jiyong Parkb0788572018-12-20 22:10:17 +0900185 if library.shared() && !library.buildStubs() {
Colin Crossb916a382016-07-29 17:28:03 -0700186 ctx.subAndroidMk(ret, library.baseInstaller)
Colin Crossb60190a2018-09-04 16:28:17 -0700187 } else {
188 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
189 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Jiyong Parkb0788572018-12-20 22:10:17 +0900190 if library.buildStubs() {
191 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
192 }
Colin Crossb60190a2018-09-04 16:28:17 -0700193 })
Colin Crossb916a382016-07-29 17:28:03 -0700194 }
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000195 if len(library.Properties.Stubs.Versions) > 0 &&
196 android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.inRecovery() && !ctx.useVndk() &&
197 !ctx.static() {
Jiyong Parkb0788572018-12-20 22:10:17 +0900198 if !library.buildStubs() {
199 ret.SubName = ".bootstrap"
200 }
201 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700202}
203
Dan Willemsenf2c27d72016-07-13 16:50:22 -0700204func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Colin Cross0f86d182017-08-10 17:07:28 -0700205 ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Colin Crossca860ac2016-01-04 14:34:37 -0800206 out := ret.OutputFile.Path()
Dan Willemsen2e224ca2018-09-06 00:26:20 -0700207 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, data.SubName)
Dan Willemsen218f6562015-07-08 18:13:11 -0700208
Dan Willemsen2e224ca2018-09-06 00:26:20 -0700209 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
210 fmt.Fprintln(w, ".KATI_READONLY: "+varname)
Dan Willemsen218f6562015-07-08 18:13:11 -0700211 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700212}
213
Colin Crossb916a382016-07-29 17:28:03 -0700214func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Colin Cross1e7d3702016-08-24 15:25:47 -0700215 ctx.subAndroidMk(ret, binary.baseInstaller)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700216
Dan Willemsen218f6562015-07-08 18:13:11 -0700217 ret.Class = "EXECUTABLES"
Dan Willemsen569edc52018-11-19 09:33:29 -0800218 ret.DistFile = binary.distFile
Colin Cross27a4b052017-08-10 16:32:23 -0700219 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossb60190a2018-09-04 16:28:17 -0700220 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String())
Colin Cross9b09f242016-12-07 13:37:42 -0800221 if len(binary.symlinks) > 0 {
222 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
223 }
224
Dan Willemsen581341d2017-02-09 16:16:31 -0800225 if binary.coverageOutputFile.Valid() {
226 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String())
227 }
Yifan Hong946e32e2018-04-03 13:22:50 -0700228
229 if len(binary.Properties.Overrides) > 0 {
230 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES := "+strings.Join(binary.Properties.Overrides, " "))
231 }
Colin Crossca860ac2016-01-04 14:34:37 -0800232 })
233}
234
Colin Crossb916a382016-07-29 17:28:03 -0700235func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
236 ctx.subAndroidMk(ret, benchmark.binaryDecorator)
Dan Willemsen58a5c8b2017-05-23 15:10:37 -0700237 ret.Class = "NATIVE_TESTS"
Colin Cross27a4b052017-08-10 16:32:23 -0700238 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crosse28f4e22017-04-24 18:10:29 -0700239 if len(benchmark.Properties.Test_suites) > 0 {
240 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
241 strings.Join(benchmark.Properties.Test_suites, " "))
242 }
Colin Cross303e21f2018-08-07 16:49:25 -0700243 if benchmark.testConfig != nil {
244 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", benchmark.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700245 }
Nelson Li1f6b14e2018-04-18 16:55:21 +0000246 fmt.Fprintln(w, "LOCAL_NATIVE_BENCHMARK := true")
Colin Crosse28f4e22017-04-24 18:10:29 -0700247 })
Anders Lewisb97e8182017-07-14 15:20:13 -0700248
249 androidMkWriteTestData(benchmark.data, ctx, ret)
Colin Crossb916a382016-07-29 17:28:03 -0700250}
251
252func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
253 ctx.subAndroidMk(ret, test.binaryDecorator)
Dan Willemsen0fe72532017-01-17 13:25:49 -0800254 ret.Class = "NATIVE_TESTS"
Colin Crossb916a382016-07-29 17:28:03 -0700255 if Bool(test.Properties.Test_per_src) {
Nan Zhang0007d812017-11-07 10:57:05 -0800256 ret.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
Colin Crossa2344662016-03-24 13:14:12 -0700257 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800258
Colin Cross27a4b052017-08-10 16:32:23 -0700259 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa929db02017-03-27 16:27:50 -0700260 if len(test.Properties.Test_suites) > 0 {
Dan Shi4df566d2017-04-03 12:29:25 -0700261 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
Colin Crossa929db02017-03-27 16:27:50 -0700262 strings.Join(test.Properties.Test_suites, " "))
263 }
Colin Cross303e21f2018-08-07 16:49:25 -0700264 if test.testConfig != nil {
265 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", test.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700266 }
Colin Crossa929db02017-03-27 16:27:50 -0700267 })
268
Anders Lewisb97e8182017-07-14 15:20:13 -0700269 androidMkWriteTestData(test.data, ctx, ret)
Colin Crossa2344662016-03-24 13:14:12 -0700270}
271
Colin Crossb916a382016-07-29 17:28:03 -0700272func (test *testLibrary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
273 ctx.subAndroidMk(ret, test.libraryDecorator)
274}
Dan Willemsene7932e82016-05-16 15:56:53 -0700275
Colin Crossb916a382016-07-29 17:28:03 -0700276func (library *toolchainLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
277 ret.Class = "STATIC_LIBRARIES"
Colin Cross27a4b052017-08-10 16:32:23 -0700278 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Logan Chien031d2b32018-07-26 00:19:50 +0800279 _, suffix, _ := splitFileExt(outputFile.Base())
280 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700281 })
282}
283
Dan Willemsenf2c27d72016-07-13 16:50:22 -0700284func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Dan Willemsen03ce63e2016-09-29 12:17:49 -0700285 // Soong installation is only supported for host modules. Have Make
286 // installation trigger Soong installation.
287 if ctx.Target().Os.Class == android.Host {
288 ret.OutputFile = android.OptionalPathForPath(installer.path)
289 }
290
Colin Cross27a4b052017-08-10 16:32:23 -0700291 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa2344662016-03-24 13:14:12 -0700292 path := installer.path.RelPathString()
Colin Crossbf305de2016-03-29 17:32:06 -0700293 dir, file := filepath.Split(path)
Logan Chien031d2b32018-07-26 00:19:50 +0800294 stem, suffix, _ := splitFileExt(file)
295 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Colin Crosse14388b2016-05-03 14:08:40 -0700296 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
Colin Crossbf305de2016-03-29 17:32:06 -0700297 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Colin Crossa2344662016-03-24 13:14:12 -0700298 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700299}
Dan Albert914449f2016-06-17 16:45:24 -0700300
Colin Crossb916a382016-07-29 17:28:03 -0700301func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Dan Willemsen01a90592017-04-07 15:21:13 -0700302 ret.SubName = ndkLibrarySuffix + "." + c.properties.ApiLevel
Dan Albert705c84b2016-08-08 10:45:03 -0700303 ret.Class = "SHARED_LIBRARIES"
Dan Albert914449f2016-06-17 16:45:24 -0700304
Colin Cross27a4b052017-08-10 16:32:23 -0700305 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Cross0875c522017-11-28 17:34:01 -0800306 path, file := filepath.Split(c.installPath.String())
Logan Chien031d2b32018-07-26 00:19:50 +0800307 stem, suffix, _ := splitFileExt(file)
Logan Chien031d2b32018-07-26 00:19:50 +0800308 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Dan Albert914449f2016-06-17 16:45:24 -0700309 fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
310 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Dan Willemsen866810d2017-04-04 14:13:45 -0700311 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Dan Albert914449f2016-06-17 16:45:24 -0700312 })
313}
Dan Willemsenb916b802017-03-19 13:44:32 -0700314
315func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
316 ret.Class = "SHARED_LIBRARIES"
Jiyong Parkf9332f12018-02-01 00:54:12 +0900317 ret.SubName = vendorSuffix
Dan Willemsenb916b802017-03-19 13:44:32 -0700318
Colin Cross27a4b052017-08-10 16:32:23 -0700319 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700320 c.libraryDecorator.androidMkWriteExportedFlags(w)
Logan Chien031d2b32018-07-26 00:19:50 +0800321 _, _, ext := splitFileExt(outputFile.Base())
Dan Willemsenb916b802017-03-19 13:44:32 -0700322
Logan Chien031d2b32018-07-26 00:19:50 +0800323 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
Dan Willemsenb916b802017-03-19 13:44:32 -0700324 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
325 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Colin Crossb60190a2018-09-04 16:28:17 -0700326 fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", c.toc().String())
Dan Willemsenb916b802017-03-19 13:44:32 -0700327 })
328}
Justin Yun71549282017-11-17 12:10:28 +0900329
330func (c *vndkPrebuiltLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
331 ret.Class = "SHARED_LIBRARIES"
332
Jae Shin43ef2642017-12-29 16:20:21 +0900333 ret.SubName = c.NameSuffix()
Justin Yun71549282017-11-17 12:10:28 +0900334
335 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
336 c.libraryDecorator.androidMkWriteExportedFlags(w)
337
338 path := c.path.RelPathString()
339 dir, file := filepath.Split(path)
Logan Chien031d2b32018-07-26 00:19:50 +0800340 stem, suffix, ext := splitFileExt(file)
Logan Chien031d2b32018-07-26 00:19:50 +0800341 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
342 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Justin Yun71549282017-11-17 12:10:28 +0900343 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
344 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
345 })
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800346}
Dan Albert8ba131b2017-12-14 13:23:15 -0800347
348func (c *ndkPrebuiltStlLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
349 ret.Class = "SHARED_LIBRARIES"
Dan Albert8ba131b2017-12-14 13:23:15 -0800350}
Jiyong Park374510b2018-03-19 18:23:01 +0900351
352func (c *vendorPublicLibraryStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
353 ret.Class = "SHARED_LIBRARIES"
354 ret.SubName = vendorPublicLibrarySuffix
355
356 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
357 c.libraryDecorator.androidMkWriteExportedFlags(w)
Logan Chien031d2b32018-07-26 00:19:50 +0800358 _, _, ext := splitFileExt(outputFile.Base())
Jiyong Park374510b2018-03-19 18:23:01 +0900359
Logan Chien031d2b32018-07-26 00:19:50 +0800360 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
Jiyong Park374510b2018-03-19 18:23:01 +0900361 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
362 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
363 })
364}
Logan Chien4fcea3d2018-11-20 11:59:08 +0800365
366func (p *prebuiltLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
367 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
368 if p.properties.Check_elf_files != nil {
369 fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES :=", *p.properties.Check_elf_files)
370 } else {
371 // soong_cc_prebuilt.mk does not include check_elf_file.mk by default
372 // because cc_library_shared and cc_binary use soong_cc_prebuilt.mk as well.
373 // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to
374 // true if `p.properties.Check_elf_files` is not specified.
375 fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := true")
376 }
377 })
378}
379
380func (p *prebuiltLibraryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
381 ctx.subAndroidMk(ret, p.libraryDecorator)
382 if p.shared() {
383 ctx.subAndroidMk(ret, &p.prebuiltLinker)
384 androidMkWriteAllowUndefinedSymbols(p.baseLinker, ret)
385 }
386}
387
388func (p *prebuiltBinaryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
389 ctx.subAndroidMk(ret, p.binaryDecorator)
390 ctx.subAndroidMk(ret, &p.prebuiltLinker)
391 androidMkWriteAllowUndefinedSymbols(p.baseLinker, ret)
392}
393
394func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, ret *android.AndroidMkData) {
395 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
396 allow := linker.Properties.Allow_undefined_symbols
397 if allow != nil {
398 fmt.Fprintln(w, "LOCAL_ALLOW_UNDEFINED_SYMBOLS :=", *allow)
399 }
400 })
401}