This should probably be done with a command line parameter, but if you have to do this in a makefile, you can use the following:
$ cat makefile qq: myprog.c makefile gcc -DMYSTRING='"hello"' -o myprog -Wall myprog.c $ cat myprog.c
-D indicates the #define compilation time, which sets MYSTRING to "hello" .
Then, when you use MYSTRING in the code, it turns into a string. In this code example, I just pass it to printf , but you can also pass it to fopen per your requirement.
When you run this executable, the output is:
[hello]
This is not unlike a simple encoding of a value in the source code - you will have to recompile if you need to change the line (so I suggested the command line parameter in the first paragraph).
paxdiablo
source share