autoconf: Defining Directories
1
1 20.5 How Do I `#define' Installation Directories?
1 =================================================
1
1 My program needs library files, installed in `datadir' and
1 similar. If I use
1 AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
1 [Define to the read-only architecture-independent
1 data directory.])
1
1 I get
1 #define DATADIR "${prefix}/share"
1
1 As already explained, this behavior is on purpose, mandated by the GNU
1 Coding Standards, see ⇒Installation Directory Variables. There
1 are several means to achieve a similar goal:
1
1 - Do not use `AC_DEFINE' but use your makefile to pass the actual
11 value of `datadir' via compilation flags. ⇒Installation
Directory Variables, for the details.
1
1 - This solution can be simplified when compiling a program: you may
1 either extend the `CPPFLAGS':
1
1 CPPFLAGS = -DDATADIR='"$(datadir)"' @CPPFLAGS@
1
1 If you are using Automake, you should use `AM_CPPFLAGS' instead:
1
1 AM_CPPFLAGS = -DDATADIR='"$(datadir)"'
1
1 Alternatively, create a dedicated header file:
1
1 DISTCLEANFILES = myprog-paths.h
1 myprog-paths.h: Makefile
1 echo '#define DATADIR "$(datadir)"' >$@
1
1 The gnulib module `configmake' provides such a header with all the
11 standard directory variables defined, ⇒configmake
(gnulib)configmake.
1
1 - Use `AC_DEFINE' but have `configure' compute the literal value of
1 `datadir' and others. Many people have wrapped macros to automate
1 this task; for an example, see the macro `AC_DEFINE_DIR' from the
1 Autoconf Macro Archive
1 (http://www.gnu.org/software/autoconf-archive/).
1
1 This solution does not conform to the GNU Coding Standards.
1
1 - Note that all the previous solutions hard wire the absolute name of
1 these directories in the executables, which is not a good
1 property. You may try to compute the names relative to `prefix',
1 and try to find `prefix' at runtime, this way your package is
1 relocatable.
1