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() {
|
2015-09-24 06:26:20 +08:00
|
|
|
pctx.SourcePathVariable("lexCmd", "prebuilts/misc/${HostPrebuiltTag}/flex/flex-2.5.39")
|
|
|
|
pctx.SourcePathVariable("yaccCmd", "prebuilts/misc/${HostPrebuiltTag}/bison/bison")
|
|
|
|
pctx.SourcePathVariable("yaccDataDir", "external/bison/data")
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
yacc = pctx.StaticRule("yacc",
|
|
|
|
blueprint.RuleParams{
|
2016-03-02 07:15:26 +08:00
|
|
|
Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags --defines=$hFile -o $cFile $in",
|
2015-11-18 07:27:28 +08:00
|
|
|
CommandDeps: []string{"$yaccCmd"},
|
2015-04-08 07:50:10 +08:00
|
|
|
Description: "yacc $out",
|
|
|
|
},
|
2016-03-02 07:15:26 +08:00
|
|
|
"yaccFlags", "cFile", "hFile")
|
2015-04-08 07:50:10 +08:00
|
|
|
|
|
|
|
lex = pctx.StaticRule("lex",
|
|
|
|
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
|
|
|
Description: "lex $out",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func genYacc(ctx android.ModuleContext, yaccFile android.Path, outFile android.ModuleGenPath, yaccFlags string) (headerFile android.ModuleGenPath) {
|
|
|
|
headerFile = android.GenPathWithExt(ctx, yaccFile, "h")
|
2015-04-08 07:50:10 +08:00
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
2015-11-18 07:27:28 +08:00
|
|
|
Rule: yacc,
|
2016-05-19 06:37:25 +08:00
|
|
|
Outputs: android.WritablePaths{outFile, headerFile},
|
2015-09-24 06:26:20 +08:00
|
|
|
Input: yaccFile,
|
2015-04-08 07:50:10 +08:00
|
|
|
Args: map[string]string{
|
|
|
|
"yaccFlags": yaccFlags,
|
2016-03-02 07:15:26 +08:00
|
|
|
"cFile": outFile.String(),
|
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-05-19 06:37:25 +08:00
|
|
|
func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath) {
|
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
2015-09-24 06:26:20 +08:00
|
|
|
Rule: lex,
|
2016-03-02 07:15:26 +08:00
|
|
|
Output: outFile,
|
2015-09-24 06:26:20 +08:00
|
|
|
Input: lexFile,
|
2015-04-08 07:50:10 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
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-05-19 06:37:25 +08:00
|
|
|
cFile := android.GenPathWithExt(ctx, 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-05-19 06:37:25 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, 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-05-19 06:37:25 +08:00
|
|
|
cFile := android.GenPathWithExt(ctx, srcFile, "c")
|
2016-03-02 07:15:26 +08:00
|
|
|
srcFiles[i] = cFile
|
|
|
|
genLex(ctx, srcFile, cFile)
|
|
|
|
case ".ll":
|
2016-05-19 06:37:25 +08:00
|
|
|
cppFile := android.GenPathWithExt(ctx, 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)
|
2015-04-08 07:50:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcFiles, deps
|
|
|
|
}
|