为了生成Makefile需要使用以下工具。
autoscanaclocalautoconfautoheaderautomake这些工具在autoconf安装包和automake安装包中。可以下载源码安装。在安装时还需m4配合,没有的话网上找找。
在源代码目录中执行 autoscan,将会生成configure.scan和autoscan.log文件。
编辑configure.scan文件,通常添加如下两行: AM_INIT_AUTOMAKE(hello, 1.0) AC_CONFIG_FILES([Makefile]) 并另存为configure.ac(或configure.in)。
执行aclocal,工具根据configure.ac(或configure.in)生成aclocal.m4文件和autom4te.cache文件夹。
执行autoconf,生成configure文件。
执行autoheader,生成config.h.in文件。
先新建文件Makefile.am,添加如下内容:
AUTOMAKE_OPTIONS=foreign //automake的等级,有三种。这里用foreign。 bin_PROGRAMS=hello //指出目标文件的名字,这里为hello hello_SOURCES=hello.c //指出依赖,可以是多个执行automake,提示: configure.ac:8: error: required file './install-sh' not found configure.ac:8: 'automake --add-missing' can install 'install-sh' configure.ac:8: error: required file './missing' not found configure.ac:8: 'automake --add-missing' can install 'missing' Makefile.am: error: required file './depcomp' not found Makefile.am: 'automake --add-missing' can install 'depcomp'
执行automake --add-missing,再执行automake
此时就会创建Makefile文件了。
因此,在autotools的使用过程中,必须要编辑的文件只有configure.ac 和 Makefile.am
此外,autotools工具还提供 make dist 打包功能
执行 make dist
根据configure.ac中
AC_INIT( [ hello ], [ 1.0 ] )
生成hello-1.0.tar.gz的源码包文件。