autotools 系列工具安装以及使用方法

xiaoxiao2021-02-28  152

1 安装autotools系列工具

为了生成Makefile需要使用以下工具。

autoscanaclocalautoconfautoheaderautomake

这些工具在autoconf安装包和automake安装包中。可以下载源码安装。在安装时还需m4配合,没有的话网上找找。


2 具体使用流程:

2.1:autoscan

在源代码目录中执行 autoscan,将会生成configure.scan和autoscan.log文件。

编辑configure.scan文件,通常添加如下两行: AM_INIT_AUTOMAKE(hello, 1.0) AC_CONFIG_FILES([Makefile]) 并另存为configure.ac(或configure.in)。

2.2:aclocal

执行aclocal,工具根据configure.ac(或configure.in)生成aclocal.m4文件和autom4te.cache文件夹。

2.3:autoconf

执行autoconf,生成configure文件。

2.4:autoheader

执行autoheader,生成config.h.in文件。

2.5:automake

先新建文件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的源码包文件。

转载请注明原文地址: https://www.6miu.com/read-29683.html

最新回复(0)