如何获取autoconf configure.ac中顶级构建目录的绝对路径? [英] How to get absolute path to top build directory in autoconf configure.ac?

查看:196
本文介绍了如何获取autoconf configure.ac中顶级构建目录的绝对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,该项目需要一个具有自己的makefile和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.

无论哪种情况,我都会在Makefile.am中使用一个包含程序路径的变量.

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

我的问题是,当使用项目的本地版本时,如何获取其在Makefile.am中使用的位置?

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

我尝试过

FOOPLACE=${abs_top_builddir}/bar/foo

但这总是使FOOPLACE仅包含/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.

推荐答案

我只是用一个简单的configure.ac做了一些测试.

I just did some testing with a simple configure.ac.

除非通过替换(即AC_CONFIG_FILES),否则我无法获得$abs_top_builddir的合理值.根据预设输出变量(autoconf),它们至少在config.status(即AC_CONFIG_COMMANDS)期间可用.他们不是.

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.

深入研究config.status,我发现@abs_top_builddir@被设置为$ac_abs_top_builddir的值.这似乎很奇怪,我认为这可能是一个错误. 我已将其发送给bug-autoconf 以了解他们的想法.

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.

故事的寓意:应该在替换完成后起作用.您也许可以在config.status中使用$ac_abs_top_builddir,但是我不会依赖它.

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.

这是我使用的测试:

configure.ac:

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@"

使用autoconf && ./configure && ./test运行它.

这篇关于如何获取autoconf configure.ac中顶级构建目录的绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆