【问题标题】:Automatic generation of AC_CONFIG_FILES input自动生成 AC_CONFIG_FILES 输入
【发布时间】:2013-03-31 02:51:43
【问题描述】:

在创建 configure.ac 文件时,标准做法似乎是明确硬编码应从相应的 Makefile.in 创建的 Makefile 列表。然而,这似乎不是必需的,该列表可以很容易地从某种 glob 规范(例如 */Makefile.in)或从 shell 命令(例如 find -name Makefile.in)生成。

不幸的是,这个工具似乎没有内置在 autoconf 中!我是 m4 的新手,但我没有遇到任何关于运行 shell 命令来生成 m4 输入值的信息。显然,它可以通过cat-ing 文件和 shell 命令生成 configure.ac 文件来破解,但这似乎不必要地复杂。

有这样做的标准方法吗?如果没有,那为什么不呢?有什么问题吗?

【问题讨论】:

  • 不想这样做的原因之一是,如果您添加一个应该由AC_CONFIG_FILES 生成的新文件,它不会在以下时间生成你运行make。当您明确列出文件时,添加新模板会更改 configure.ac,这会强制重新运行(以及其他)autoconf(重建configure)、configure(重建config.status)和@987654331 @(重建模板输出)。
  • 你可以使用m4_esyscmd 破解一些东西,但请不要。
  • 您不需要生成configure.ac。如果您坚持,请使用find 命令并将结果放在AC_CONFIG_FILES 的参数列表中,但不要自动执行该过程。这在项目的生命周期中应该很少发生(即一次),并且应该由人来监控。对该列表所做的任何更改都应手动完成,以帮助防止构建膨胀。

标签: unix build-automation autotools autoconf


【解决方案1】:

尽管有 cmets,但我最终还是这样做了。我在问题中没有提到的是这种自动生成已经完成,但是以一种非常特别的方式(cating 将各种文件组合在一起,其中一些是动态生成的,以创建 configure.ac)我只是想把它清理干净。

在我们的构建脚本中:

confdir="config/configure.ac_scripts"

# Generate a sorted list of all the makefiles in the project, wrap it into
# an autoconfigure command and put it into a file.
makefile_list="$(find -type f -name 'Makefile.am' \
                | sed -e 's:Makefile\.am:Makefile:' -e 's:^./::' \
                | sort)"

# A bit more explanation of the above command:
# First we find all Makefile.ams in the project.
# Then we remove the .am using sed to get a list of Makefiles to create. We
# also remove the "./" here because the autotools don't like it.
# Finally we sort the output so that the order of the resulting list is
# deterministic.


# Create the file containing the list of Makefiles
cat > "$confdir/new_makefile_list" <<EOF
# GENERATED FILE, DO NOT MODIFY.
AC_CONFIG_FILES([
$makefile_list
])
EOF
# In case you haven't seen it before: this writes the lines between <<EOF
# and EOF into the file $confdir/new_makefile_list. Variables are
# substituted as normal.

# If we found some new dirs then write it into the list file that is
# included in configure.ac and tell the user. The fact that we have
# modified a file included in configure.ac will cause make to rerun
# autoconf and configure.
touch "$confdir/makefile_list"
if ! diff -q "$confdir/new_makefile_list" "$confdir/makefile_list" > /dev/null 2>&1; 
then
    echo "New/removed directories detected and $confdir/makefile_list updated,"
    echo "./configure will be rerun automatically by make."
    mv "$confdir/new_makefile_list" "$confdir/makefile_list"
fi

然后在 configure.ac 我们有:

# Include the file containing the constructed AC_CONFIG_FILES([....]) command
m4_include([config/configure.ac_scripts/makefile_list])

而不是直接写入 Makefile 列表。

完整的源代码是herehere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    相关资源
    最近更新 更多