[10407] Add -o <outfile> option to genrevision.

This gives more flexibility to build systems that don't run genrevision with desired destination as working dir.
For example a build system may run:
build/tools/genrevision -o build/src/shared/revision.h
This commit is contained in:
Lynx3d 2010-08-24 19:04:58 +02:00
parent f3579fba64
commit 2260b7921f
2 changed files with 13 additions and 3 deletions

View file

@ -204,12 +204,14 @@ int main(int argc, char **argv)
bool use_url = false;
bool svn_prefered = false;
std::string path;
std::string outfile = "revision.h";
// Call: tool {options} [path]
// -g use git prefered (default)
// -s use svn prefered
// -r use only revision (without repo URL) (default)
// -u include repositire URL as commit URL or "rev at URL"
// -o <file> write header to specified target file
for(int k = 1; k <= argc; ++k)
{
if(!argv[k] || !*argv[k])
@ -237,6 +239,12 @@ int main(int argc, char **argv)
case 'u':
use_url = true;
continue;
case 'o':
// read next argument as target file, if not available return error
if (++k == argc)
return 1;
outfile = argv[k];
continue;
default:
printf("Unknown option %s",argv[k]);
return 1;
@ -281,7 +289,7 @@ int main(int argc, char **argv)
/// get existed header data for compare
std::string oldData;
if(FILE* HeaderFile = fopen("revision.h","rb"))
if(FILE* HeaderFile = fopen(outfile.c_str(),"rb"))
{
while(!feof(HeaderFile))
{
@ -297,11 +305,13 @@ int main(int argc, char **argv)
/// update header only if different data
if(newData != oldData)
{
if(FILE* OutputFile = fopen("revision.h","wb"))
if(FILE* OutputFile = fopen(outfile.c_str(),"wb"))
{
fprintf(OutputFile,"%s",newData.c_str());
fclose(OutputFile);
}
else
return 1;
}
return 0;