blob: 4b0cb31dc4ee678d72f2526164eab1e1959f492a [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 (
dimitry43204492019-05-23 13:24:38 +020027 nativeBridgeSuffix = ".native_bridge"
28 vendorSuffix = ".vendor"
29 recoverySuffix = ".recovery"
Jiyong Park27b188b2017-07-18 13:23:39 +090030)
31
Dan Willemsenf2c27d72016-07-13 16:50:22 -070032type AndroidMkContext interface {
Jiyong Parkb0788572018-12-20 22:10:17 +090033 Name() string
Dan Willemsenf2c27d72016-07-13 16:50:22 -070034 Target() android.Target
Colin Crossb916a382016-07-29 17:28:03 -070035 subAndroidMk(*android.AndroidMkData, interface{})
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +000036 Arch() android.Arch
37 Os() android.OsType
38 Host() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070039 useVndk() bool
Jiyong Parkb0788572018-12-20 22:10:17 +090040 static() bool
41 inRecovery() bool
Colin Crossb916a382016-07-29 17:28:03 -070042}
43
44type subAndroidMkProvider interface {
45 AndroidMk(AndroidMkContext, *android.AndroidMkData)
46}
47
48func (c *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
49 if c.subAndroidMkOnce == nil {
50 c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
51 }
52 if androidmk, ok := obj.(subAndroidMkProvider); ok {
53 if !c.subAndroidMkOnce[androidmk] {
54 c.subAndroidMkOnce[androidmk] = true
55 androidmk.AndroidMk(c, data)
56 }
57 }
Dan Willemsenf2c27d72016-07-13 16:50:22 -070058}
59
Colin Crossa18e9cf2017-08-10 17:00:19 -070060func (c *Module) AndroidMk() android.AndroidMkData {
Jiyong Park9d452992018-10-03 00:38:19 +090061 if c.Properties.HideFromMake || !c.IsForPlatform() {
Colin Crossa18e9cf2017-08-10 17:00:19 -070062 return android.AndroidMkData{
63 Disabled: true,
64 }
Colin Crossbc6fb162016-05-24 15:39:04 -070065 }
66
Colin Crossa18e9cf2017-08-10 17:00:19 -070067 ret := android.AndroidMkData{
68 OutputFile: c.outputFile,
Jiyong Parkb0788572018-12-20 22:10:17 +090069 // TODO(jiyong): add the APEXes providing shared libs to the required modules
70 // Currently, adding c.Properties.ApexesProvidingSharedLibs is causing multiple
Martin Stjernholmcc4b0ad2019-07-05 22:38:25 +010071 // ART APEXes (com.android.art.debug|release) to be installed. And this
Jiyong Parkb0788572018-12-20 22:10:17 +090072 // is breaking some older devices (like marlin) where system.img is small.
73 Required: c.Properties.AndroidMkRuntimeLibs,
74 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Logan Chien43d34c32017-12-20 01:17:32 +080075
Colin Crossa18e9cf2017-08-10 17:00:19 -070076 Extra: []android.AndroidMkExtraFunc{
77 func(w io.Writer, outputFile android.Path) {
Colin Cross5beccee2017-12-07 15:28:59 -080078 if len(c.Properties.Logtags) > 0 {
79 fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(c.Properties.Logtags, " "))
80 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070081 if len(c.Properties.AndroidMkSharedLibs) > 0 {
82 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
83 }
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +000084 if len(c.Properties.AndroidMkStaticLibs) > 0 {
85 fmt.Fprintln(w, "LOCAL_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkStaticLibs, " "))
86 }
87 if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
88 fmt.Fprintln(w, "LOCAL_WHOLE_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkWholeStaticLibs, " "))
89 }
Inseob Kim9516ee92019-05-09 10:56:13 +090090 fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.makeLinkType)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070091 if c.useVndk() {
Colin Crossa18e9cf2017-08-10 17:00:19 -070092 fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
Jooyung Han76106d92019-05-20 18:49:10 +090093 if c.isVndk() && !c.static() {
94 fmt.Fprintln(w, "LOCAL_SOONG_VNDK_VERSION := "+c.vndkVersion())
95 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070096 }
97 },
98 },
99 }
Colin Crossca860ac2016-01-04 14:34:37 -0800100
Colin Crossca860ac2016-01-04 14:34:37 -0800101 for _, feature := range c.features {
Colin Crossb916a382016-07-29 17:28:03 -0700102 c.subAndroidMk(&ret, feature)
Colin Crossca860ac2016-01-04 14:34:37 -0800103 }
104
Colin Crossb916a382016-07-29 17:28:03 -0700105 c.subAndroidMk(&ret, c.compiler)
106 c.subAndroidMk(&ret, c.linker)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700107 if c.sanitize != nil {
108 c.subAndroidMk(&ret, c.sanitize)
109 }
Colin Crossb916a382016-07-29 17:28:03 -0700110 c.subAndroidMk(&ret, c.installer)
Colin Crossca860ac2016-01-04 14:34:37 -0800111
dimitry43204492019-05-23 13:24:38 +0200112 if c.Target().NativeBridge == android.NativeBridgeEnabled {
113 ret.SubName += nativeBridgeSuffix
114 }
115
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700116 if c.useVndk() && c.hasVendorVariant() {
Jiyong Park27b188b2017-07-18 13:23:39 +0900117 // .vendor suffix is added only when we will have two variants: core and vendor.
118 // The suffix is not added for vendor-only module.
119 ret.SubName += vendorSuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +0900120 } else if c.inRecovery() && !c.onlyInRecovery() {
121 ret.SubName += recoverySuffix
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700122 }
123
Colin Crossa18e9cf2017-08-10 17:00:19 -0700124 return ret
Colin Crossca860ac2016-01-04 14:34:37 -0800125}
126
Anders Lewisb97e8182017-07-14 15:20:13 -0700127func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, ret *android.AndroidMkData) {
128 var testFiles []string
129 for _, d := range data {
130 rel := d.Rel()
131 path := d.String()
132 if !strings.HasSuffix(path, rel) {
133 panic(fmt.Errorf("path %q does not end with %q", path, rel))
134 }
135 path = strings.TrimSuffix(path, rel)
136 testFiles = append(testFiles, path+":"+rel)
137 }
138 if len(testFiles) > 0 {
Colin Cross27a4b052017-08-10 16:32:23 -0700139 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Anders Lewisb97e8182017-07-14 15:20:13 -0700140 fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(testFiles, " "))
Anders Lewisb97e8182017-07-14 15:20:13 -0700141 })
142 }
143}
144
dimitrydb417472019-05-20 16:16:47 +0200145func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
146 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
147 var result []string
148 for _, override := range overrides {
149 result = append(result, override+nativeBridgeSuffix)
150 }
151 return result
152 }
153
154 return overrides
155}
156
Dan Willemsen58539402017-03-19 13:44:32 -0700157func (library *libraryDecorator) androidMkWriteExportedFlags(w io.Writer) {
158 exportedFlags := library.exportedFlags()
Inseob Kim69378442019-06-03 19:10:47 +0900159 for _, dir := range library.exportedDirs() {
160 exportedFlags = append(exportedFlags, "-I"+dir)
161 }
162 for _, dir := range library.exportedSystemDirs() {
163 exportedFlags = append(exportedFlags, "-isystem "+dir)
164 }
Dan Willemsen58539402017-03-19 13:44:32 -0700165 if len(exportedFlags) > 0 {
166 fmt.Fprintln(w, "LOCAL_EXPORT_CFLAGS :=", strings.Join(exportedFlags, " "))
Dan Willemsend5781342017-02-15 16:15:21 -0800167 }
Inseob Kim69378442019-06-03 19:10:47 +0900168 exportedDeps := library.exportedDeps()
169 if len(exportedDeps) > 0 {
170 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DEPS :=", strings.Join(exportedDeps.Strings(), " "))
Dan Willemsen58539402017-03-19 13:44:32 -0700171 }
172}
Dan Willemsend5781342017-02-15 16:15:21 -0800173
Logan Chien41eabe62019-04-10 13:33:58 +0800174func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
175 if library.sAbiOutputFile.Valid() {
176 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", library.sAbiOutputFile.String())
177 if library.sAbiDiff.Valid() && !library.static() {
178 fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", library.sAbiDiff.String())
179 fmt.Fprintln(w, "HEADER_ABI_DIFFS +=", library.sAbiDiff.String())
180 }
181 }
182}
183
Dan Willemsen58539402017-03-19 13:44:32 -0700184func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Dan Willemsend5781342017-02-15 16:15:21 -0800185 if library.static() {
186 ret.Class = "STATIC_LIBRARIES"
187 } else if library.shared() {
Dan Willemsend5781342017-02-15 16:15:21 -0800188 ret.Class = "SHARED_LIBRARIES"
Colin Crossb60190a2018-09-04 16:28:17 -0700189 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
190 fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", library.toc().String())
Jiyong Park47e4fcb2019-02-05 22:33:10 +0900191 if !library.buildStubs() {
192 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String())
193 }
dimitryd95964a2018-11-07 13:43:34 +0100194 if len(library.Properties.Overrides) > 0 {
dimitrydb417472019-05-20 16:16:47 +0200195 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES := "+strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " "))
dimitryd95964a2018-11-07 13:43:34 +0100196 }
Jiyong Parkf1194352019-02-25 11:05:47 +0900197 if len(library.post_install_cmds) > 0 {
198 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD := "+strings.Join(library.post_install_cmds, "&& "))
199 }
Colin Crossb60190a2018-09-04 16:28:17 -0700200 })
Dan Willemsend5781342017-02-15 16:15:21 -0800201 } else if library.header() {
Colin Crossb60190a2018-09-04 16:28:17 -0700202 ret.Class = "HEADER_LIBRARIES"
Dan Willemsend5781342017-02-15 16:15:21 -0800203 }
204
Dan Willemsen569edc52018-11-19 09:33:29 -0800205 ret.DistFile = library.distFile
Colin Cross27a4b052017-08-10 16:32:23 -0700206 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Dan Willemsen58539402017-03-19 13:44:32 -0700207 library.androidMkWriteExportedFlags(w)
Logan Chien41eabe62019-04-10 13:33:58 +0800208 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
Dan Willemsen218f6562015-07-08 18:13:11 -0700209
Logan Chien031d2b32018-07-26 00:19:50 +0800210 _, _, ext := splitFileExt(outputFile.Base())
211
212 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
Dan Willemsen218f6562015-07-08 18:13:11 -0700213
Dan Willemsen581341d2017-02-09 16:16:31 -0800214 if library.coverageOutputFile.Valid() {
215 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String())
216 }
Vic Yangefd249e2018-11-12 20:19:56 -0800217
218 if library.useCoreVariant {
219 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
220 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
221 fmt.Fprintln(w, "LOCAL_VNDK_DEPEND_ON_CORE_VARIANT := true")
222 }
Colin Crossca860ac2016-01-04 14:34:37 -0800223 })
Colin Crossb916a382016-07-29 17:28:03 -0700224
Jiyong Parkb0788572018-12-20 22:10:17 +0900225 if library.shared() && !library.buildStubs() {
Colin Crossb916a382016-07-29 17:28:03 -0700226 ctx.subAndroidMk(ret, library.baseInstaller)
Colin Crossb60190a2018-09-04 16:28:17 -0700227 } else {
228 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
229 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
Jiyong Parkb0788572018-12-20 22:10:17 +0900230 if library.buildStubs() {
231 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
232 }
Colin Crossb60190a2018-09-04 16:28:17 -0700233 })
Colin Crossb916a382016-07-29 17:28:03 -0700234 }
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000235 if len(library.Properties.Stubs.Versions) > 0 &&
236 android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.inRecovery() && !ctx.useVndk() &&
237 !ctx.static() {
Jiyong Parkb0788572018-12-20 22:10:17 +0900238 if !library.buildStubs() {
239 ret.SubName = ".bootstrap"
240 }
241 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700242}
243
Dan Willemsenf2c27d72016-07-13 16:50:22 -0700244func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Colin Cross0f86d182017-08-10 17:07:28 -0700245 ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Colin Crossca860ac2016-01-04 14:34:37 -0800246 out := ret.OutputFile.Path()
Dan Willemsen2e224ca2018-09-06 00:26:20 -0700247 varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, data.SubName)
Dan Willemsen218f6562015-07-08 18:13:11 -0700248
Dan Willemsen2e224ca2018-09-06 00:26:20 -0700249 fmt.Fprintf(w, "\n%s := %s\n", varname, out.String())
250 fmt.Fprintln(w, ".KATI_READONLY: "+varname)
Dan Willemsen218f6562015-07-08 18:13:11 -0700251 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700252}
253
Colin Crossb916a382016-07-29 17:28:03 -0700254func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Colin Cross1e7d3702016-08-24 15:25:47 -0700255 ctx.subAndroidMk(ret, binary.baseInstaller)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700256
Dan Willemsen218f6562015-07-08 18:13:11 -0700257 ret.Class = "EXECUTABLES"
Dan Willemsen569edc52018-11-19 09:33:29 -0800258 ret.DistFile = binary.distFile
Colin Cross27a4b052017-08-10 16:32:23 -0700259 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossb60190a2018-09-04 16:28:17 -0700260 fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String())
Colin Cross9b09f242016-12-07 13:37:42 -0800261 if len(binary.symlinks) > 0 {
262 fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
263 }
264
Dan Willemsen581341d2017-02-09 16:16:31 -0800265 if binary.coverageOutputFile.Valid() {
266 fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String())
267 }
Yifan Hong946e32e2018-04-03 13:22:50 -0700268
269 if len(binary.Properties.Overrides) > 0 {
dimitrydb417472019-05-20 16:16:47 +0200270 fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES := "+strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " "))
Yifan Hong946e32e2018-04-03 13:22:50 -0700271 }
Jiyong Parkf1194352019-02-25 11:05:47 +0900272 if len(binary.post_install_cmds) > 0 {
273 fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD := "+strings.Join(binary.post_install_cmds, "&& "))
274 }
Colin Crossca860ac2016-01-04 14:34:37 -0800275 })
276}
277
Colin Crossb916a382016-07-29 17:28:03 -0700278func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
279 ctx.subAndroidMk(ret, benchmark.binaryDecorator)
Dan Willemsen58a5c8b2017-05-23 15:10:37 -0700280 ret.Class = "NATIVE_TESTS"
Colin Cross27a4b052017-08-10 16:32:23 -0700281 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crosse28f4e22017-04-24 18:10:29 -0700282 if len(benchmark.Properties.Test_suites) > 0 {
283 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
284 strings.Join(benchmark.Properties.Test_suites, " "))
285 }
Colin Cross303e21f2018-08-07 16:49:25 -0700286 if benchmark.testConfig != nil {
287 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", benchmark.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700288 }
Nelson Li1f6b14e2018-04-18 16:55:21 +0000289 fmt.Fprintln(w, "LOCAL_NATIVE_BENCHMARK := true")
Colin Crosse28f4e22017-04-24 18:10:29 -0700290 })
Anders Lewisb97e8182017-07-14 15:20:13 -0700291
292 androidMkWriteTestData(benchmark.data, ctx, ret)
Colin Crossb916a382016-07-29 17:28:03 -0700293}
294
295func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
296 ctx.subAndroidMk(ret, test.binaryDecorator)
Dan Willemsen0fe72532017-01-17 13:25:49 -0800297 ret.Class = "NATIVE_TESTS"
Colin Crossb916a382016-07-29 17:28:03 -0700298 if Bool(test.Properties.Test_per_src) {
Nan Zhang0007d812017-11-07 10:57:05 -0800299 ret.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
Colin Crossa2344662016-03-24 13:14:12 -0700300 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800301
Colin Cross27a4b052017-08-10 16:32:23 -0700302 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa929db02017-03-27 16:27:50 -0700303 if len(test.Properties.Test_suites) > 0 {
Dan Shi4df566d2017-04-03 12:29:25 -0700304 fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
Colin Crossa929db02017-03-27 16:27:50 -0700305 strings.Join(test.Properties.Test_suites, " "))
306 }
Colin Cross303e21f2018-08-07 16:49:25 -0700307 if test.testConfig != nil {
308 fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", test.testConfig.String())
Julien Despreze146e392018-08-02 15:00:46 -0700309 }
Colin Crossa929db02017-03-27 16:27:50 -0700310 })
311
Anders Lewisb97e8182017-07-14 15:20:13 -0700312 androidMkWriteTestData(test.data, ctx, ret)
Colin Crossa2344662016-03-24 13:14:12 -0700313}
314
Colin Crossb916a382016-07-29 17:28:03 -0700315func (test *testLibrary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
316 ctx.subAndroidMk(ret, test.libraryDecorator)
317}
Dan Willemsene7932e82016-05-16 15:56:53 -0700318
Colin Crossb916a382016-07-29 17:28:03 -0700319func (library *toolchainLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
320 ret.Class = "STATIC_LIBRARIES"
Colin Cross27a4b052017-08-10 16:32:23 -0700321 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Logan Chien031d2b32018-07-26 00:19:50 +0800322 _, suffix, _ := splitFileExt(outputFile.Base())
323 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Dan Willemsen7517ed02016-06-10 17:20:30 -0700324 })
325}
326
Dan Willemsenf2c27d72016-07-13 16:50:22 -0700327func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Dan Willemsen03ce63e2016-09-29 12:17:49 -0700328 // Soong installation is only supported for host modules. Have Make
329 // installation trigger Soong installation.
330 if ctx.Target().Os.Class == android.Host {
331 ret.OutputFile = android.OptionalPathForPath(installer.path)
332 }
333
Colin Cross27a4b052017-08-10 16:32:23 -0700334 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Crossa2344662016-03-24 13:14:12 -0700335 path := installer.path.RelPathString()
Colin Crossbf305de2016-03-29 17:32:06 -0700336 dir, file := filepath.Split(path)
Logan Chien031d2b32018-07-26 00:19:50 +0800337 stem, suffix, _ := splitFileExt(file)
338 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Colin Crosse14388b2016-05-03 14:08:40 -0700339 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
Colin Crossbf305de2016-03-29 17:32:06 -0700340 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Colin Crossa2344662016-03-24 13:14:12 -0700341 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700342}
Dan Albert914449f2016-06-17 16:45:24 -0700343
Colin Crossb916a382016-07-29 17:28:03 -0700344func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Dan Willemsen01a90592017-04-07 15:21:13 -0700345 ret.SubName = ndkLibrarySuffix + "." + c.properties.ApiLevel
Dan Albert705c84b2016-08-08 10:45:03 -0700346 ret.Class = "SHARED_LIBRARIES"
Dan Albert914449f2016-06-17 16:45:24 -0700347
Colin Cross27a4b052017-08-10 16:32:23 -0700348 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Colin Cross0875c522017-11-28 17:34:01 -0800349 path, file := filepath.Split(c.installPath.String())
Logan Chien031d2b32018-07-26 00:19:50 +0800350 stem, suffix, _ := splitFileExt(file)
Logan Chien031d2b32018-07-26 00:19:50 +0800351 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Dan Albert914449f2016-06-17 16:45:24 -0700352 fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path)
353 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Dan Willemsen866810d2017-04-04 14:13:45 -0700354 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Dan Albert914449f2016-06-17 16:45:24 -0700355 })
356}
Dan Willemsenb916b802017-03-19 13:44:32 -0700357
358func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
359 ret.Class = "SHARED_LIBRARIES"
Jiyong Parkf9332f12018-02-01 00:54:12 +0900360 ret.SubName = vendorSuffix
Dan Willemsenb916b802017-03-19 13:44:32 -0700361
Colin Cross27a4b052017-08-10 16:32:23 -0700362 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700363 c.libraryDecorator.androidMkWriteExportedFlags(w)
Logan Chien031d2b32018-07-26 00:19:50 +0800364 _, _, ext := splitFileExt(outputFile.Base())
Dan Willemsenb916b802017-03-19 13:44:32 -0700365
Logan Chien031d2b32018-07-26 00:19:50 +0800366 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
Dan Willemsenb916b802017-03-19 13:44:32 -0700367 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
368 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
Colin Crossb60190a2018-09-04 16:28:17 -0700369 fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", c.toc().String())
Dan Willemsenb916b802017-03-19 13:44:32 -0700370 })
371}
Justin Yun71549282017-11-17 12:10:28 +0900372
373func (c *vndkPrebuiltLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
374 ret.Class = "SHARED_LIBRARIES"
375
Jae Shin43ef2642017-12-29 16:20:21 +0900376 ret.SubName = c.NameSuffix()
Justin Yun71549282017-11-17 12:10:28 +0900377
378 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
379 c.libraryDecorator.androidMkWriteExportedFlags(w)
380
381 path := c.path.RelPathString()
382 dir, file := filepath.Split(path)
Logan Chien031d2b32018-07-26 00:19:50 +0800383 stem, suffix, ext := splitFileExt(file)
Logan Chien031d2b32018-07-26 00:19:50 +0800384 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
385 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
Justin Yun71549282017-11-17 12:10:28 +0900386 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
387 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
388 })
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800389}
Dan Albert8ba131b2017-12-14 13:23:15 -0800390
391func (c *ndkPrebuiltStlLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
392 ret.Class = "SHARED_LIBRARIES"
Dan Albert8ba131b2017-12-14 13:23:15 -0800393}
Jiyong Park374510b2018-03-19 18:23:01 +0900394
395func (c *vendorPublicLibraryStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
396 ret.Class = "SHARED_LIBRARIES"
397 ret.SubName = vendorPublicLibrarySuffix
398
399 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
400 c.libraryDecorator.androidMkWriteExportedFlags(w)
Logan Chien031d2b32018-07-26 00:19:50 +0800401 _, _, ext := splitFileExt(outputFile.Base())
Jiyong Park374510b2018-03-19 18:23:01 +0900402
Logan Chien031d2b32018-07-26 00:19:50 +0800403 fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext)
Jiyong Park374510b2018-03-19 18:23:01 +0900404 fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
405 fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
406 })
407}
Logan Chien4fcea3d2018-11-20 11:59:08 +0800408
409func (p *prebuiltLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
410 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
411 if p.properties.Check_elf_files != nil {
412 fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES :=", *p.properties.Check_elf_files)
413 } else {
414 // soong_cc_prebuilt.mk does not include check_elf_file.mk by default
415 // because cc_library_shared and cc_binary use soong_cc_prebuilt.mk as well.
416 // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to
417 // true if `p.properties.Check_elf_files` is not specified.
418 fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := true")
419 }
420 })
421}
422
423func (p *prebuiltLibraryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
424 ctx.subAndroidMk(ret, p.libraryDecorator)
425 if p.shared() {
426 ctx.subAndroidMk(ret, &p.prebuiltLinker)
427 androidMkWriteAllowUndefinedSymbols(p.baseLinker, ret)
428 }
429}
430
431func (p *prebuiltBinaryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
432 ctx.subAndroidMk(ret, p.binaryDecorator)
433 ctx.subAndroidMk(ret, &p.prebuiltLinker)
434 androidMkWriteAllowUndefinedSymbols(p.baseLinker, ret)
435}
436
437func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, ret *android.AndroidMkData) {
438 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
439 allow := linker.Properties.Allow_undefined_symbols
440 if allow != nil {
441 fmt.Fprintln(w, "LOCAL_ALLOW_UNDEFINED_SYMBOLS :=", *allow)
442 }
443 })
444}