Reputation: 31
I would like to know how can I get the --prefix and the --exec-prefix values passed to the configure script (autotools) in my c source code?
For example if I'm using autotools to build a package in linux I do:
./configure --prefix=/usr/local/apps --exec-prefix=/usr/local/apps &&
make &&
make install
And all the files that the application uses are installed depending on that values.
So in my application for open a file, for example, I need to know that value to know where the images where installed and then open it.
I could hard code that value but I don`t want to do that because I could only install the application there.
How can I know that values?
I'm using Anjuta.
Thanks in advance for your help.
Upvotes: 3
Views: 1569
Reputation: 212634
The usual thing is to define a value for the preprocessor, either in config.h
via AC_DEFINE
, or as a flag in AM_CPPFLAGS
. For example, in Makefile.am:
AM_CPPFLAGS = -DPREFIX="\"$(prefix)\""
This allows the code to contain things like printf( "prefix = %s\n", PREFIX )
Keep in mind that the value of the string in the source code will not reflect any value of DESTDIR
, and so may not work if the user does a staged installation.
Upvotes: 5