In my project, a number of paths to various directories, files and other components of the system are stored as #define
s in a filenames.h
, a file included by all that need them. It works well for all the various binaries generated by compilation, but the project also includes a few shell scripts that use the same paths. Currently this means that as a path changes, all I have to do is edit filenames.h
and recompile to get the set of executables to understand the new path, but I have to edit each shell script by hand.
So the question is, how to make the #defines
into shell variables, for example generating some filenames.sh
script that would be called from other scripts to initialize them. So for example:
#define TMP_PATH "/ait/tmp/"
#define SYNCTMZFILE TMP_PATH "sync_tmz"
would create
TMP_PATH="/ait/tmp/"
SYNCTMZFILE="/ait/tmp/sync_tmz"
Of course it would be possible to write a C program that creates it (even prints it out to stdout and then to execute it in backticks in the shell) but I'd prefer a simpler, more robust method, say, writing a half-C half-shell like thing that run through cpp
would create the right output, or something alike.