8 std::string X
= "$Format:%h by %cn on %ci$";
10 std::string
derive_format(std::string kwformat
)
12 if(kwformat
[0] != '$' || kwformat
[1] != 'F' || kwformat
[kwformat
.length() - 1] != '$') {
13 std::cerr
<< "Bad keyword format '" << kwformat
<< "'" << std::endl
;
16 return "--pretty=f" + kwformat
.substr(2, kwformat
.length() - 3);
19 std::string
shellquote(std::string arg
)
23 for(size_t i
= 0; i
< arg
.length(); i
++) {
33 std::string
runlog(std::string logformat
)
35 std::string command
= "git log " + shellquote(logformat
) + " -1";
39 FILE* out
= popen(command
.c_str(), "r");
41 std::cerr
<< "Can't invoke git to get the version" << std::endl
;
44 while((r
= fread(buf
, 1, 4095, out
)) > 0) {
46 retval
= retval
+ buf
;
49 std::cerr
<< "Error reading git version output" << std::endl
;
56 std::string
get_main_version()
58 std::ifstream
x("VERSION");
60 std::cerr
<< "Error reading main version" << std::endl
;
66 std::cerr
<< "Error reading main version" << std::endl
;
74 std::string gitversion
;
75 std::string mainversion
= get_main_version();
77 std::string logformat
= derive_format(X
);
78 gitversion
= runlog(logformat
);
81 std::cout
<< "#include <string>" << std::endl
;
82 std::cout
<< "std::string lsnes_git_revision = \"" << gitversion
<< "\";" << std::endl
;
83 std::cout
<< "std::string lsnes_version = \"" << mainversion
<< "\";" << std::endl
;