儘管有評論,但我最終還是這樣做了。我在這個問題中沒有提到的是,這種自動生成已經完成,但是以一種非常特殊的方式(將各種文件彙集在一起,其中一些文件在飛行中生成,以創建configure.ac)和I只是想清理它。
在構建腳本有:
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文件列表。
完整的源代碼是here和here。
您不希望這樣做的原因之一是,如果您添加了一個應該由'AC_CONFIG_FILES'生成的新文件,那麼當您運行'make'時它不會生成。當你明確列出文件時,添加一個新模板會改變'configure.ac',這會強制重新運行(其中包括)'autoconf'(重建'configure'),'configure'(重建'config.status' )和'config.status'(重建模板輸出)。 – 2013-04-08 21:18:11
你可能會用'm4_esyscmd'破解一些東西,但請不要。 – 2013-04-08 21:19:17
您不需要生成'configure.ac'。如果你堅持,使用'find'命令並將結果放在'AC_CONFIG_FILES'的參數列表中,但不要自動執行該過程。這是在項目生命週期中很少發生的事情(即一次),應該由人來監控。對該列表所做的任何更改都應手動完成,以防止構建膨脹。 – 2013-04-15 13:06:23