2015-01-31 09:27:36 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
// This file generates the final rules for compiling all C/C++. All properties related to
|
|
|
|
// compiling should have been translated into builderFlags or another argument to the Transform*
|
|
|
|
// functions.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/common"
|
2015-05-01 07:36:18 +08:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"strconv"
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2015-03-27 05:43:45 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2015-01-31 09:27:36 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-04-29 09:17:56 +08:00
|
|
|
objectExtension = ".o"
|
2015-01-31 09:27:36 +08:00
|
|
|
staticLibraryExtension = ".a"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-09-24 06:26:20 +08:00
|
|
|
pctx = common.NewPackageContext("android/soong/cc")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
cc = pctx.StaticRule("cc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
2015-10-21 06:21:33 +08:00
|
|
|
Command: "$relPwd $ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$ccCmd"},
|
2015-01-31 09:27:36 +08:00
|
|
|
Description: "cc $out",
|
|
|
|
},
|
2015-11-18 07:19:46 +08:00
|
|
|
"ccCmd", "cFlags")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
ld = pctx.StaticRule("ld",
|
|
|
|
blueprint.RuleParams{
|
2015-03-31 08:47:53 +08:00
|
|
|
Command: "$ldCmd ${ldDirFlags} ${crtBegin} @${out}.rsp " +
|
2015-04-23 04:07:53 +08:00
|
|
|
"${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$ldCmd"},
|
2015-03-31 08:47:53 +08:00
|
|
|
Description: "ld $out",
|
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
2015-04-23 04:07:53 +08:00
|
|
|
"ldCmd", "ldDirFlags", "crtBegin", "libFlags", "crtEnd", "ldFlags")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
partialLd = pctx.StaticRule("partialLd",
|
|
|
|
blueprint.RuleParams{
|
2015-11-24 06:01:42 +08:00
|
|
|
Command: "$ldCmd -nostdlib -Wl,-r ${in} -o ${out} ${ldFlags}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$ldCmd"},
|
2015-01-31 09:27:36 +08:00
|
|
|
Description: "partialLd $out",
|
|
|
|
},
|
2015-11-24 06:01:42 +08:00
|
|
|
"ldCmd", "ldFlags")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
ar = pctx.StaticRule("ar",
|
|
|
|
blueprint.RuleParams{
|
2015-03-31 08:47:53 +08:00
|
|
|
Command: "rm -f ${out} && $arCmd $arFlags $out @${out}.rsp",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$arCmd"},
|
2015-03-31 08:47:53 +08:00
|
|
|
Description: "ar $out",
|
|
|
|
Rspfile: "${out}.rsp",
|
|
|
|
RspfileContent: "${in}",
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
"arCmd", "arFlags")
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
darwinAr = pctx.StaticRule("darwinAr",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "rm -f ${out} && $arCmd $arFlags $out $in",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$arCmd"},
|
2015-05-01 07:36:18 +08:00
|
|
|
Description: "ar $out",
|
|
|
|
},
|
|
|
|
"arCmd", "arFlags")
|
|
|
|
|
|
|
|
darwinAppendAr = pctx.StaticRule("darwinAppendAr",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "cp -f ${inAr} ${out}.tmp && $arCmd $arFlags ${out}.tmp $in && mv ${out}.tmp ${out}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$arCmd"},
|
2015-05-01 07:36:18 +08:00
|
|
|
Description: "ar $out",
|
|
|
|
},
|
|
|
|
"arCmd", "arFlags", "inAr")
|
|
|
|
|
2015-03-27 05:44:11 +08:00
|
|
|
prefixSymbols = pctx.StaticRule("prefixSymbols",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$objcopyCmd --prefix-symbols=${prefix} ${in} ${out}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$objcopyCmd"},
|
2015-03-27 05:44:11 +08:00
|
|
|
Description: "prefixSymbols $out",
|
|
|
|
},
|
|
|
|
"objcopyCmd", "prefix")
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/copygcclib.sh")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
copyGccLib = pctx.StaticRule("copyGccLib",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
Command: "$copyGccLibPath $out $ccCmd $cFlags -print-file-name=${libName}",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$copyGccLibPath", "$ccCmd"},
|
2015-01-31 09:27:36 +08:00
|
|
|
Description: "copy gcc $out",
|
|
|
|
},
|
|
|
|
"ccCmd", "cFlags", "libName")
|
|
|
|
)
|
|
|
|
|
2015-11-18 07:19:46 +08:00
|
|
|
func init() {
|
|
|
|
// We run gcc/clang with PWD=/proc/self/cwd to remove $TOP from the
|
|
|
|
// debug output. That way two builds in two different directories will
|
|
|
|
// create the same output.
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
pctx.StaticVariable("relPwd", "PWD=/proc/self/cwd")
|
|
|
|
} else {
|
|
|
|
// Darwin doesn't have /proc
|
|
|
|
pctx.StaticVariable("relPwd", "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
type builderFlags struct {
|
|
|
|
globalFlags string
|
|
|
|
asFlags string
|
|
|
|
cFlags string
|
|
|
|
conlyFlags string
|
|
|
|
cppFlags string
|
|
|
|
ldFlags string
|
2016-01-07 06:41:07 +08:00
|
|
|
libFlags string
|
2015-04-08 07:50:10 +08:00
|
|
|
yaccFlags string
|
2015-01-31 09:27:36 +08:00
|
|
|
nocrt bool
|
2015-03-24 08:50:24 +08:00
|
|
|
toolchain Toolchain
|
2015-01-31 09:27:36 +08:00
|
|
|
clang bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
|
2015-09-24 06:26:20 +08:00
|
|
|
func TransformSourceToObj(ctx common.AndroidModuleContext, subdir string, srcFiles common.Paths,
|
|
|
|
flags builderFlags, deps common.Paths) (objFiles common.Paths) {
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
objFiles = make(common.Paths, len(srcFiles))
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
|
|
|
|
cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
|
|
|
|
asflags := flags.globalFlags + " " + flags.asFlags
|
|
|
|
|
2016-03-04 09:21:04 +08:00
|
|
|
if flags.clang {
|
|
|
|
cflags += " ${noOverrideClangGlobalCflags}"
|
|
|
|
cppflags += " ${noOverrideClangGlobalCflags}"
|
|
|
|
} else {
|
|
|
|
cflags += " ${noOverrideGlobalCflags}"
|
|
|
|
cppflags += " ${noOverrideGlobalCflags}"
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
for i, srcFile := range srcFiles {
|
2015-09-24 06:26:20 +08:00
|
|
|
objFile := common.ObjPathWithExt(ctx, srcFile, subdir, "o")
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
objFiles[i] = objFile
|
|
|
|
|
|
|
|
var moduleCflags string
|
|
|
|
var ccCmd string
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
switch srcFile.Ext() {
|
2015-01-31 09:27:36 +08:00
|
|
|
case ".S", ".s":
|
|
|
|
ccCmd = "gcc"
|
|
|
|
moduleCflags = asflags
|
|
|
|
case ".c":
|
|
|
|
ccCmd = "gcc"
|
|
|
|
moduleCflags = cflags
|
|
|
|
case ".cpp", ".cc":
|
|
|
|
ccCmd = "g++"
|
|
|
|
moduleCflags = cppflags
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("File %s has unknown extension", srcFile)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if flags.clang {
|
|
|
|
switch ccCmd {
|
|
|
|
case "gcc":
|
|
|
|
ccCmd = "clang"
|
|
|
|
case "g++":
|
|
|
|
ccCmd = "clang++"
|
|
|
|
default:
|
|
|
|
panic("unrecoginzied ccCmd")
|
|
|
|
}
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
ccCmd = "${clangBin}/" + ccCmd
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
|
|
|
ccCmd = gccCmd(flags.toolchain, ccCmd)
|
|
|
|
}
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
2015-01-31 09:27:36 +08:00
|
|
|
Rule: cc,
|
2015-09-24 06:26:20 +08:00
|
|
|
Output: objFile,
|
|
|
|
Input: srcFile,
|
2016-04-21 05:21:14 +08:00
|
|
|
OrderOnly: deps,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
2015-04-23 04:07:53 +08:00
|
|
|
"cFlags": moduleCflags,
|
|
|
|
"ccCmd": ccCmd,
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return objFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a rule for compiling multiple .o files to a static library (.a)
|
2015-09-24 06:26:20 +08:00
|
|
|
func TransformObjToStaticLib(ctx common.AndroidModuleContext, objFiles common.Paths,
|
|
|
|
flags builderFlags, outputFile common.ModuleOutPath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
arCmd := gccCmd(flags.toolchain, "ar")
|
|
|
|
arFlags := "crsPD"
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
|
|
|
Rule: ar,
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": arFlags,
|
|
|
|
"arCmd": arCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
// Generate a rule for compiling multiple .o files to a static library (.a) on
|
|
|
|
// darwin. The darwin ar tool doesn't support @file for list files, and has a
|
|
|
|
// very small command line length limit, so we have to split the ar into multiple
|
|
|
|
// steps, each appending to the previous one.
|
2015-09-24 06:26:20 +08:00
|
|
|
func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles common.Paths,
|
|
|
|
flags builderFlags, outputPath common.ModuleOutPath) {
|
2015-05-01 07:36:18 +08:00
|
|
|
|
2015-12-15 12:02:44 +08:00
|
|
|
arCmd := "${macArPath}"
|
2015-05-01 07:36:18 +08:00
|
|
|
arFlags := "cqs"
|
|
|
|
|
|
|
|
// ARG_MAX on darwin is 262144, use half that to be safe
|
2015-09-24 06:26:20 +08:00
|
|
|
objFilesLists, err := splitListForSize(objFiles.Strings(), 131072)
|
2015-05-01 07:36:18 +08:00
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("%s", err.Error())
|
|
|
|
}
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
outputFile := outputPath.String()
|
|
|
|
|
2015-05-01 07:36:18 +08:00
|
|
|
var in, out string
|
|
|
|
for i, l := range objFilesLists {
|
|
|
|
in = out
|
|
|
|
out = outputFile
|
|
|
|
if i != len(objFilesLists)-1 {
|
|
|
|
out += "." + strconv.Itoa(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
if in == "" {
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: darwinAr,
|
|
|
|
Outputs: []string{out},
|
|
|
|
Inputs: l,
|
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": arFlags,
|
|
|
|
"arCmd": arCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: darwinAppendAr,
|
|
|
|
Outputs: []string{out},
|
|
|
|
Inputs: l,
|
|
|
|
Implicits: []string{in},
|
|
|
|
Args: map[string]string{
|
|
|
|
"arFlags": arFlags,
|
|
|
|
"arCmd": arCmd,
|
|
|
|
"inAr": in,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
|
|
|
|
// and shared libraires, to a shared library (.so) or dynamic executable
|
|
|
|
func TransformObjToDynamicBinary(ctx common.AndroidModuleContext,
|
2015-09-24 06:26:20 +08:00
|
|
|
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps common.Paths,
|
|
|
|
crtBegin, crtEnd common.OptionalPath, groupLate bool, flags builderFlags, outputFile common.WritablePath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
|
|
|
var ldCmd string
|
|
|
|
if flags.clang {
|
2016-01-07 06:41:07 +08:00
|
|
|
ldCmd = "${clangBin}/clang++"
|
2015-01-31 09:27:36 +08:00
|
|
|
} else {
|
|
|
|
ldCmd = gccCmd(flags.toolchain, "g++")
|
|
|
|
}
|
|
|
|
|
|
|
|
var ldDirs []string
|
|
|
|
var libFlagsList []string
|
|
|
|
|
2016-01-07 06:41:07 +08:00
|
|
|
if len(flags.libFlags) > 0 {
|
|
|
|
libFlagsList = append(libFlagsList, flags.libFlags)
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
if len(wholeStaticLibs) > 0 {
|
2015-11-25 09:53:15 +08:00
|
|
|
if ctx.Host() && ctx.Darwin() {
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, common.JoinWithPrefix(wholeStaticLibs.Strings(), "-force_load "))
|
2015-05-01 07:36:18 +08:00
|
|
|
} else {
|
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--whole-archive ")
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, wholeStaticLibs.Strings()...)
|
2015-05-01 07:36:18 +08:00
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--no-whole-archive ")
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, staticLibs.Strings()...)
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-07-09 04:02:23 +08:00
|
|
|
if groupLate && len(lateStaticLibs) > 0 {
|
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--start-group")
|
|
|
|
}
|
2015-09-24 06:26:20 +08:00
|
|
|
libFlagsList = append(libFlagsList, lateStaticLibs.Strings()...)
|
2015-07-09 04:02:23 +08:00
|
|
|
if groupLate && len(lateStaticLibs) > 0 {
|
|
|
|
libFlagsList = append(libFlagsList, "-Wl,--end-group")
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
for _, lib := range sharedLibs {
|
2015-09-24 06:26:20 +08:00
|
|
|
dir, file := filepath.Split(lib.String())
|
2015-01-31 09:27:36 +08:00
|
|
|
if !strings.HasPrefix(file, "lib") {
|
2015-09-24 06:26:20 +08:00
|
|
|
panic("shared library " + lib.String() + " does not start with lib")
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
2015-11-25 09:53:15 +08:00
|
|
|
if !strings.HasSuffix(file, flags.toolchain.ShlibSuffix()) {
|
2015-09-24 06:26:20 +08:00
|
|
|
panic("shared library " + lib.String() + " does not end with " + flags.toolchain.ShlibSuffix())
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
libFlagsList = append(libFlagsList,
|
2015-11-25 09:53:15 +08:00
|
|
|
"-l"+strings.TrimSuffix(strings.TrimPrefix(file, "lib"), flags.toolchain.ShlibSuffix()))
|
2015-01-31 09:27:36 +08:00
|
|
|
ldDirs = append(ldDirs, dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
deps = append(deps, sharedLibs...)
|
|
|
|
deps = append(deps, staticLibs...)
|
2015-03-18 01:47:08 +08:00
|
|
|
deps = append(deps, lateStaticLibs...)
|
2015-01-31 09:27:36 +08:00
|
|
|
deps = append(deps, wholeStaticLibs...)
|
2015-09-24 06:26:20 +08:00
|
|
|
if crtBegin.Valid() {
|
|
|
|
deps = append(deps, crtBegin.Path(), crtEnd.Path())
|
2015-01-31 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
2015-01-31 09:27:36 +08:00
|
|
|
Rule: ld,
|
2015-09-24 06:26:20 +08:00
|
|
|
Output: outputFile,
|
2015-01-31 09:27:36 +08:00
|
|
|
Inputs: objFiles,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"ldCmd": ldCmd,
|
|
|
|
"ldDirFlags": ldDirsToFlags(ldDirs),
|
2015-09-24 06:26:20 +08:00
|
|
|
"crtBegin": crtBegin.String(),
|
2015-01-31 09:27:36 +08:00
|
|
|
"libFlags": strings.Join(libFlagsList, " "),
|
|
|
|
"ldFlags": flags.ldFlags,
|
2015-09-24 06:26:20 +08:00
|
|
|
"crtEnd": crtEnd.String(),
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a rule for compiling multiple .o files to a .o using ld partial linking
|
2015-09-24 06:26:20 +08:00
|
|
|
func TransformObjsToObj(ctx common.AndroidModuleContext, objFiles common.Paths,
|
|
|
|
flags builderFlags, outputFile common.WritablePath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-11-24 06:01:42 +08:00
|
|
|
var ldCmd string
|
|
|
|
if flags.clang {
|
2016-01-07 06:41:07 +08:00
|
|
|
ldCmd = "${clangBin}clang++"
|
2015-11-24 06:01:42 +08:00
|
|
|
} else {
|
|
|
|
ldCmd = gccCmd(flags.toolchain, "g++")
|
|
|
|
}
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
|
|
|
Rule: partialLd,
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: objFiles,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
2015-09-24 06:26:20 +08:00
|
|
|
"ldCmd": ldCmd,
|
2015-11-24 06:01:42 +08:00
|
|
|
"ldFlags": flags.ldFlags,
|
2015-01-31 09:27:36 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-27 05:44:11 +08:00
|
|
|
// Generate a rule for runing objcopy --prefix-symbols on a binary
|
2015-09-24 06:26:20 +08:00
|
|
|
func TransformBinaryPrefixSymbols(ctx common.AndroidModuleContext, prefix string, inputFile common.Path,
|
|
|
|
flags builderFlags, outputFile common.WritablePath) {
|
2015-03-27 05:44:11 +08:00
|
|
|
|
|
|
|
objcopyCmd := gccCmd(flags.toolchain, "objcopy")
|
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
|
|
|
Rule: prefixSymbols,
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
2015-03-27 05:44:11 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"objcopyCmd": objcopyCmd,
|
|
|
|
"prefix": prefix,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-01-31 09:27:36 +08:00
|
|
|
func CopyGccLib(ctx common.AndroidModuleContext, libName string,
|
2015-09-24 06:26:20 +08:00
|
|
|
flags builderFlags, outputFile common.WritablePath) {
|
2015-01-31 09:27:36 +08:00
|
|
|
|
2015-09-24 06:26:20 +08:00
|
|
|
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
|
|
|
|
Rule: copyGccLib,
|
|
|
|
Output: outputFile,
|
2015-01-31 09:27:36 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"ccCmd": gccCmd(flags.toolchain, "gcc"),
|
|
|
|
"cFlags": flags.globalFlags,
|
|
|
|
"libName": libName,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-24 08:50:24 +08:00
|
|
|
func gccCmd(toolchain Toolchain, cmd string) string {
|
2015-01-31 09:27:36 +08:00
|
|
|
return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
|
|
|
|
}
|
2015-05-01 07:36:18 +08:00
|
|
|
|
|
|
|
func splitListForSize(list []string, limit int) (lists [][]string, err error) {
|
|
|
|
var i int
|
|
|
|
|
|
|
|
start := 0
|
|
|
|
bytes := 0
|
|
|
|
for i = range list {
|
|
|
|
l := len(list[i])
|
|
|
|
if l > limit {
|
|
|
|
return nil, fmt.Errorf("list element greater than size limit (%d)", limit)
|
|
|
|
}
|
|
|
|
if bytes+l > limit {
|
|
|
|
lists = append(lists, list[start:i])
|
|
|
|
start = i
|
|
|
|
bytes = 0
|
|
|
|
}
|
|
|
|
bytes += l + 1 // count a space between each list element
|
|
|
|
}
|
|
|
|
|
|
|
|
lists = append(lists, list[start:])
|
|
|
|
|
|
|
|
totalLen := 0
|
|
|
|
for _, l := range lists {
|
|
|
|
totalLen += len(l)
|
|
|
|
}
|
|
|
|
if totalLen != len(list) {
|
|
|
|
panic(fmt.Errorf("Failed breaking up list, %d != %d", len(list), totalLen))
|
|
|
|
}
|
|
|
|
return lists, nil
|
|
|
|
}
|