Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get absolute path to top build directory in autoconf configure.ac?

I am working on a project which requires a subproject which has its own makefile and configure.ac. The subproject is a program which is used to generate source files for the main project. There is an option to disable the building of this project and attempt to use an installed version instead.

In either case I create a variable which is used in my Makefile.am containing the path to the program.

My question is, When using the local version of the project, how can I get its location for use in my Makefile.am?

I have tried

FOOPLACE=${abs_top_builddir}/bar/foo

But this always makes FOOPLACE contain only /bar/foo. I'm also not even sure this will be the right way to do this though even in principle.

like image 444
crobar Avatar asked Feb 23 '13 14:02

crobar


1 Answers

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.

like image 83
Jack Kelly Avatar answered Nov 04 '22 15:11

Jack Kelly