Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 18 | "fmt" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 19 | "io" |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 20 | "path/filepath" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 23 | "android/soong/android" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 26 | var ( |
dimitry | 4320449 | 2019-05-23 13:24:38 +0200 | [diff] [blame] | 27 | nativeBridgeSuffix = ".native_bridge" |
| 28 | vendorSuffix = ".vendor" |
| 29 | recoverySuffix = ".recovery" |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 30 | ) |
| 31 | |
Dan Willemsen | f2c27d7 | 2016-07-13 16:50:22 -0700 | [diff] [blame] | 32 | type AndroidMkContext interface { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 33 | Name() string |
Dan Willemsen | f2c27d7 | 2016-07-13 16:50:22 -0700 | [diff] [blame] | 34 | Target() android.Target |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 35 | subAndroidMk(*android.AndroidMkData, interface{}) |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame] | 36 | Arch() android.Arch |
| 37 | Os() android.OsType |
| 38 | Host() bool |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 39 | useVndk() bool |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 40 | vndkVersion() string |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 41 | static() bool |
| 42 | inRecovery() bool |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | type subAndroidMkProvider interface { |
| 46 | AndroidMk(AndroidMkContext, *android.AndroidMkData) |
| 47 | } |
| 48 | |
| 49 | func (c *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) { |
| 50 | if c.subAndroidMkOnce == nil { |
| 51 | c.subAndroidMkOnce = make(map[subAndroidMkProvider]bool) |
| 52 | } |
| 53 | if androidmk, ok := obj.(subAndroidMkProvider); ok { |
| 54 | if !c.subAndroidMkOnce[androidmk] { |
| 55 | c.subAndroidMkOnce[androidmk] = true |
| 56 | androidmk.AndroidMk(c, data) |
| 57 | } |
| 58 | } |
Dan Willemsen | f2c27d7 | 2016-07-13 16:50:22 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 61 | func (c *Module) AndroidMk() android.AndroidMkData { |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 62 | if c.Properties.HideFromMake || !c.IsForPlatform() { |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 63 | return android.AndroidMkData{ |
| 64 | Disabled: true, |
| 65 | } |
Colin Cross | bc6fb16 | 2016-05-24 15:39:04 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 68 | ret := android.AndroidMkData{ |
| 69 | OutputFile: c.outputFile, |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 70 | // TODO(jiyong): add the APEXes providing shared libs to the required modules |
| 71 | // Currently, adding c.Properties.ApexesProvidingSharedLibs is causing multiple |
Martin Stjernholm | cc4b0ad | 2019-07-05 22:38:25 +0100 | [diff] [blame] | 72 | // ART APEXes (com.android.art.debug|release) to be installed. And this |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 73 | // is breaking some older devices (like marlin) where system.img is small. |
| 74 | Required: c.Properties.AndroidMkRuntimeLibs, |
| 75 | Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk", |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 76 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 77 | Extra: []android.AndroidMkExtraFunc{ |
| 78 | func(w io.Writer, outputFile android.Path) { |
Colin Cross | 5beccee | 2017-12-07 15:28:59 -0800 | [diff] [blame] | 79 | if len(c.Properties.Logtags) > 0 { |
| 80 | fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES :=", strings.Join(c.Properties.Logtags, " ")) |
| 81 | } |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 82 | if len(c.Properties.AndroidMkSharedLibs) > 0 { |
| 83 | fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " ")) |
| 84 | } |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 85 | if len(c.Properties.AndroidMkStaticLibs) > 0 { |
| 86 | fmt.Fprintln(w, "LOCAL_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkStaticLibs, " ")) |
| 87 | } |
| 88 | if len(c.Properties.AndroidMkWholeStaticLibs) > 0 { |
| 89 | fmt.Fprintln(w, "LOCAL_WHOLE_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkWholeStaticLibs, " ")) |
| 90 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 91 | fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.makeLinkType) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 92 | if c.useVndk() { |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 93 | fmt.Fprintln(w, "LOCAL_USE_VNDK := true") |
Jooyung Han | 76106d9 | 2019-05-20 18:49:10 +0900 | [diff] [blame] | 94 | if c.isVndk() && !c.static() { |
| 95 | fmt.Fprintln(w, "LOCAL_SOONG_VNDK_VERSION := "+c.vndkVersion()) |
| 96 | } |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 97 | } |
| 98 | }, |
| 99 | }, |
| 100 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 101 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 102 | for _, feature := range c.features { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 103 | c.subAndroidMk(&ret, feature) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 106 | c.subAndroidMk(&ret, c.compiler) |
| 107 | c.subAndroidMk(&ret, c.linker) |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 108 | if c.sanitize != nil { |
| 109 | c.subAndroidMk(&ret, c.sanitize) |
| 110 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 111 | c.subAndroidMk(&ret, c.installer) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 112 | |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 113 | ret.SubName += c.Properties.SubName |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 114 | |
Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 115 | return ret |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 118 | func androidMkWriteTestData(data android.Paths, ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 119 | var testFiles []string |
| 120 | for _, d := range data { |
| 121 | rel := d.Rel() |
| 122 | path := d.String() |
| 123 | if !strings.HasSuffix(path, rel) { |
| 124 | panic(fmt.Errorf("path %q does not end with %q", path, rel)) |
| 125 | } |
| 126 | path = strings.TrimSuffix(path, rel) |
| 127 | testFiles = append(testFiles, path+":"+rel) |
| 128 | } |
| 129 | if len(testFiles) > 0 { |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 130 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 131 | fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(testFiles, " ")) |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 132 | }) |
| 133 | } |
| 134 | } |
| 135 | |
dimitry | db41747 | 2019-05-20 16:16:47 +0200 | [diff] [blame] | 136 | func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string { |
| 137 | if ctx.Target().NativeBridge == android.NativeBridgeEnabled { |
| 138 | var result []string |
| 139 | for _, override := range overrides { |
| 140 | result = append(result, override+nativeBridgeSuffix) |
| 141 | } |
| 142 | return result |
| 143 | } |
| 144 | |
| 145 | return overrides |
| 146 | } |
| 147 | |
Dan Willemsen | 5853940 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 148 | func (library *libraryDecorator) androidMkWriteExportedFlags(w io.Writer) { |
| 149 | exportedFlags := library.exportedFlags() |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 150 | for _, dir := range library.exportedDirs() { |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame^] | 151 | exportedFlags = append(exportedFlags, "-I"+dir.String()) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 152 | } |
| 153 | for _, dir := range library.exportedSystemDirs() { |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame^] | 154 | exportedFlags = append(exportedFlags, "-isystem "+dir.String()) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 155 | } |
Dan Willemsen | 5853940 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 156 | if len(exportedFlags) > 0 { |
| 157 | fmt.Fprintln(w, "LOCAL_EXPORT_CFLAGS :=", strings.Join(exportedFlags, " ")) |
Dan Willemsen | d578134 | 2017-02-15 16:15:21 -0800 | [diff] [blame] | 158 | } |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 159 | exportedDeps := library.exportedDeps() |
| 160 | if len(exportedDeps) > 0 { |
| 161 | fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DEPS :=", strings.Join(exportedDeps.Strings(), " ")) |
Dan Willemsen | 5853940 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 162 | } |
| 163 | } |
Dan Willemsen | d578134 | 2017-02-15 16:15:21 -0800 | [diff] [blame] | 164 | |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 165 | func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) { |
| 166 | if library.sAbiOutputFile.Valid() { |
| 167 | fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", library.sAbiOutputFile.String()) |
| 168 | if library.sAbiDiff.Valid() && !library.static() { |
| 169 | fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", library.sAbiDiff.String()) |
| 170 | fmt.Fprintln(w, "HEADER_ABI_DIFFS +=", library.sAbiDiff.String()) |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Dan Willemsen | 5853940 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 175 | func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Dan Willemsen | d578134 | 2017-02-15 16:15:21 -0800 | [diff] [blame] | 176 | if library.static() { |
| 177 | ret.Class = "STATIC_LIBRARIES" |
| 178 | } else if library.shared() { |
Dan Willemsen | d578134 | 2017-02-15 16:15:21 -0800 | [diff] [blame] | 179 | ret.Class = "SHARED_LIBRARIES" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 180 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 181 | fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", library.toc().String()) |
Jiyong Park | 47e4fcb | 2019-02-05 22:33:10 +0900 | [diff] [blame] | 182 | if !library.buildStubs() { |
| 183 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String()) |
| 184 | } |
dimitry | d95964a | 2018-11-07 13:43:34 +0100 | [diff] [blame] | 185 | if len(library.Properties.Overrides) > 0 { |
dimitry | db41747 | 2019-05-20 16:16:47 +0200 | [diff] [blame] | 186 | fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES := "+strings.Join(makeOverrideModuleNames(ctx, library.Properties.Overrides), " ")) |
dimitry | d95964a | 2018-11-07 13:43:34 +0100 | [diff] [blame] | 187 | } |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 188 | if len(library.post_install_cmds) > 0 { |
| 189 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD := "+strings.Join(library.post_install_cmds, "&& ")) |
| 190 | } |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 191 | }) |
Dan Willemsen | d578134 | 2017-02-15 16:15:21 -0800 | [diff] [blame] | 192 | } else if library.header() { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 193 | ret.Class = "HEADER_LIBRARIES" |
Dan Willemsen | d578134 | 2017-02-15 16:15:21 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 196 | ret.DistFile = library.distFile |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 197 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Dan Willemsen | 5853940 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 198 | library.androidMkWriteExportedFlags(w) |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 199 | library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 200 | |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 201 | _, _, ext := android.SplitFileExt(outputFile.Base()) |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 202 | |
| 203 | fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 204 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 205 | if library.coverageOutputFile.Valid() { |
| 206 | fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String()) |
| 207 | } |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 208 | |
| 209 | if library.useCoreVariant { |
| 210 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
| 211 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") |
| 212 | fmt.Fprintln(w, "LOCAL_VNDK_DEPEND_ON_CORE_VARIANT := true") |
| 213 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 214 | }) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 215 | |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 216 | if library.shared() && !library.buildStubs() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 217 | ctx.subAndroidMk(ret, library.baseInstaller) |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 218 | } else { |
| 219 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 220 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 221 | if library.buildStubs() { |
| 222 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") |
| 223 | } |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 224 | }) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 225 | } |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame] | 226 | if len(library.Properties.Stubs.Versions) > 0 && |
| 227 | android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.inRecovery() && !ctx.useVndk() && |
| 228 | !ctx.static() { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 229 | if !library.buildStubs() { |
| 230 | ret.SubName = ".bootstrap" |
| 231 | } |
| 232 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Dan Willemsen | f2c27d7 | 2016-07-13 16:50:22 -0700 | [diff] [blame] | 235 | func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 236 | ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 237 | out := ret.OutputFile.Path() |
Dan Willemsen | 2e224ca | 2018-09-06 00:26:20 -0700 | [diff] [blame] | 238 | varname := fmt.Sprintf("SOONG_%sOBJECT_%s%s", prefix, name, data.SubName) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 239 | |
Dan Willemsen | 2e224ca | 2018-09-06 00:26:20 -0700 | [diff] [blame] | 240 | fmt.Fprintf(w, "\n%s := %s\n", varname, out.String()) |
| 241 | fmt.Fprintln(w, ".KATI_READONLY: "+varname) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 242 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 245 | func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 246 | ctx.subAndroidMk(ret, binary.baseInstaller) |
Dan Willemsen | 7517ed0 | 2016-06-10 17:20:30 -0700 | [diff] [blame] | 247 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 248 | ret.Class = "EXECUTABLES" |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 249 | ret.DistFile = binary.distFile |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 250 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 251 | fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String()) |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 252 | if len(binary.symlinks) > 0 { |
| 253 | fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " ")) |
| 254 | } |
| 255 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 256 | if binary.coverageOutputFile.Valid() { |
| 257 | fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String()) |
| 258 | } |
Yifan Hong | 946e32e | 2018-04-03 13:22:50 -0700 | [diff] [blame] | 259 | |
| 260 | if len(binary.Properties.Overrides) > 0 { |
dimitry | db41747 | 2019-05-20 16:16:47 +0200 | [diff] [blame] | 261 | fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES := "+strings.Join(makeOverrideModuleNames(ctx, binary.Properties.Overrides), " ")) |
Yifan Hong | 946e32e | 2018-04-03 13:22:50 -0700 | [diff] [blame] | 262 | } |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 263 | if len(binary.post_install_cmds) > 0 { |
| 264 | fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD := "+strings.Join(binary.post_install_cmds, "&& ")) |
| 265 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 266 | }) |
| 267 | } |
| 268 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 269 | func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 270 | ctx.subAndroidMk(ret, benchmark.binaryDecorator) |
Dan Willemsen | 58a5c8b | 2017-05-23 15:10:37 -0700 | [diff] [blame] | 271 | ret.Class = "NATIVE_TESTS" |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 272 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 273 | if len(benchmark.Properties.Test_suites) > 0 { |
| 274 | fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", |
| 275 | strings.Join(benchmark.Properties.Test_suites, " ")) |
| 276 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 277 | if benchmark.testConfig != nil { |
| 278 | fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", benchmark.testConfig.String()) |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 279 | } |
Nelson Li | 1f6b14e | 2018-04-18 16:55:21 +0000 | [diff] [blame] | 280 | fmt.Fprintln(w, "LOCAL_NATIVE_BENCHMARK := true") |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 281 | }) |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 282 | |
| 283 | androidMkWriteTestData(benchmark.data, ctx, ret) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 287 | ctx.subAndroidMk(ret, test.binaryDecorator) |
Dan Willemsen | 0fe7253 | 2017-01-17 13:25:49 -0800 | [diff] [blame] | 288 | ret.Class = "NATIVE_TESTS" |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 289 | if Bool(test.Properties.Test_per_src) { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 290 | ret.SubName = "_" + String(test.binaryDecorator.Properties.Stem) |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 291 | } |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 292 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 293 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Colin Cross | a929db0 | 2017-03-27 16:27:50 -0700 | [diff] [blame] | 294 | if len(test.Properties.Test_suites) > 0 { |
Dan Shi | 4df566d | 2017-04-03 12:29:25 -0700 | [diff] [blame] | 295 | fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=", |
Colin Cross | a929db0 | 2017-03-27 16:27:50 -0700 | [diff] [blame] | 296 | strings.Join(test.Properties.Test_suites, " ")) |
| 297 | } |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 298 | if test.testConfig != nil { |
| 299 | fmt.Fprintln(w, "LOCAL_FULL_TEST_CONFIG :=", test.testConfig.String()) |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 300 | } |
Colin Cross | a929db0 | 2017-03-27 16:27:50 -0700 | [diff] [blame] | 301 | }) |
| 302 | |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 303 | androidMkWriteTestData(test.data, ctx, ret) |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 306 | func (fuzz *fuzzBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 307 | ctx.subAndroidMk(ret, fuzz.binaryDecorator) |
| 308 | |
| 309 | var fuzzFiles []string |
| 310 | for _, d := range fuzz.corpus { |
Mitch Phillips | 8a2bc0b | 2019-10-17 15:04:01 -0700 | [diff] [blame] | 311 | fuzzFiles = append(fuzzFiles, |
| 312 | filepath.Dir(fuzz.corpusIntermediateDir.String())+":corpus/"+d.Base()) |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | if fuzz.dictionary != nil { |
Mitch Phillips | 8a2bc0b | 2019-10-17 15:04:01 -0700 | [diff] [blame] | 316 | fuzzFiles = append(fuzzFiles, |
| 317 | filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base()) |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | if len(fuzzFiles) > 0 { |
| 321 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 322 | fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(fuzzFiles, " ")) |
| 323 | }) |
| 324 | } |
| 325 | |
| 326 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 327 | fmt.Fprintln(w, "LOCAL_IS_FUZZ_TARGET := true") |
| 328 | }) |
| 329 | } |
| 330 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 331 | func (test *testLibrary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 332 | ctx.subAndroidMk(ret, test.libraryDecorator) |
| 333 | } |
Dan Willemsen | e7932e8 | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 334 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 335 | func (library *toolchainLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 336 | ret.Class = "STATIC_LIBRARIES" |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 337 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 338 | _, suffix, _ := android.SplitFileExt(outputFile.Base()) |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 339 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) |
Dan Willemsen | 7517ed0 | 2016-06-10 17:20:30 -0700 | [diff] [blame] | 340 | }) |
| 341 | } |
| 342 | |
Dan Willemsen | f2c27d7 | 2016-07-13 16:50:22 -0700 | [diff] [blame] | 343 | func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Dan Willemsen | 03ce63e | 2016-09-29 12:17:49 -0700 | [diff] [blame] | 344 | // Soong installation is only supported for host modules. Have Make |
| 345 | // installation trigger Soong installation. |
| 346 | if ctx.Target().Os.Class == android.Host { |
| 347 | ret.OutputFile = android.OptionalPathForPath(installer.path) |
| 348 | } |
| 349 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 350 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 351 | path, file := filepath.Split(installer.path.ToMakePath().String()) |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 352 | stem, suffix, _ := android.SplitFileExt(file) |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 353 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 354 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) |
Colin Cross | bf305de | 2016-03-29 17:32:06 -0700 | [diff] [blame] | 355 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 356 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 357 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 358 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 359 | func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 360 | ret.SubName = ndkLibrarySuffix + "." + c.properties.ApiLevel |
Dan Albert | 705c84b | 2016-08-08 10:45:03 -0700 | [diff] [blame] | 361 | ret.Class = "SHARED_LIBRARIES" |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 362 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 363 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 364 | path, file := filepath.Split(c.installPath.String()) |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 365 | stem, suffix, _ := android.SplitFileExt(file) |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 366 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 367 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) |
| 368 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
Dan Willemsen | 866810d | 2017-04-04 14:13:45 -0700 | [diff] [blame] | 369 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 370 | }) |
| 371 | } |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 372 | |
| 373 | func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 374 | ret.Class = "SHARED_LIBRARIES" |
| 375 | |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 376 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 377 | c.libraryDecorator.androidMkWriteExportedFlags(w) |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 378 | _, _, ext := android.SplitFileExt(outputFile.Base()) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 379 | |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 380 | fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 381 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
| 382 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 383 | fmt.Fprintln(w, "LOCAL_SOONG_TOC :=", c.toc().String()) |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 384 | }) |
| 385 | } |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 386 | |
| 387 | func (c *vndkPrebuiltLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 388 | ret.Class = "SHARED_LIBRARIES" |
| 389 | |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 390 | ret.SubName = c.NameSuffix() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 391 | |
| 392 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 393 | c.libraryDecorator.androidMkWriteExportedFlags(w) |
| 394 | |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 395 | path, file := filepath.Split(c.path.ToMakePath().String()) |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 396 | stem, suffix, ext := android.SplitFileExt(file) |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 397 | fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext) |
| 398 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 399 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 400 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
| 401 | }) |
Colin Cross | 7a6fcbe | 2017-12-06 13:08:00 -0800 | [diff] [blame] | 402 | } |
Dan Albert | 8ba131b | 2017-12-14 13:23:15 -0800 | [diff] [blame] | 403 | |
| 404 | func (c *ndkPrebuiltStlLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 405 | ret.Class = "SHARED_LIBRARIES" |
Dan Albert | 8ba131b | 2017-12-14 13:23:15 -0800 | [diff] [blame] | 406 | } |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 407 | |
| 408 | func (c *vendorPublicLibraryStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 409 | ret.Class = "SHARED_LIBRARIES" |
| 410 | ret.SubName = vendorPublicLibrarySuffix |
| 411 | |
| 412 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 413 | c.libraryDecorator.androidMkWriteExportedFlags(w) |
Ivan Lozano | 022a73b | 2019-09-09 20:29:31 -0700 | [diff] [blame] | 414 | _, _, ext := android.SplitFileExt(outputFile.Base()) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 415 | |
Logan Chien | 031d2b3 | 2018-07-26 00:19:50 +0800 | [diff] [blame] | 416 | fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 417 | fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") |
| 418 | fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true") |
| 419 | }) |
| 420 | } |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 421 | |
| 422 | func (p *prebuiltLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 423 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 424 | if p.properties.Check_elf_files != nil { |
| 425 | fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES :=", *p.properties.Check_elf_files) |
| 426 | } else { |
| 427 | // soong_cc_prebuilt.mk does not include check_elf_file.mk by default |
| 428 | // because cc_library_shared and cc_binary use soong_cc_prebuilt.mk as well. |
| 429 | // In order to turn on prebuilt ABI checker, set `LOCAL_CHECK_ELF_FILES` to |
| 430 | // true if `p.properties.Check_elf_files` is not specified. |
| 431 | fmt.Fprintln(w, "LOCAL_CHECK_ELF_FILES := true") |
| 432 | } |
| 433 | }) |
| 434 | } |
| 435 | |
| 436 | func (p *prebuiltLibraryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 437 | ctx.subAndroidMk(ret, p.libraryDecorator) |
| 438 | if p.shared() { |
| 439 | ctx.subAndroidMk(ret, &p.prebuiltLinker) |
| 440 | androidMkWriteAllowUndefinedSymbols(p.baseLinker, ret) |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | func (p *prebuiltBinaryLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
| 445 | ctx.subAndroidMk(ret, p.binaryDecorator) |
| 446 | ctx.subAndroidMk(ret, &p.prebuiltLinker) |
| 447 | androidMkWriteAllowUndefinedSymbols(p.baseLinker, ret) |
| 448 | } |
| 449 | |
| 450 | func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, ret *android.AndroidMkData) { |
| 451 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
| 452 | allow := linker.Properties.Allow_undefined_symbols |
| 453 | if allow != nil { |
| 454 | fmt.Fprintln(w, "LOCAL_ALLOW_UNDEFINED_SYMBOLS :=", *allow) |
| 455 | } |
| 456 | }) |
| 457 | } |