On Tue, Oct 18, 2011, Elazar Leibovich wrote about "Re: Newer gcc swallow version control keywords": > Excuse the idiotic solution, but can't you just add an option to print it > out? > > int main(int argc,char**argv) {if (argc == 2 && strcmp(argv[1],"--ident") > puts(ident);...}
The point in Oleg's trick (which is not Oleg's invention - it has been in use for decades) is to be able to tell not just a single version number for the executable (your "--ident" is basically the same as "--version" supported by many programs), but rather to be able to tell the exact version of each and every source code file which participated in creating this executable. You run "ident" on the executable, and get a list of dozens (or thousands) of source file names and their exact version numbers and dates. This could be useful if you have a lot of versions of your code running around, and you don't remember how exactly each executable was generated. This trick was particularly useful in the days of SCCS and RCS, which work separately on each file, and each file has a separate version number. One reason that nobody really cares about this trick any more is that it has become MUCH LESS IMPORTANT on modern version control systems, e.g., Subversion or Git, where there is a single version number (or version hash) for the entire project, not one per file. So if you just include this single version number in your main() - as in your example - it is enough to find exactly which version of each source file went into this executable. If your project's result doesn't have a main() (e.g., it is a library), just find another way to stick this version number - e.g., provide a function or global variable (which won't be optimized out) containing this version number - and stick it in the same object file as your library's most important function (so it always gets included by users of your library). > It seems like a good idea anyhow, to have a stable way of extracting this > ident string from the executable (what happens for instance if by accident > you have rcsident and rcs_ident? How would you know from the stripped > executable which one to trust?). The idea with ident(1) is that the content of the string, not the variable name holding it, has a recognizeable structure. In particular, it looks like this: $Id: something $ - with the word "something" replaced by anything you wish. ident(1) looks for such strings in any file you give it - whether it is an executable, source code, or whatever, and prints them. what(1), SCCS's precursor of RCS's ident(1), used a different string format for the same purpose - it looked like "@(#) something" (with the string typically ending with a null). Nobody in their right mind still uses SCCS today, but what(1) still works, if you wish to use strings of this format in your executables to mark them. Nadav. -- Nadav Har'El | Tuesday, Oct 18 2011, n...@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |Windows-2000/Professional isn't. http://nadav.harel.org.il | _______________________________________________ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il