(autoconf.info)Defining Directories

Next: Autom4te Cache Prev: Why Not Imake Up: FAQ

19.5 How Do I `#define' Installation Directories?

     My program needs library files, installed in `datadir' and
     similar.  If I use
          AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
            [Define to the read-only architecture-independent
             data directory.])

     I get
          #define DATADIR "${prefix}/share"

As already explained, this behavior is on purpose, mandated by the GNU
Coding Standards, see Note: Installation Directory Variables.  There
are several means to achieve a similar goal:

   - Do not use `AC_DEFINE' but use your makefile to pass the actual
     value of `datadir' via compilation flags.  Note: Installation
     Directory Variables, for the details.

   - This solution can be simplified when compiling a program: you may
     either extend the `CPPFLAGS':

          CPPFLAGS = -DDATADIR='"$(datadir)"' @CPPFLAGS@

     If you are using Automake, you should use `AM_CPPFLAGS' instead:

          AM_CPPFLAGS = -DDATADIR='"$(datadir)"'

     Alternatively, create a dedicated header file:

          DISTCLEANFILES = myprog-paths.h
          myprog-paths.h: Makefile
                  echo '#define DATADIR "$(datadir)"' >$@

   - Use `AC_DEFINE' but have `configure' compute the literal value of
     `datadir' and others.  Many people have wrapped macros to automate
     this task.  For instance, the macro `AC_DEFINE_DIR' from the
     Autoconf Macro Archive (http://autoconf-archive.cryp.to/).

     This solution does not conform to the GNU Coding Standards.

   - Note that all the previous solutions hard wire the absolute name of
     these directories in the executables, which is not a good
     property.  You may try to compute the names relative to `prefix',
     and try to find `prefix' at runtime, this way your package is

automatically generated by info2www