1

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

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

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

4

1 回答 1

0

尽管有评论,但我最终还是这样做了。我在问题中没有提到的是这种自动生成已经完成,但是以一种非常特别的方式(cat将各种文件组合在一起,其中一些是动态生成的,以创建 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 列表。

完整的源代码在这里这里

于 2015-04-16T15:14:00.540 回答