User forums > General (but related to Code::Blocks)
Integrating svnversion into the build process
(1/1)
Crypticode:
Hi, could someone explain me how i can do this:
http://subversion.tigris.org/faq.html#version-value-in-source
in Code::Blocks ? I dont get it right ... :/
Thanks in advance
thomas:
You can use a keyword such as $Revision$ anywhere in your sources and set the svn:keywords property accordingly, then Subversion will replace that string with the current revision.
This can be done inside any source file or the makefile, you can then do whatever you want... use string manipulation in your source, or feed it to some tool (sed?) from inside the makefile... whatever.
Note that the revision shown will be the revision of the file that contains the keyword, this is not necessarily HEAD.
Another way is to call svn info from the makefile or from a special tool and extract the revision from the output. This is more complicated but always accurate.
Crypticode:
Thanks...
--- Quote ---Note that the revision shown will be the revision of the file that contains the keyword, this is not necessarily HEAD.
--- End quote ---
If you only had read the link i provided... i want to know HOW i can call the program svnversion.exe from within the makefile code::blocks generates... Please read the link and tell me your suggestions again, cause i failed in setting these 2 -Defines in every way i tried :(
Crypticode:
Oops, never mind. It works now, simply with backticks.
@ All who care...
If you have Subversion installed on your system just add the following to "Build Options/Other options" for your Target:
--- Code: ----DSVN_REV=`svnversion -n .`
--- End code ---
You can then use the extracted Revision number in your program like:
--- Code: ---#define _STR(x) #x
#define STR(x) _STR(x)
printf("Revision: %s\n", STR(SVN_REV))
--- End code ---
Note that the revision string is "extracted" when your Project folder is no "working SVN copy"
:D
thomas:
I did read that. svnversion is another tool that can be used instead of svn info.
It is the same thing, except that svn info runs about 10 times faster, which is why I prefer it.
What they do in that example is nothing more but echo some C code into a file (with output redirection) and run svnversion -n in backticks during that.
This will produce a souce file with code that looks like char *SVN_version = "12342";
There is no deep magic behind that :)
The defines are another way of doing it, but are not needed if you produce the source file. I don't know about the $(shell ...) syntax, but a guess would be that you need to replace "shell" with "sh" or "bash". If it were me, I'd use the other solution, it confirmedly works without any problems.
Navigation
[0] Message Index
Go to full version