自动生成AC_CONFIG_FILES输入

时间:2013-04-08 21:07:44

标签: unix build-automation autotools autoconf

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

不幸的是,似乎这个设施并没有内置到autoconf中!我是m4的新手,但我没有遇到任何关于运行shell命令来生成m4输入值的事情。显然,可以通过cat生成configure.ac文件来共同攻击文件和shell命令,但这似乎不必要地复杂。

有没有一种标准的方法可以做到这一点?如果不是那么为什么不呢?有什么问题吗?

1 个答案:

答案 0 :(得分:0)

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