Ninja: cmcldeps
- don't depend on argument order - update help
This commit is contained in:
parent
77cb7b502f
commit
220fdc16fc
|
@ -482,15 +482,16 @@ void SubprocessSet::Clear() {
|
||||||
// See http://msdn.microsoft.com/en-us/library/zay8tzh6(v=vs.85).aspx
|
// See http://msdn.microsoft.com/en-us/library/zay8tzh6(v=vs.85).aspx
|
||||||
void _setargv() {}
|
void _setargv() {}
|
||||||
|
|
||||||
|
|
||||||
static void usage(const char* msg) {
|
static void usage(const char* msg) {
|
||||||
Fatal("%s\n\nusage:\n "
|
Fatal("%s\n\nusage:\n "
|
||||||
" cldeps "
|
"cmcldeps "
|
||||||
"<source file> "
|
"<language C, CXX or RC> "
|
||||||
|
"<source file path> "
|
||||||
"<output path for *.d file> "
|
"<output path for *.d file> "
|
||||||
"<output path for *.obj file> "
|
"<output path for *.obj file> "
|
||||||
"<prefix of /showIncludes> "
|
"<prefix of /showIncludes> "
|
||||||
"<path to cl> "
|
"<path to cl.exe> "
|
||||||
|
"<path to tool (cl or rc)> "
|
||||||
"<rest of command ...>\n", msg);
|
"<rest of command ...>\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,12 +548,6 @@ static void parseCommandLine(LPTSTR wincmdline,
|
||||||
/* self */ getArg(cmdline);
|
/* self */ getArg(cmdline);
|
||||||
lang = getArg(cmdline);
|
lang = getArg(cmdline);
|
||||||
srcfile = getArg(cmdline);
|
srcfile = getArg(cmdline);
|
||||||
std::string::size_type pos = srcfile.rfind("\\");
|
|
||||||
if (pos != string::npos) {
|
|
||||||
srcfile = srcfile.substr(pos + 1);
|
|
||||||
} else {
|
|
||||||
srcfile = "";
|
|
||||||
}
|
|
||||||
dfile = getArg(cmdline);
|
dfile = getArg(cmdline);
|
||||||
objfile = getArg(cmdline);
|
objfile = getArg(cmdline);
|
||||||
prefix = getArg(cmdline);
|
prefix = getArg(cmdline);
|
||||||
|
@ -615,7 +610,7 @@ std::string replace(const std::string& str, const std::string& what,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int process( const string& srcfile,
|
static int process( const string& srcfilename,
|
||||||
const string& dfile,
|
const string& dfile,
|
||||||
const string& objfile,
|
const string& objfile,
|
||||||
const string& prefix,
|
const string& prefix,
|
||||||
|
@ -652,7 +647,7 @@ static int process( const string& srcfile,
|
||||||
includes.push_back(inc);
|
includes.push_back(inc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isFirstLine || !startsWith(line, srcfile)) {
|
if (!isFirstLine || !startsWith(line, srcfilename)) {
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stdout, "%s\n", line.c_str());
|
fprintf(stdout, "%s\n", line.c_str());
|
||||||
}
|
}
|
||||||
|
@ -685,32 +680,38 @@ int main() {
|
||||||
parseCommandLine(GetCommandLine(), lang, srcfile, dfile, objfile,
|
parseCommandLine(GetCommandLine(), lang, srcfile, dfile, objfile,
|
||||||
prefix, cl, binpath, rest);
|
prefix, cl, binpath, rest);
|
||||||
|
|
||||||
#if 0
|
// needed to suppress filename output of msvc tools
|
||||||
fprintf(stderr, "\n\ncmcldebug:\n");
|
string srcfilename;
|
||||||
fprintf(stderr, ".d : %s\n", dfile.c_str());
|
std::string::size_type pos = srcfile.rfind("\\");
|
||||||
fprintf(stderr, "OBJ : %s\n", objfile.c_str());
|
if (pos != string::npos) {
|
||||||
fprintf(stderr, "CL : %s\n", clpath.c_str());
|
srcfilename = srcfile.substr(pos + 1);
|
||||||
fprintf(stderr, "REST: %s\n", rest.c_str());
|
}
|
||||||
fprintf(stderr, "\n\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string showflag = " /showIncludes /nologo ";
|
std::string nol = " /nologo ";
|
||||||
if (lang != "RC") {
|
std::string show = " /showIncludes ";
|
||||||
return process(srcfile, dfile, objfile, prefix,
|
if (lang == "C" || lang == "CXX") {
|
||||||
binpath + showflag + rest);
|
return process(srcfilename, dfile, objfile, prefix,
|
||||||
} else {
|
binpath + nol + show + rest);
|
||||||
|
} else if (lang == "RC") {
|
||||||
// "misuse" cl.exe to get headers from .rc files
|
// "misuse" cl.exe to get headers from .rc files
|
||||||
// rc: /fo x\CMakeFiles\x.dir\x.rc.res src\x\x.rc
|
|
||||||
// cl: /out:x\CMakeFiles\x.dir\x.rc.res.dep.obj /Tc src\x\x.rc
|
|
||||||
|
|
||||||
cl = "\"" + cl + "\" /P /DRC_INVOKED " + showflag +
|
string clrest = rest;
|
||||||
replace(rest, "/fo" + objfile, "/out:" + objfile + ".dep.obj /Tc ");
|
// rc: /fo x.dir\x.rc.res -> cl: /out:x.dir\x.rc.res.dep.obj
|
||||||
|
clrest = replace(clrest, "/fo", "/out:");
|
||||||
|
clrest = replace(clrest, objfile, objfile + ".dep.obj ");
|
||||||
|
// rc: src\x\x.rc -> cl: /Tc src\x\x.rc
|
||||||
|
clrest = replace(clrest, srcfile, "/Tc " + srcfile);
|
||||||
|
|
||||||
int ret;
|
cl = "\"" + cl + "\" /P /DRC_INVOKED ";
|
||||||
ret = process(srcfile, dfile, objfile, prefix, cl, true);
|
|
||||||
ret = process(srcfile, "" , objfile, prefix,
|
// extract dependencies with cl.exe
|
||||||
binpath + " /nologo " + rest);
|
process(srcfilename, dfile, objfile,
|
||||||
return ret;
|
prefix, cl + nol + show + clrest, true);
|
||||||
|
|
||||||
|
// compile rc file with rc.exe
|
||||||
|
return process(srcfilename, "" , objfile, prefix, binpath + nol + rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usage("Invalid language specified.");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue