GNU/Autotools 使用流程分析

Cmake 的意义在于跨越各种操作系统,Autotools 的意义在于跨越各种Unix 。

编译开源软件经常会遇到这种固定安装方式:

./configure
make
make install

这样的软件一般都是使用 GNU 的 Autotools 进行软件编译的,通常我们说的 Autotools 是一套工具集一般包含下面几个 GNU 开源项目:

  • Autoconf: autoscan autoconf autoheader autoreconf autoupdate autom4te ifnames
  • Automake: automake aclocal
  • Libtool: libtoolize

Debian 系统下安装 autotools 方法为 apt install automake autoconf libtool m4
可以使用 apt-file list autoconf |grep "/usr/bin" 来查看每个包都包含哪些应用软件

Dominik Kern 大神的个人主页上有一个经典教程讲述了怎么使用 Autotools 来开发应用,下图为教程中的一个图例:

这里写图片描述

我自己写了一个 Autotools 的例子放到了 Github 上面 autotools_hello ,使用的方式比较简单,使用 autogen.sh 去生成 configure config.h.in Makefile.in 等文件,使用 autoremove.sh 重新初始化文件
下面是 autogen.sh 的文件内容,从中可以看出 Autotools 工具的使用顺序:

#!/bin/sh
# autogen.sh
aclocal && \
    autoheader && \
    libtoolize && \
    autoconf && \
    touch NEWS README AUTHORS ChangeLog && \
    automake --add-missing --force-missing --copy

Autotools运行流程图:
这里写图片描述


流程总结:

  1. 执行 autoscan 命令。这个命令主要用于扫描工作目录,并且生成 configure.scan 文件;
  2. 修改 configure.scanconfigure.ac 文件,并且修改配置内容,语法参考 Autoconf 文档
  3. 执行 aclocal 命令。扫描 configure.ac 文件生成 aclocal.m4 文件;
  4. 执行 autoheader 命令。生成 config.h.in 文件;
  5. 执行 libtoolize 命令。如果生成库文件需要用到这一步骤;
  6. 执行 autoconf 命令。将 configure.ac 文件中的宏展开,生成 configure 脚本;
  7. 新增 Makefile.am 文件,修改配置内容,语法参考 Automake 文档Libtool 文档
  8. 执行 automake 命令。生成 Makefile.in 文件;

经过上面的8个步骤在工程目录下就会生成 configure, config.h.in, Makefile.in 三个文件,接下来就是经典的 ./configure -> make -> make install 了。


参考文档

  1. An Introduction to the Autotools
  2. Getting started with the autotools: a “Hello World” example
  3. Autotools使用详细解读
  4. 在 Linux 中使用 Eclipse 和 Gnu Autotools 管理 C/C++ 项目
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值