autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: config variables in config.h


From: Akim Demaille
Subject: Re: config variables in config.h
Date: 05 Sep 2002 08:57:25 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

| Hello,
| I would like my program to know where it has been installed, in
| particular, the location of $datadir. Looks like a natural way to do
| it is to have a #define in config.h, like this:
| 
| /*
|  * myprog data directory
|  */
| #define MYPROG_DATA_DIR "/usr/local/share/myprog"
| 
| I tried the following in configure.in:
| 
| AC_DEFINE_UNQUOTED(MYPROG_DATA_DIR,$datadir,[myprog data directory])
| 
| but it doesn't work ($prefix/share is inserted and not expanded). I
| would appreciate it if someone could tell me how to do this properly.
| 
| Thanks in advance.

See the documentation.

Installation Directory Variables
--------------------------------

[...]

   Most of these variables have values that rely on `prefix' or
`exec_prefix'.  It is deliberate that the directory output variables
keep them unexpanded: typically address@hidden@' will be replaced by
`${prefix}/share', not `/usr/local/share'.

   This behavior is mandated by the GNU coding standards, so that when
the user runs:

`make'
     she can still specify a different prefix from the one specified to
     `configure', in which case, if needed, the package shall hard code
     dependencies corresponding to the make-specified prefix.

`make install'
     she can specify a different installation location, in which case
     the package _must_ still depend on the location which was compiled
     in (i.e., never recompile when `make install' is run).  This is an
     extremely important feature, as many people may decide to install
     all the files of a package grouped together, and then install
     links from the final locations to there.

   In order to support these features, it is essential that `datadir'
remains being defined as `${prefix}/share' to depend upon the current
value of `prefix'.

   A corollary is that you should not use these variables except in
Makefiles.  For instance, instead of trying to evaluate `datadir' in
`configure' and hardcoding it in Makefiles using e.g.
`AC_DEFINE_UNQUOTED(DATADIR, "$datadir")', you should add
`-DDATADIR="$(datadir)"' to your `CPPFLAGS'.

   Similarly you should not rely on `AC_OUTPUT_FILES' to replace
`datadir' and friends in your shell scripts and other files, rather let
`make' manage their replacement.  For instance Autoconf ships templates
of its shell scripts ending with `.sh', and uses this Makefile snippet:

     .sh:
             rm -f $@ address@hidden
             sed 's,@datadir\@,$(pkgdatadir),g' $< >address@hidden
             chmod +x address@hidden
             mv address@hidden $@

   Three things are noteworthy:

address@hidden@'
     The backslash prevents `configure' from replacing address@hidden@' in
     the sed expression itself.

`$(pkgdatadir)'
     Don't use address@hidden@'!  Use the matching makefile variable
     instead.

`,'
     Don't use `/' in the sed expression(s) since most probably the
     variables you use, such as `$(pkgdatadir)', will contain some.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]