【问题标题】:Use shell commands to find Makefile.am in configure.ac使用 shell 命令在 configure.ac 中找到 Makefile.am
【发布时间】:2013-08-13 04:32:32
【问题描述】:

我正在尝试添加一些 shell 命令以在我的项目 autoconf 中自动搜索 Makefile.am(这样我就不必担心下次有新的 Makefile.am 时忘记添加条目)。但这似乎不起作用。我试图创建一个最小的项目设置来说明这个问题。项目目录包含:

├── AUTHORS
├── ChangeLog
├── common.mk.in
├── configure.ac
├── COPYING
├── INSTALL
├── install-sh
├── Makefile.am
├── missing
├── NEWS
├── proj1
│   ├── Makefile.am
│   ├── module1
│   │   └── Makfile.am
│   └── module2
│       └── Makfile.am
├── proj2
│   ├── Makefile.am
│   ├── module1
│   │   └── Makfile.am
│   └── module2
│       └── Makfile.am
└── README

这里的大多数文件都是空的,除了:

---------configure.ac---------

AC_INIT([TEST], [1.0])
found_makefile_am=`find . -name 'Makefile.am' | sed -e 's/\.am$//g' -e 's/^\.\///g' | sed ':a;N;$!ba;s/\n/ /g'`
found_mk=`find . -name '*.mk.in' | sed -e 's/\.am$//g' -e 's/^\.\///g' | sed ':a;N;$!ba;s/\n/ /g'`
AM_INIT_AUTOMAKE
#AC_CONFIG_FILES([proj2/Makefile proj1/Makefile Makefile])
AC_CONFIG_FILES([${found_makefile_am}])
AC_CONFIG_FILES([${found_mk}])
AC_OUTPUT

---------proj*/Makefile.am---------

SUBDIRS = module1 module2

注意这一行:

AC_CONFIG_FILES([${found_mk}])

完美运行,但这个:

AC_CONFIG_FILES([${found_makefile_am}])

失败:

$autoreconf -i
automake-1.12: error: no 'Makefile.am' found for any configure output
automake-1.12: Did you forget AC_CONFIG_FILES([Makefile]) in configure.ac?
autoreconf-2.69: automake failed with exit status: 1

我不得不将其替换为:

AC_CONFIG_FILES([proj2/Makefile proj1/Makefile Makefile])

在我看来,shell 变量在 autoconfig 调用 automake 之前没有正确展开。那么有没有办法解决这个问题呢?

【问题讨论】:

    标签: autotools autoconf automake


    【解决方案1】:

    填充configure.ac 需要在autoconf 运行之前发生,因此任何shell 命令都应该由m4_esyscmd 调用。注意我给你的建议是用锤子敲拇指的最佳方法,也就是说你真的不应该这样做,但是如果你想自动填充 AC_CONFIG_FILES 的内容,你可以这样做:

    AC_CONFIG_FILES(m4_esyscmd([find ...]))
    

    其中...find 命令的剩余部分。这将在 m4 在 autoconf 期间运行时调用 find 命令,而不是等到用户执行配置脚本。这是必要的,因为您需要在运行 automake 之前找到 Makefile.am 文件,并且在配置脚本之前很久就会调用 automake。

    【讨论】:

      【解决方案2】:

      我想这可能无法按照 automake 手册中的说明完成:

      http://www.gnu.org/software/automake/manual/automake.html#Requirements

      请注意,您不应使用 shell 变量来声明 Makefile 文件 automake 必须为其创建 Makefile.in。甚至 AC_SUBST 也没有 帮助在这里,因为automake在运行时需要知道文件名 为了检查 Makefile.am 是否存在。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-16
        • 1970-01-01
        • 2017-03-23
        • 2015-11-18
        • 2017-08-09
        • 2016-04-14
        • 2012-11-22
        相关资源
        最近更新 更多