天天看点

GNU autotools 安装和使用

1. 下载

http://www.gnu.org/software/software.html

2. 安装

m4-1.4.11.tar.gz

autoconf-2.63.tar.gz

automake-1.9.1.tar.gz

3. autotools五工具

  • aclocal
  • autoscan
  • autoconf
  • autoheader
  • automake

4. autotools使用流程

第一步:手工编写Makefile.am这个文件

第二步:在源代码目录树的最高层运行autoscan。然后手动修改configure.scan文件,并改名为configure.ac/configure.in

第三步:运行aclocal,它会根据configure.ac的内容生成aclocal.m4文件

第四步:运行autoconf,它根据configure.ac和aclocal.m4的内容生成configure这个配置脚本文件

第五步:运行automake –add-missing,它根据Makefile.am的内容生成Makefile.in

第六步:运行configure,它会根据Makefile.in的内容生成Makefile这个文件

5. 流程图

GNU autotools 安装和使用

6. 举例

# cat hello.c 

#include <stdio.h>
#include "include/hello.h"

int main()
{
        puts("hello");

        return ;
}
           
# cat Makefile.am   //automake使用

SUBDIRS = lib
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = hello
hello_SOURCES = hello.c
hello_LDADD = lib/libprint.a
           

AUTOMAKE_OPTIONS为设置automake的选项。automake提供了3种软件等级:

  • foreign //只检测必须的文件
  • gnu //默认级别
  • gnits

SUBDIRS:子目录选项

bin_PROGRAMS:如果多个执行文件, 用空格隔开

hello_SOURCES:”hello”这个可执行程序所需的原始文件。如果”hello”这个程序是由多个源文件所产生, 所有源文件用空格隔开

# cat lib/Makefile.am

noinst_LIBRARIES = libprint.a
libprint_a_SOURCES = print.c ../include/print.h
           
# ls include

hello.h
print.h
           

7. 开始使用

生成configure.scan

//修改(软件名称, 版本信息, bug汇报E-mail)
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
//为
AC_INIT(hello, 0.01, [[email protected].org])
AM_INIT_AUTOMAKE
AC_PROG_RANLIB
           

重命名为configure.ac

AC_CONFIG_SCRDIR:宏用来侦测所指定的源码文件是否存在, 来确定源码目录的有效性

AC_CONFIG_HEADER:宏用于生成config.h文件,以便 autoheader 命令使用

AC_PROG_CC:用来指定编译器,如果不指定,默认gcc

AC_CONFIG_FILES:宏用于生成相应的Makefile文件

AC_OUTPUT:用来设定 configure 所要产生的文件,如果是makefile,configure 会把它检查出来的结果带入makefile.in文件产生合适的makefile

# aclocal
# autoconf
# autoheader
# automake --add-missing
           

Automake工具会根据 configure.in 中的参量把 Makefile.am 转换成 Makefile.in 文件

–add-missing:可以让 Automake 自动添加一些必需的脚本文件

再次运行,可以辅助生成几个必要的文件:

Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./README' not found
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
           

解决办法:手动touch

# ./configure
# make
           

继续阅读