1

configure.ac ファイルを作成するときの標準的な方法は、対応する Makefile.in から作成する必要がある Makefile のリストを明示的にハードコーディングすることです。ただし、これは必要ないように思われます。リストは、ある種の glob 仕様 (例: */Makefile.in) またはシェル コマンド (例: find -name Makefile.in) から簡単に生成できます。

残念ながら、この機能が autoconf に組み込まれているようには見えません! 私は m4 を初めて使用しますが、シェル コマンドを実行して m4 入力値を生成する方法については何も知りませんでした。明らかに、catファイルとシェル コマンドを一緒に -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 に答える