2015-04-08 07:50:10 +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 (
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2015-04-08 07:50:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-09-14 07:55:40 +08:00
|
|
|
pctx.SourcePathVariable("lexCmd", "prebuilts/misc/${config.HostPrebuiltTag}/flex/flex-2.5.39")
|
2018-01-09 09:26:13 +08:00
|
|
|
pctx.SourcePathVariable("yaccCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/bison")
|
|
|
|
pctx.SourcePathVariable("yaccDataDir", "prebuilts/build-tools/common/bison")
|
2016-11-04 05:28:51 +08:00
|
|
|
|
|
|
|
pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2016-08-30 07:14:13 +08:00
|
|
|
yacc = pctx.AndroidStaticRule("yacc",
|
2015-04-08 07:50:10 +08:00
|
|
|
blueprint.RuleParams{
|
2016-11-04 05:28:31 +08:00
|
|
|
Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags --defines=$hFile -o $out $in",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$yaccCmd"},
|
2015-04-08 07:50:10 +08:00
|
|
|
},
|
2016-11-04 05:28:31 +08:00
|
|
|
"yaccFlags", "hFile")
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
lex = pctx.AndroidStaticRule("lex",
|
2015-04-08 07:50:10 +08:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$lexCmd -o$out $in",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$lexCmd"},
|
2015-04-08 07:50:10 +08:00
|
|
|
})
|
2016-11-04 05:28:51 +08:00
|
|
|
|
|
|
|
aidl = pctx.AndroidStaticRule("aidl",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$aidlCmd -d${out}.d -ninja $aidlFlags $in $outDir $out",
|
|
|
|
CommandDeps: []string{"$aidlCmd"},
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
},
|
|
|
|
"aidlFlags", "outDir")
|
2017-09-09 16:15:26 +08:00
|
|
|
|
|
|
|
windmc = pctx.AndroidStaticRule("windmc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$windmcCmd -r$$(dirname $out) -h$$(dirname $out) $in",
|
|
|
|
CommandDeps: []string{"$windmcCmd"},
|
|
|
|
},
|
|
|
|
"windmcCmd")
|
2015-04-08 07:50:10 +08:00
|
|
|
)
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func genYacc(ctx android.ModuleContext, yaccFile android.Path, outFile android.ModuleGenPath, yaccFlags string) (headerFile android.ModuleGenPath) {
|
2016-11-03 11:43:13 +08:00
|
|
|
headerFile = android.GenPathWithExt(ctx, "yacc", yaccFile, "h")
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2016-11-04 05:28:31 +08:00
|
|
|
Rule: yacc,
|
2017-05-10 04:45:28 +08:00
|
|
|
Description: "yacc " + yaccFile.Rel(),
|
2016-11-04 05:28:31 +08:00
|
|
|
Output: outFile,
|
|
|
|
ImplicitOutput: headerFile,
|
|
|
|
Input: yaccFile,
|
2015-04-08 07:50:10 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"yaccFlags": yaccFlags,
|
2015-09-24 06:26:20 +08:00
|
|
|
"hFile": headerFile.String(),
|
2015-04-08 07:50:10 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2016-03-02 07:15:26 +08:00
|
|
|
return headerFile
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 05:28:51 +08:00
|
|
|
func genAidl(ctx android.ModuleContext, aidlFile android.Path, outFile android.ModuleGenPath, aidlFlags string) android.Paths {
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: aidl,
|
|
|
|
Description: "aidl " + aidlFile.Rel(),
|
|
|
|
Output: outFile,
|
|
|
|
Input: aidlFile,
|
2016-11-04 05:28:51 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"aidlFlags": aidlFlags,
|
|
|
|
"outDir": android.PathForModuleGen(ctx, "aidl").String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO: This should return the generated headers, not the source file.
|
|
|
|
return android.Paths{outFile}
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath) {
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: lex,
|
|
|
|
Description: "lex " + lexFile.Rel(),
|
|
|
|
Output: outFile,
|
|
|
|
Input: lexFile,
|
2015-04-08 07:50:10 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-09 16:15:26 +08:00
|
|
|
func genWinMsg(ctx android.ModuleContext, srcFile android.Path, flags builderFlags) (android.Path, android.Path) {
|
|
|
|
headerFile := android.GenPathWithExt(ctx, "windmc", srcFile, "h")
|
|
|
|
rcFile := android.GenPathWithExt(ctx, "windmc", srcFile, "rc")
|
|
|
|
|
|
|
|
windmcCmd := gccCmd(flags.toolchain, "windmc")
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-09-09 16:15:26 +08:00
|
|
|
Rule: windmc,
|
|
|
|
Description: "windmc " + srcFile.Rel(),
|
|
|
|
Output: rcFile,
|
|
|
|
ImplicitOutput: headerFile,
|
|
|
|
Input: srcFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"windmcCmd": windmcCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return rcFile, headerFile
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|
|
|
buildFlags builderFlags) (android.Paths, android.Paths) {
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
var deps android.Paths
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2017-05-02 08:37:24 +08:00
|
|
|
var rsFiles android.Paths
|
|
|
|
|
2015-04-08 07:50:10 +08:00
|
|
|
for i, srcFile := range srcFiles {
|
2015-09-24 06:26:20 +08:00
|
|
|
switch srcFile.Ext() {
|
2016-03-02 07:15:26 +08:00
|
|
|
case ".y":
|
2016-11-03 11:43:13 +08:00
|
|
|
cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c")
|
2016-03-02 07:15:26 +08:00
|
|
|
srcFiles[i] = cFile
|
|
|
|
deps = append(deps, genYacc(ctx, srcFile, cFile, buildFlags.yaccFlags))
|
|
|
|
case ".yy":
|
2016-11-03 11:43:13 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp")
|
2015-04-08 07:50:10 +08:00
|
|
|
srcFiles[i] = cppFile
|
2016-03-02 07:15:26 +08:00
|
|
|
deps = append(deps, genYacc(ctx, srcFile, cppFile, buildFlags.yaccFlags))
|
|
|
|
case ".l":
|
2016-11-03 11:43:13 +08:00
|
|
|
cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
|
2016-03-02 07:15:26 +08:00
|
|
|
srcFiles[i] = cFile
|
|
|
|
genLex(ctx, srcFile, cFile)
|
|
|
|
case ".ll":
|
2016-11-03 11:43:13 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
|
2015-04-08 07:50:10 +08:00
|
|
|
srcFiles[i] = cppFile
|
2016-03-02 07:15:26 +08:00
|
|
|
genLex(ctx, srcFile, cppFile)
|
2016-10-21 07:11:43 +08:00
|
|
|
case ".proto":
|
2017-11-19 10:23:14 +08:00
|
|
|
ccFile, headerFile := genProto(ctx, srcFile, buildFlags.protoFlags,
|
2018-02-15 05:58:34 +08:00
|
|
|
buildFlags.protoOutParams, buildFlags.protoRoot)
|
2017-09-21 03:59:05 +08:00
|
|
|
srcFiles[i] = ccFile
|
|
|
|
deps = append(deps, headerFile)
|
2016-11-04 05:28:51 +08:00
|
|
|
case ".aidl":
|
|
|
|
cppFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp")
|
|
|
|
srcFiles[i] = cppFile
|
|
|
|
deps = append(deps, genAidl(ctx, srcFile, cppFile, buildFlags.aidlFlags)...)
|
2017-05-02 08:37:24 +08:00
|
|
|
case ".rs", ".fs":
|
|
|
|
cppFile := rsGeneratedCppFile(ctx, srcFile)
|
|
|
|
rsFiles = append(rsFiles, srcFiles[i])
|
|
|
|
srcFiles[i] = cppFile
|
2017-09-09 16:15:26 +08:00
|
|
|
case ".mc":
|
|
|
|
rcFile, headerFile := genWinMsg(ctx, srcFile, buildFlags)
|
|
|
|
srcFiles[i] = rcFile
|
|
|
|
deps = append(deps, headerFile)
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 08:37:24 +08:00
|
|
|
if len(rsFiles) > 0 {
|
|
|
|
deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...)
|
|
|
|
}
|
|
|
|
|
2015-04-08 07:50:10 +08:00
|
|
|
return srcFiles, deps
|
|
|
|
}
|