In an Autotools project I am trying to generate parts of my .conf file. The program needs to read from $(pkgdatadir)
, but I know that that variable is only set in Makefile.in
, so I instead substituted datadir
and PACKAGE
.
configure.ac:
AC_PREREQ([2.69])
AC_INIT([foo], [1.0.0], [[email protected]])
AC_CONFIG_SRCDIR([foo.c])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([m4])
AC_SUBST(datadir)
AC_SUBST(PACKAGE)
AC_CONFIG_FILES(foo.conf)
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_MKDIR_P
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
foo.conf.in:
Dir = @datadir@/@PACKAGE@
The resulting foo.conf:
Dir = ${prefix}/share/foo
I would like autoconf to evaluate the ${prefix}
when substituting, and I don't know how to make that happen.
Unfortunately, you can't substitute Makefile variables like
datadir
at configure-time, since they aren't fully expanded. (See the documentation here.)The unfortunate solution if you want to do both configure-time and build-time substitutions is to do a two-step substitution, from
foo.conf.in.in
tofoo.conf.in
at configure time, andfoo.conf.in
tofoo.conf
at build time:in configure.ac:
in Makefile.am:
in foo.conf.in.in:
I happen to use
%
signs for build-time substitutions so that I don't confuse them with configure-time substitutions marked by@
. The makefile rule above also makes the generatedfoo.conf
readonly so that you don't edit it by mistake and get your changes overwritten.