blob: 10c85087d2f65f5d57c706a571eb2d4b8a0b540b [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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
17// This file generates the final rules for compiling all C/C++. All properties related to
18// compiling should have been translated into builderFlags or another argument to the Transform*
19// functions.
20
21import (
22 "android/soong/common"
Colin Cross0af4b842015-04-30 16:36:18 -070023 "fmt"
24 "runtime"
25 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080026
Colin Cross3f40fa42015-01-30 17:27:36 -080027 "path/filepath"
28 "strings"
Colin Crossed4cf0b2015-03-26 14:43:45 -070029
30 "github.com/google/blueprint"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
33const (
Dan Albertc3144b12015-04-28 18:17:56 -070034 objectExtension = ".o"
Colin Cross3f40fa42015-01-30 17:27:36 -080035 staticLibraryExtension = ".a"
36)
37
38var (
Dan Willemsen34cc69e2015-09-23 15:26:20 -070039 pctx = common.NewPackageContext("android/soong/cc")
Colin Cross3f40fa42015-01-30 17:27:36 -080040
41 cc = pctx.StaticRule("cc",
42 blueprint.RuleParams{
43 Depfile: "${out}.d",
44 Deps: blueprint.DepsGCC,
Dan Willemsene6540452015-10-20 15:21:33 -070045 Command: "$relPwd $ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080046 CommandDeps: []string{"$ccCmd"},
Colin Cross3f40fa42015-01-30 17:27:36 -080047 Description: "cc $out",
48 },
Dan Willemsen322a0a62015-11-17 15:19:46 -080049 "ccCmd", "cFlags")
Colin Cross3f40fa42015-01-30 17:27:36 -080050
51 ld = pctx.StaticRule("ld",
52 blueprint.RuleParams{
Colin Cross7d21c442015-03-30 17:47:53 -070053 Command: "$ldCmd ${ldDirFlags} ${crtBegin} @${out}.rsp " +
Colin Cross28344522015-04-22 13:07:53 -070054 "${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
Dan Willemsenc94a7682015-11-17 15:27:28 -080055 CommandDeps: []string{"$ldCmd"},
Colin Cross7d21c442015-03-30 17:47:53 -070056 Description: "ld $out",
57 Rspfile: "${out}.rsp",
58 RspfileContent: "${in}",
Colin Cross3f40fa42015-01-30 17:27:36 -080059 },
Colin Cross28344522015-04-22 13:07:53 -070060 "ldCmd", "ldDirFlags", "crtBegin", "libFlags", "crtEnd", "ldFlags")
Colin Cross3f40fa42015-01-30 17:27:36 -080061
62 partialLd = pctx.StaticRule("partialLd",
63 blueprint.RuleParams{
Colin Cross41280a42015-11-23 14:01:42 -080064 Command: "$ldCmd -nostdlib -Wl,-r ${in} -o ${out} ${ldFlags}",
Dan Willemsenc94a7682015-11-17 15:27:28 -080065 CommandDeps: []string{"$ldCmd"},
Colin Cross3f40fa42015-01-30 17:27:36 -080066 Description: "partialLd $out",
67 },
Colin Cross41280a42015-11-23 14:01:42 -080068 "ldCmd", "ldFlags")
Colin Cross3f40fa42015-01-30 17:27:36 -080069
70 ar = pctx.StaticRule("ar",
71 blueprint.RuleParams{
Colin Cross7d21c442015-03-30 17:47:53 -070072 Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp",
Dan Willemsenc94a7682015-11-17 15:27:28 -080073 CommandDeps: []string{"$arCmd"},
Colin Cross7d21c442015-03-30 17:47:53 -070074 Description: "ar $out",
75 Rspfile: "${out}.rsp",
76 RspfileContent: "${in}",
Colin Cross3f40fa42015-01-30 17:27:36 -080077 },
78 "arCmd", "arFlags")
79
Colin Cross0af4b842015-04-30 16:36:18 -070080 darwinAr = pctx.StaticRule("darwinAr",
81 blueprint.RuleParams{
82 Command: "rm -f ${out} && $arCmd $arFlags $out $in",
Dan Willemsenc94a7682015-11-17 15:27:28 -080083 CommandDeps: []string{"$arCmd"},
Colin Cross0af4b842015-04-30 16:36:18 -070084 Description: "ar $out",
85 },
86 "arCmd", "arFlags")
87
88 darwinAppendAr = pctx.StaticRule("darwinAppendAr",
89 blueprint.RuleParams{
90 Command: "cp -f ${inAr} ${out}.tmp && $arCmd $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}",
Dan Willemsenc94a7682015-11-17 15:27:28 -080091 CommandDeps: []string{"$arCmd"},
Colin Cross0af4b842015-04-30 16:36:18 -070092 Description: "ar $out",
93 },
94 "arCmd", "arFlags", "inAr")
95
Colin Crossbfae8852015-03-26 14:44:11 -070096 prefixSymbols = pctx.StaticRule("prefixSymbols",
97 blueprint.RuleParams{
98 Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}",
Dan Willemsenc94a7682015-11-17 15:27:28 -080099 CommandDeps: []string{"$objcopyCmd"},
Colin Crossbfae8852015-03-26 14:44:11 -0700100 Description: "prefixSymbols $out",
101 },
102 "objcopyCmd", "prefix")
103
Colin Cross665dce92016-04-28 14:50:03 -0700104 stripPath = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
105
106 strip = pctx.StaticRule("strip",
107 blueprint.RuleParams{
108 Depfile: "${out}.d",
109 Deps: blueprint.DepsGCC,
110 Command: "CROSS_COMPILE=$crossCompile $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
111 CommandDeps: []string{"$stripPath"},
112 Description: "strip $out",
113 },
114 "args", "crossCompile")
115
Colin Cross14747412016-04-27 16:10:38 -0700116 copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
Colin Cross3f40fa42015-01-30 17:27:36 -0800117
118 copyGccLib = pctx.StaticRule("copyGccLib",
119 blueprint.RuleParams{
120 Depfile: "${out}.d",
121 Deps: blueprint.DepsGCC,
122 Command: "$copyGccLibPath $out $ccCmd $cFlags -print-file-name=${libName}",
Dan Willemsenc94a7682015-11-17 15:27:28 -0800123 CommandDeps: []string{"$copyGccLibPath", "$ccCmd"},
Colin Cross3f40fa42015-01-30 17:27:36 -0800124 Description: "copy gcc $out",
125 },
126 "ccCmd", "cFlags", "libName")
127)
128
Dan Willemsen322a0a62015-11-17 15:19:46 -0800129func init() {
130 // We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the
131 // debug output. That way two builds in two different directories will
132 // create the same output.
133 if runtime.GOOS != "darwin" {
134 pctx.StaticVariable("relPwd", "PWD=/proc/self/cwd")
135 } else {
136 // Darwin doesn't have /proc
137 pctx.StaticVariable("relPwd", "")
138 }
139}
140
Colin Cross3f40fa42015-01-30 17:27:36 -0800141type builderFlags struct {
142 globalFlags string
143 asFlags string
144 cFlags string
145 conlyFlags string
146 cppFlags string
147 ldFlags string
Colin Cross16b23492016-01-06 14:41:07 -0800148 libFlags string
Colin Cross581c1892015-04-07 16:50:10 -0700149 yaccFlags string
Colin Cross3f40fa42015-01-30 17:27:36 -0800150 nocrt bool
Colin Cross97ba0732015-03-23 17:50:24 -0700151 toolchain Toolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800152 clang bool
Colin Cross665dce92016-04-28 14:50:03 -0700153
154 stripKeepSymbols bool
155 stripKeepMiniDebugInfo bool
156 stripAddGnuDebuglink bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800157}
158
159// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700160func TransformSourceToObj(ctx common.AndroidModuleContext, subdir string, srcFiles common.Paths,
161 flags builderFlags, deps common.Paths) (objFiles common.Paths) {
Colin Cross581c1892015-04-07 16:50:10 -0700162
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700163 objFiles = make(common.Paths, len(srcFiles))
Colin Cross3f40fa42015-01-30 17:27:36 -0800164
165 cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
166 cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
167 asflags := flags.globalFlags + " " + flags.asFlags
168
Dan Willemsenbe03f342016-03-03 17:21:04 -0800169 if flags.clang {
170 cflags += " ${noOverrideClangGlobalCflags}"
171 cppflags += " ${noOverrideClangGlobalCflags}"
172 } else {
173 cflags += " ${noOverrideGlobalCflags}"
174 cppflags += " ${noOverrideGlobalCflags}"
175 }
176
Colin Cross3f40fa42015-01-30 17:27:36 -0800177 for i, srcFile := range srcFiles {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700178 objFile := common.ObjPathWithExt(ctx, srcFile, subdir, "o")
Colin Cross3f40fa42015-01-30 17:27:36 -0800179
180 objFiles[i] = objFile
181
182 var moduleCflags string
183 var ccCmd string
184
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700185 switch srcFile.Ext() {
Colin Cross3f40fa42015-01-30 17:27:36 -0800186 case ".S", ".s":
187 ccCmd = "gcc"
188 moduleCflags = asflags
189 case ".c":
190 ccCmd = "gcc"
191 moduleCflags = cflags
192 case ".cpp", ".cc":
193 ccCmd = "g++"
194 moduleCflags = cppflags
195 default:
196 ctx.ModuleErrorf("File %s has unknown extension", srcFile)
197 continue
198 }
199
200 if flags.clang {
201 switch ccCmd {
202 case "gcc":
203 ccCmd = "clang"
204 case "g++":
205 ccCmd = "clang++"
206 default:
207 panic("unrecoginzied ccCmd")
208 }
209
Colin Cross16b23492016-01-06 14:41:07 -0800210 ccCmd = "${clangBin}/" + ccCmd
Colin Cross3f40fa42015-01-30 17:27:36 -0800211 } else {
212 ccCmd = gccCmd(flags.toolchain, ccCmd)
213 }
214
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700215 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
Colin Cross3f40fa42015-01-30 17:27:36 -0800216 Rule: cc,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700217 Output: objFile,
218 Input: srcFile,
Dan Willemsenb40aab62016-04-20 14:21:14 -0700219 OrderOnly: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800220 Args: map[string]string{
Colin Cross28344522015-04-22 13:07:53 -0700221 "cFlags": moduleCflags,
222 "ccCmd": ccCmd,
Colin Cross3f40fa42015-01-30 17:27:36 -0800223 },
224 })
225 }
226
227 return objFiles
228}
229
230// Generate a rule for compiling multiple .o files to a static library (.a)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700231func TransformObjToStaticLib(ctx common.AndroidModuleContext, objFiles common.Paths,
232 flags builderFlags, outputFile common.ModuleOutPath) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800233
234 arCmd := gccCmd(flags.toolchain, "ar")
235 arFlags := "crsPD"
236
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700237 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
238 Rule: ar,
239 Output: outputFile,
240 Inputs: objFiles,
Colin Cross3f40fa42015-01-30 17:27:36 -0800241 Args: map[string]string{
242 "arFlags": arFlags,
243 "arCmd": arCmd,
244 },
245 })
246}
247
Colin Cross0af4b842015-04-30 16:36:18 -0700248// Generate a rule for compiling multiple .o files to a static library (.a) on
249// darwin. The darwin ar tool doesn't support @file for list files, and has a
250// very small command line length limit, so we have to split the ar into multiple
251// steps, each appending to the previous one.
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700252func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles common.Paths,
253 flags builderFlags, outputPath common.ModuleOutPath) {
Colin Cross0af4b842015-04-30 16:36:18 -0700254
Dan Willemsencf7c71b2015-12-14 20:02:44 -0800255 arCmd := "${macArPath}"
Colin Cross0af4b842015-04-30 16:36:18 -0700256 arFlags := "cqs"
257
258 // ARG_MAX on darwin is 262144, use half that to be safe
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700259 objFilesLists, err := splitListForSize(objFiles.Strings(), 131072)
Colin Cross0af4b842015-04-30 16:36:18 -0700260 if err != nil {
261 ctx.ModuleErrorf("%s", err.Error())
262 }
263
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700264 outputFile := outputPath.String()
265
Colin Cross0af4b842015-04-30 16:36:18 -0700266 var in, out string
267 for i, l := range objFilesLists {
268 in = out
269 out = outputFile
270 if i != len(objFilesLists)-1 {
271 out += "." + strconv.Itoa(i)
272 }
273
274 if in == "" {
275 ctx.Build(pctx, blueprint.BuildParams{
276 Rule: darwinAr,
277 Outputs: []string{out},
278 Inputs: l,
279 Args: map[string]string{
280 "arFlags": arFlags,
281 "arCmd": arCmd,
282 },
283 })
284 } else {
285 ctx.Build(pctx, blueprint.BuildParams{
286 Rule: darwinAppendAr,
287 Outputs: []string{out},
288 Inputs: l,
289 Implicits: []string{in},
290 Args: map[string]string{
291 "arFlags": arFlags,
292 "arCmd": arCmd,
293 "inAr": in,
294 },
295 })
296 }
297 }
298}
299
Colin Cross3f40fa42015-01-30 17:27:36 -0800300// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
301// and shared libraires, to a shared library (.so) or dynamic executable
302func TransformObjToDynamicBinary(ctx common.AndroidModuleContext,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700303 objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps common.Paths,
304 crtBegin, crtEnd common.OptionalPath, groupLate bool, flags builderFlags, outputFile common.WritablePath) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800305
306 var ldCmd string
307 if flags.clang {
Colin Cross16b23492016-01-06 14:41:07 -0800308 ldCmd = "${clangBin}/clang++"
Colin Cross3f40fa42015-01-30 17:27:36 -0800309 } else {
310 ldCmd = gccCmd(flags.toolchain, "g++")
311 }
312
313 var ldDirs []string
314 var libFlagsList []string
315
Colin Cross16b23492016-01-06 14:41:07 -0800316 if len(flags.libFlags) > 0 {
317 libFlagsList = append(libFlagsList, flags.libFlags)
318 }
319
Colin Cross3f40fa42015-01-30 17:27:36 -0800320 if len(wholeStaticLibs) > 0 {
Dan Willemsen490fd492015-11-24 17:53:15 -0800321 if ctx.Host() && ctx.Darwin() {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700322 libFlagsList = append(libFlagsList, common.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load "))
Colin Cross0af4b842015-04-30 16:36:18 -0700323 } else {
324 libFlagsList = append(libFlagsList, "-Wl,--whole-archive ")
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700325 libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...)
Colin Cross0af4b842015-04-30 16:36:18 -0700326 libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ")
327 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800328 }
329
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700330 libFlagsList = append(libFlagsList, staticLibs.Strings()...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800331
Dan Willemsenedc385f2015-07-08 13:02:23 -0700332 if groupLate && len(lateStaticLibs) > 0 {
333 libFlagsList = append(libFlagsList, "-Wl,--start-group")
334 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700335 libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...)
Dan Willemsenedc385f2015-07-08 13:02:23 -0700336 if groupLate && len(lateStaticLibs) > 0 {
337 libFlagsList = append(libFlagsList, "-Wl,--end-group")
338 }
339
Colin Cross3f40fa42015-01-30 17:27:36 -0800340 for _, lib := range sharedLibs {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700341 dir, file := filepath.Split(lib.String())
Colin Cross3f40fa42015-01-30 17:27:36 -0800342 if !strings.HasPrefix(file, "lib") {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700343 panic("shared library " + lib.String() + " does not start with lib")
Colin Cross3f40fa42015-01-30 17:27:36 -0800344 }
Dan Willemsen490fd492015-11-24 17:53:15 -0800345 if !strings.HasSuffix(file, flags.toolchain.ShlibSuffix()) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700346 panic("shared library " + lib.String() + " does not end with " + flags.toolchain.ShlibSuffix())
Colin Cross3f40fa42015-01-30 17:27:36 -0800347 }
348 libFlagsList = append(libFlagsList,
Dan Willemsen490fd492015-11-24 17:53:15 -0800349 "-l"+strings.TrimSuffix(strings.TrimPrefix(file, "lib"), flags.toolchain.ShlibSuffix()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800350 ldDirs = append(ldDirs, dir)
351 }
352
Colin Cross3f40fa42015-01-30 17:27:36 -0800353 deps = append(deps, sharedLibs...)
354 deps = append(deps, staticLibs...)
Colin Cross3075ad02015-03-17 10:47:08 -0700355 deps = append(deps, lateStaticLibs...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800356 deps = append(deps, wholeStaticLibs...)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700357 if crtBegin.Valid() {
358 deps = append(deps, crtBegin.Path(), crtEnd.Path())
Colin Cross3f40fa42015-01-30 17:27:36 -0800359 }
360
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700361 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
Colin Cross3f40fa42015-01-30 17:27:36 -0800362 Rule: ld,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700363 Output: outputFile,
Colin Cross3f40fa42015-01-30 17:27:36 -0800364 Inputs: objFiles,
365 Implicits: deps,
366 Args: map[string]string{
367 "ldCmd": ldCmd,
368 "ldDirFlags": ldDirsToFlags(ldDirs),
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700369 "crtBegin": crtBegin.String(),
Colin Cross3f40fa42015-01-30 17:27:36 -0800370 "libFlags": strings.Join(libFlagsList, " "),
371 "ldFlags": flags.ldFlags,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700372 "crtEnd": crtEnd.String(),
Colin Cross3f40fa42015-01-30 17:27:36 -0800373 },
374 })
375}
376
377// Generate a rule for compiling multiple .o files to a .o using ld partial linking
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700378func TransformObjsToObj(ctx common.AndroidModuleContext, objFiles common.Paths,
379 flags builderFlags, outputFile common.WritablePath) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800380
Colin Cross41280a42015-11-23 14:01:42 -0800381 var ldCmd string
382 if flags.clang {
Colin Cross16b23492016-01-06 14:41:07 -0800383 ldCmd = "${clangBin}clang++"
Colin Cross41280a42015-11-23 14:01:42 -0800384 } else {
385 ldCmd = gccCmd(flags.toolchain, "g++")
386 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800387
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700388 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
389 Rule: partialLd,
390 Output: outputFile,
391 Inputs: objFiles,
Colin Cross3f40fa42015-01-30 17:27:36 -0800392 Args: map[string]string{
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700393 "ldCmd": ldCmd,
Colin Cross41280a42015-11-23 14:01:42 -0800394 "ldFlags": flags.ldFlags,
Colin Cross3f40fa42015-01-30 17:27:36 -0800395 },
396 })
397}
398
Colin Crossbfae8852015-03-26 14:44:11 -0700399// Generate a rule for runing objcopy --prefix-symbols on a binary
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700400func TransformBinaryPrefixSymbols(ctx common.AndroidModuleContext, prefix string, inputFile common.Path,
401 flags builderFlags, outputFile common.WritablePath) {
Colin Crossbfae8852015-03-26 14:44:11 -0700402
403 objcopyCmd := gccCmd(flags.toolchain, "objcopy")
404
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700405 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
406 Rule: prefixSymbols,
407 Output: outputFile,
408 Input: inputFile,
Colin Crossbfae8852015-03-26 14:44:11 -0700409 Args: map[string]string{
410 "objcopyCmd": objcopyCmd,
411 "prefix": prefix,
412 },
413 })
414}
415
Colin Cross665dce92016-04-28 14:50:03 -0700416func TransformStrip(ctx common.AndroidModuleContext, inputFile common.Path,
417 outputFile common.WritablePath, flags builderFlags) {
418
419 crossCompile := gccCmd(flags.toolchain, "")
420 args := ""
421 if flags.stripAddGnuDebuglink {
422 args += " --add-gnu-debuglink"
423 }
424 if flags.stripKeepMiniDebugInfo {
425 args += " --keep-mini-debug-info"
426 }
427 if flags.stripKeepSymbols {
428 args += " --keep-symbols"
429 }
430
431 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
432 Rule: strip,
433 Output: outputFile,
434 Input: inputFile,
435 Args: map[string]string{
436 "crossCompile": crossCompile,
437 "args": args,
438 },
439 })
440}
441
Colin Cross3f40fa42015-01-30 17:27:36 -0800442func CopyGccLib(ctx common.AndroidModuleContext, libName string,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700443 flags builderFlags, outputFile common.WritablePath) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800444
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700445 ctx.ModuleBuild(pctx, common.ModuleBuildParams{
446 Rule: copyGccLib,
447 Output: outputFile,
Colin Cross3f40fa42015-01-30 17:27:36 -0800448 Args: map[string]string{
449 "ccCmd": gccCmd(flags.toolchain, "gcc"),
450 "cFlags": flags.globalFlags,
451 "libName": libName,
452 },
453 })
454}
455
Colin Cross97ba0732015-03-23 17:50:24 -0700456func gccCmd(toolchain Toolchain, cmd string) string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800457 return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
458}
Colin Cross0af4b842015-04-30 16:36:18 -0700459
460func splitListForSize(list []string, limit int) (lists [][]string, err error) {
461 var i int
462
463 start := 0
464 bytes := 0
465 for i = range list {
466 l := len(list[i])
467 if l > limit {
468 return nil, fmt.Errorf("list element greater than size limit (%d)", limit)
469 }
470 if bytes+l > limit {
471 lists = append(lists, list[start:i])
472 start = i
473 bytes = 0
474 }
475 bytes += l + 1 // count a space between each list element
476 }
477
478 lists = append(lists, list[start:])
479
480 totalLen := 0
481 for _, l := range lists {
482 totalLen += len(l)
483 }
484 if totalLen != len(list) {
485 panic(fmt.Errorf("Failed breaking up list, %d != %d", len(list), totalLen))
486 }
487 return lists, nil
488}