tags:

views:

48

answers:

3

Suppose there is a C program, which stores its version in a global char* in main.c. Can the buildsystem (gnu make) somehow extract the value of this variable on build time, so that the executable built could have the exact version name as it appears in the program?

What I'd like to achieve is that given the source:

char g_version[] = "Superprogram 1.32 build 1142";

the buildsystem would generate an executable named Superprogram 1.32 build 1142.exe

+4  A: 

The shell function allows you to call external applications such as sed that can be used to parse the source for the details required.

Ignacio Vazquez-Abrams
Though his version string looks suspiciously hand-crafted, I would also have advised to check `what` tool. That plus `shell` might be what he's looking for.
Dummy00001
Thanks for replying, this might actually work, provided that I get up to speed on my abilities on sed (and the other utils, mentioned below by mouviciel)...
Manjabes
+1  A: 

You can use any combination of unix text tools (grep, sed, awk, perl, tail, ...) in your Makefile in order to extract that information from source file.

mouviciel
+4  A: 

Define your version variable from a Macro:

char g_version[] = VERSION;

then make your makefile put a -D argument on the command line when compiling

gcc hack.c -DVERSION=\"Superprogram\ 1.99\"

And of course you should in your example use sed/grep/awk etc to generate your version string.

I'm aware of the -D option, but that cannot be applied in this case. The version string has to stay where it is.
Manjabes