How to get absolute path to top build directory in autoconf configure.ac?
I just did some testing with a simple configure.ac
.
I couldn't get a sensible value for $abs_top_builddir
unless it was through a substitution (i.e., AC_CONFIG_FILES
). According to Preset Output Variables(autoconf), they should at least be available during config.status
(i.e., AC_CONFIG_COMMANDS
). They are not.
Diving into config.status
, I found that @abs_top_builddir@
was set to the value of $ac_abs_top_builddir
. This seems strange, and I think it may be a bug. I have sent it to bug-autoconf to see what they think.
Moral of the story: It should work anywhere substitutions are done. You may be able to use $ac_abs_top_builddir
within config.status
, but I wouldn't rely on it.
Here is the test I used:
configure.ac:
AC_PREREQ([2.67])
AC_INIT([], [0], [[email protected]])
AC_MSG_NOTICE([notice: ${abs_top_builddir}])
AC_MSG_NOTICE([notice+ac: ${abs_top_builddir}])
AC_CONFIG_COMMANDS_PRE([echo "pre+ac: ${ac_abs_top_builddir}"])
AC_CONFIG_COMMANDS_PRE([echo "pre: ${abs_top_builddir}"])
AC_CONFIG_COMMANDS_POST([echo "post+ac: ${ac_abs_top_builddir}"])
AC_CONFIG_COMMANDS_POST([echo "post: ${abs_top_builddir}"])
AC_CONFIG_COMMANDS([echo],
[echo "config.status+ac: ${ac_abs_top_builddir}"
echo "config.status: ${abs_top_builddir}"])
AC_CONFIG_FILES([test], [chmod +x test])
AC_OUTPUT
test.in:
#!/bin/sh
# -*- sh -*-
# @configure_input@
echo "test: @abs_top_builddir@"
echo "test+ac: @ac_abs_top_builddir@"
Run it with autoconf && ./configure && ./test
.