2013-04-08 75 views
1

創建configure.ac文件時,標準做法似乎是明確硬編碼應該從相應的Makefile.in創建的Makefiles列表。然而,似乎這不是必須的,該列表可以容易地從某種全局規範(例如*/Makefile.in)或從shell命令(例如find -name Makefile.in)生成。自動生成AC_CONFIG_FILES輸入

不幸的是,它似乎並沒有將這個設備內置到autoconf中!我是m4的新手,但我還沒有遇到任何有關運行shell命令來生成m4輸入值的信息。很明顯,它可以通過將文件和shell命令一起生成configure.ac文件來破解,但這似乎不必要的複雜。

有沒有這樣做的標準方式?如果不是,那爲什麼不呢?有什麼問題嗎?

+2

您不希望這樣做的原因之一是,如果您添加了一個應該由'AC_CONFIG_FILES'生成的新文件,那麼當您運行'make'時它不會生成。當你明確列出文件時,添加一個新模板會改變'configure.ac',這會強制重新運行(其中包括)'autoconf'(重建'configure'),'configure'(重建'config.status' )和'config.status'(重建模板輸出)。 – 2013-04-08 21:18:11

+1

你可能會用'm4_esyscmd'破解一些東西,但請不要。 – 2013-04-08 21:19:17

+0

您不需要生成'configure.ac'。如果你堅持,使用'find'命令並將結果放在'AC_CONFIG_FILES'的參數列表中,但不要自動執行該過程。這是在項目生命週期中很少發生的事情(即一次),應該由人來監控。對該列表所做的任何更改都應手動完成,以防止構建膨脹。 – 2013-04-15 13:06:23

回答

0

儘管有評論,但我最終還是這樣做了。我在這個問題中沒有提到的是,這種自動生成已經完成,但是以一種非常特殊的方式(將各種文件彙集在一起​​,其中一些文件在飛行中生成,以創建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文件列表。

完整的源代碼是herehere