diff --git a/cc/builder.go b/cc/builder.go index 1a4f5054d..b5bdc3d37 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -158,6 +158,13 @@ var ( }, "asFlags") + windres = pctx.AndroidStaticRule("windres", + blueprint.RuleParams{ + Command: "$windresCmd $flags -I$$(dirname $in) -i $in -o $out", + CommandDeps: []string{"$windresCmd"}, + }, + "windresCmd", "flags") + _ = pctx.SourcePathVariable("sAbiDumper", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/header-abi-dumper") // -w has been added since header-abi-dumper does not need to produce any sort of diagnostic information. @@ -332,7 +339,8 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and objFiles[i] = objFile - if srcFile.Ext() == ".asm" { + switch srcFile.Ext() { + case ".asm": ctx.ModuleBuild(pctx, android.ModuleBuildParams{ Rule: yasm, Description: "yasm " + srcFile.Rel(), @@ -344,6 +352,19 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and }, }) continue + case ".rc": + ctx.ModuleBuild(pctx, android.ModuleBuildParams{ + Rule: windres, + Description: "windres " + srcFile.Rel(), + Output: objFile, + Input: srcFile, + OrderOnly: deps, + Args: map[string]string{ + "windresCmd": gccCmd(flags.toolchain, "windres"), + "flags": flags.toolchain.WindresFlags(), + }, + }) + continue } var moduleCflags string diff --git a/cc/compiler.go b/cc/compiler.go index 0cc809d1b..5ffaf1752 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -429,6 +429,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag "-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String()) } + if compiler.hasSrcExt(".mc") { + flags.GlobalFlags = append(flags.GlobalFlags, + "-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String()) + } + if compiler.hasSrcExt(".aidl") { if len(compiler.Properties.Aidl.Local_include_dirs) > 0 { localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs) diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index fc0282bc2..d62ebe465 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -70,6 +70,8 @@ type Toolchain interface { YasmFlags() string + WindresFlags() string + Is64Bit() bool ShlibSuffix() string @@ -135,6 +137,10 @@ func (toolchainBase) YasmFlags() string { return "" } +func (toolchainBase) WindresFlags() string { + return "" +} + func (toolchainBase) SanitizerRuntimeLibraryArch() string { return "" } diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 4709823d8..99c76f1c7 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -172,6 +172,14 @@ func (t *toolchainWindows) IncludeFlags() string { return "${config.WindowsIncludeFlags}" } +func (t *toolchainWindowsX86) WindresFlags() string { + return "-F pe-i386" +} + +func (t *toolchainWindowsX8664) WindresFlags() string { + return "-F pe-x86-64" +} + func (t *toolchainWindows) ClangSupported() bool { return false } diff --git a/cc/gen.go b/cc/gen.go index 7a22abdde..6c9579edd 100644 --- a/cc/gen.go +++ b/cc/gen.go @@ -54,6 +54,13 @@ var ( Deps: blueprint.DepsGCC, }, "aidlFlags", "outDir") + + windmc = pctx.AndroidStaticRule("windmc", + blueprint.RuleParams{ + Command: "$windmcCmd -r$$(dirname $out) -h$$(dirname $out) $in", + CommandDeps: []string{"$windmcCmd"}, + }, + "windmcCmd") ) func genYacc(ctx android.ModuleContext, yaccFile android.Path, outFile android.ModuleGenPath, yaccFlags string) (headerFile android.ModuleGenPath) { @@ -100,6 +107,26 @@ func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.Mod }) } +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") + + ctx.ModuleBuild(pctx, android.ModuleBuildParams{ + Rule: windmc, + Description: "windmc " + srcFile.Rel(), + Output: rcFile, + ImplicitOutput: headerFile, + Input: srcFile, + Args: map[string]string{ + "windmcCmd": windmcCmd, + }, + }) + + return rcFile, headerFile +} + func genSources(ctx android.ModuleContext, srcFiles android.Paths, buildFlags builderFlags) (android.Paths, android.Paths) { @@ -137,6 +164,10 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths, cppFile := rsGeneratedCppFile(ctx, srcFile) rsFiles = append(rsFiles, srcFiles[i]) srcFiles[i] = cppFile + case ".mc": + rcFile, headerFile := genWinMsg(ctx, srcFile, buildFlags) + srcFiles[i] = rcFile + deps = append(deps, headerFile) } }