I am trying to create a global define in config.h for the installation directory of the application. According to the Autoconf manual, the prefix variable can be used for this purpose. In configure.ac I created a global define with:
AC_DEFINE_UNQUOTED([PROGRAM_DIRECTORY], [${prefix}], [])
but config.h is created with:
#define PROGRAM_DIRECTORY NONE
I get the same results even if I run configure with:
./configure --prefix=/usr/local
I have also tried other variables like bindir.
Is there a variable I can use that will give me information? Or am I going about this in the wrong way?
I am trying to create a global define in config.h for the installation directory of the application.
There are some potential problems with that, but Ok.
According to the Autoconf manual, the prefix variable can be used for this purpose.
Well, the prefix is meant to designate the root of a directory tree, with built artifacts being installed in various subdirectories. The typical choice is between /usr
and /usr/local
, though under some circumstances you might indeed use something else, such as /opt/my_prog
. If that's consistent with what you want to do, then you should use the standard --prefix
option provided by every Autoconf configure
script to convey the desired prefix to it:
./configure --prefix=/usr/local
Of course, /usr/local
is the default for this variable. If that's actually what you want then you should not need to do anything special to get that as your prefix.
Let me suggest, however, that you not create a prefix-based definition in config.h
. The Autotools go to some trouble to ensure that whatever prefix you specify when you configure
can be overridden at make
time by specifying a prefix
to make
:
make prefix=/something/else
If that were exercised, then the actual installation directories would differ from the ones given in config.h
. Therefore, I would recommend instead causing an appropriate definition be specified via a -D
option in the appropriate foo_CPPFLAGS
Automake variable, or by equivalent means if you are using Autoconf
without Automake
. For example:
foo_CPPFLAGS = $(AM_CPPFLAGS) -DPROGRAM_DIRECTORY='$(prefix)'
That does not conflict with using config.h
for other purposes. (Note that the quotes will be processed by the shell; they are not significant to make
, and they will not appear in the defined symbol's actual value.)
With that said, I cannot immediately explain the behavior you describe. My best guess would be that your AC_DEFINE_UNQUOTED()
appears early enough in your configure.ac
that it takes effect before command-line processing. In that case, moving it down might be enough to make it have the expected effect.