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

查看:48
本文介绍了如何在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.

我无法获得 $abs_top_builddir 的合理值,除非它是通过替换(即,AC_CONFIG_FILES).根据预设输出变量(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

测试输入:

#!/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天全站免登陆