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

爱⌒轻易说出口 提交于 2019-12-23 07:49:41

问题


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.


回答1:


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], [foo@example.com])
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.




回答2:


Looking inside a configure script, I see the absolute path to where the configure script is being run from is set by using

ac_abs_confdir=`(
    cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
    pwd)`

I've tested it by using $ac_abs_confdir in configure.ac and it works.



来源:https://stackoverflow.com/questions/15041754/how-to-get-absolute-path-to-top-build-directory-in-autoconf-configure-ac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!