OK, I need to compile the *value* of a #define'ed symbol into a C++ program.
I would like to pass the symbol's value on the compile line without a lot of hideous quoting. (Partly to make it independent of any particular shell's quoting rules, and partly to reduce the magic involved so that others can maintain it.
I want a compile command line that looks something like this:
The CPP cannot do what you want... alas. It is possible that GPP might have some extension that will do it, but I don't remember it.
There shouldn't be any problem quoting as follows for win32 or posix shells. You may have troubles on older systems...
gcc ... -DFILENAME="\"filename.txt\"" ...
In any case, typically a makefile is executed by bash (or at least the old sh) anyway, so unless you expect your program to be heavily used on ancient OSes, you might as well just figure that it isn't worth your time to worry about it.
It's not like I had much choice in the matter. The program in question is a thin wrapper Setup.exe, so there isn't any environment set up when it executes.
The filename is set by an environment variable when the Setup.exe is compiled.
Ah, then you can make yourself a little include file that will do it for you. As part of your make requirements/targets, add a phony target that will build the include file. You can do something like:
[edit]
If you can't guarantee command.com or cmd.exe will be available on the target, you can just compile an extra little utility program that will generate the include file, and use the phony target the same way to cause its generation
1 2 3 4 5 6 7 8 9 10 11 12
// genfname.exe
#include <cstdlib>
#include <cstdio>
usingnamespace std;
int main()
{
char* filename = getenv( "FILENAME" );
if (filename == NULL) filename = "#error FILENAME is not defined";
printf( "const char* filename = \"%s\";\n", filename );
return 0;
}