The configure
script will generate the necessary Makefile
that will use the C compiler's -DMACRO=content
functionality to essentially inject C preprocessor #define MACRO content
statements into the compilation units. So, sysconfdir
could be used via Make rules:
foo.o: foo.c
$(CC) -DCONFDIR=$(sysconfdir) -o $@ $<
(That says to build the foo.o
object file when foo.c
is updated; to build it, use the $(CC)
variable to run the C compiler, define CONFDIR
with the contents of $(sysconfdir)
(supplied via the ./configure
script), put output into the target file ($@
) and give the source file ($<
) as the lone input to the compiler.))
Then the C code in foo.c
could use it like this:
FILE *conf;
if (conf = fopen(CONFDIR "/foo", "r")) {
/* read config file */
} else {
/* unable to open config, either error and die or supply defaults */
}
Note the C string concatenation is performed before compiling the program -- super convenient for exactly this kind of use.
More details here: http://www.gnu.org/software/hello/manual/autoconf/Installation-Directory-Variables.html#Installation-Directory-Variables