Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: ironhead on July 10, 2008, 02:05:27 PM

Title: Help with pre-build steps
Post by: ironhead on July 10, 2008, 02:05:27 PM
I have the following in my makefile:

..$/svnversion.h:
@echo #define SVN_VERSION $(shell svn info --revision HEAD | grep Revision | cut -f2 -d" ") > ..$/svnversion.h
@echo #define SVN_VERSION_STR "$(shell svn info --revision HEAD | grep Revision | cut -f2 -d" ")" >> ..$/svnversion.h


which generates the following svnversion.h:

#define SVN_VERSION 1837
#define SVN_VERSION_STR "1837"


My question is how can I create a pre-build step that results in the same file generation as that of my make file?

I have the first line of the file generating with:

$if($SVN_BUILD){cmd /c svn info --revision HEAD | grep Revision | sed -e "s/Revision:/#define SVN_VERSION/" > svnversion.h}

but I can't get sed to handle inserting the double quote.  I'm also hoping there is a cleaner way to do this with the built in C::B scripting support.

Thanx!
Title: Re: Help with pre-build steps
Post by: mariocup on July 10, 2008, 04:42:42 PM
Hi ironhead,

normally I use


sed -es/string/replace/ > name.h


without quotes. The quotes depend on the using shell/cmd. So you could try alternatively to use ' as quote.

Bye,

Mario
Title: Re: Help with pre-build steps
Post by: ironhead on July 11, 2008, 02:57:33 AM
I got it to work with the following pre-build step:

$if($SVN_BUILD){cmd /c svn info --revision HEAD | grep Revision | sed -e "s/Revision:/#define SVN_VERSION/" > svnversion.h}
$if($SVN_BUILD){cmd /c svn info --revision HEAD | grep Revision | sed -e "s/Revision: /#define SVN_VERSION_STR \"/" -e "s/$/\"/" >> svnversion.h}