`

OS + Linux RedHat Autotools aclocal / autoscan / autoconf / autoheader /automake

    博客分类:
  • OS
 
阅读更多

Auto Tools使用流程

http://vaqeteart.iteye.com/blog/900666

图解autoscan、aclocal、autoheader、automake、autoconf、configure、make

http://baigoogledu.blog.51cto.com/738227/153552

http://hi.baidu.com/yzkuang/blog/item/557e4f24423d8136c9955908.html

 

Auto Tools使用流程
本文内容:
一、简介
二、AutoTools相关说明
三、实际例子

一、简介
=============
本文简单介绍最简单的auto tools工具的使用流程。
对于一个UNIX/Linux下C程序员来说,一个比较麻烦的工作就是写自己的Makefile。
可能你有如下经验:写一个简单的C程序,自己多写几行gcc命令就把程序变成可执行的了;写一个稍微复杂点的程序,源文件个数可能在30个左右,还是写一 行行的gcc命令就麻烦了,你可能想到写个makefile,你可能也在这样做着;但你某一天会发现你写的这个Makefile可能不是一个所有 UNIX/Linux类操作系统下通用的Makefile,比如某人下载了你的程序去他自己电脑上可能make不了。这样,你就有必要了解并学会运用 autoconf和automake了。
本节要讲的autotools系列工具正是为此而设的,它只需用户输入简单的目标文件、依赖文件、文件目录等就可以轻松地生成Makefile了,这无疑 是广大用户的所希望的。另外,这些工具还可以完成系统配置信息的收集,从而可以方便地处理各种移植性的问题。也正是基于此,现在Linux上的软件开发一 般都用autotools来制作Makefile。

二、AutoTools相关说明

============= =============

autotools 是系列工具 , 它含有 :
• aclocal
• autoscan
• autoconf
• autoheader
• automake
============= =============
在开始使用autoconf和automake之前,首先确认你的系统安装有GNU的如下软件:
1. automake
2. autoconf
3. m4
4. perl
5. 如果你需要产生共享库(shared library)则还需要GNU Libtool

autoconf和automake工作的几个步骤:
步骤解释如下:
1、由你的源文件通过autoscan命令生成configure.scan文件,然后修改configure.scan文件并重命名为configure.in
2、由aclocal命令生成aclocal.m4
3、由autoconf命令生成configure
4、编辑一个Makefile.am文件并由automake命令生成Makefile.in文件
5、运行configure命令生成Makefile

automake支持三种目录层次:flat、shallow和deep。
一个flat包指的是所有文件都在一个目录中的包。为这类包提供的Makefile.am不需要SUBDIRS这个宏。这类包的一个例子是termutils。对应咱们程序员来说:就是所有源文件及自己写的头文件都位于当前目录里面,且没有子目录。
一个deep包指的是所有的源代码都被储存在子目录中的包;顶层目录主要包含配置信息。GNU cpio是这类包的一个很好的例子,GNU tar也是。deep包的顶层Makefile.am将包括宏SUBDIRS,但没有其它定义需要创建的对象的宏。对应咱们程序员来说:就是所有源文件及 自己写的头文件都位于当前目录的一个子目录里面,而当前目录里没有任何源文件。
一个shallow包指的是主要的源代码储存在顶层目录中,而各个部分(典型的是库)则储存在子目录中的包。automake本身就是这类包(GNU make也是如此,它现在已经不使用automake)。对应咱们程序员来说:就是主要源文件在当前目录里,而其它一些实现各部分功能的源文件各自位于不 同目录。
前两个层次的程序编辑方法非常简单,按照上述步骤一步步即可。而第三种层次shallow稍微复杂一点,但这是我们经常写程序用到的结构。下面以一个例子说明shallow层次结构的源文件如何自动生成Makefile文件。

本文只是用一个非常简单的例子,记录了一个使用autotools的实践步骤:
更高级的用法,需要仔细学习这个系列工具的用户手册。

 

 

 

图解autoscan、aclocal、autoheader、automake、autoconf、configure、make
2008年05月13日 星期二 16:42

1.autoscan (autoconf): 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。

    your source files --> [autoscan*] --> [configure.scan] --> configure.ac

 

2.aclocal (automake):根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”

 

user input files   optional input     process          output files
================   ==============     =======          ============

                    acinclude.m4 - - - - -.
                                          V
                                      .-------,
configure.ac ------------------------>|aclocal|
                 {user macro files} ->|       |------> aclocal.m4
                                      `-------'
3.autoheader(autoconf): 根据configure.ac中的某些宏,比如cpp宏定义,运行m4,声称config.h.in

user input files    optional input     process          output files
================    ==============     =======          ============

                    aclocal.m4 - - - - - - - .
                                             |
                                             V
                                     .----------,
configure.ac ----------------------->|autoheader|----> autoconfig.h.in
                                     `----------'

4.automake: automake将Makefile.am中定义的结构建立Makefile.in,然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它 会自己产生config.guess和config.sub

user input files   optional input   processes          output files
================   ==============   =========          ============

                                     .--------,
                                     |        | - - -> COPYING
                                     |        | - - -> INSTALL
                                     |        |------> install-sh
                                     |        |------> missing
                                     |automake|------> mkinstalldirs
configure.ac ----------------------->|        |
Makefile.am  ----------------------->|        |------> Makefile.in
                                     |        |------> stamp-h.in
                                 .---+        | - - -> config.guess
                                 |   |        | - - -> config.sub
                                 |   `------+-'
                                 |          | - - - -> config.guess
                                 |libtoolize| - - - -> config.sub
                                 |          |--------> ltmain.sh
                                 |          |--------> ltconfig
                                 `----------'

5.autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。

user input files   optional input   processes          output files
================   ==============   =========          ============

aclocal.m4 ,autoconfig.h.in - - - - - - -.
                                         V
                                     .--------,
configure.ac ----------------------->|autoconf|------> configure
 
6. ./configure的过程
                                           .-------------> [config.cache]
     configure* --------------------------+-------------> config.log
                                          |
              [config.h.in] -.            v            .--> [autoconfig.h]
                             +-------> config.status* -+                   
              Makefile.in ---'                         `-->   Makefile
 
7. make过程
 
[autoconfig.h] -.
                     +--> make* --->  程序
        Makefile   ---'
 
.---------,
                   config.site - - ->|         |
                  config.cache - - ->|configure







| - - -> config.cache
                                     |         +-,
                                     `-+-------' |
                                       |         |----> config.status
                   config.h.in ------->|config-  |----> config.h
                   Makefile.in ------->|  .status|----> Makefile
                                       |         |----> stamp-h
                                       |         +--,
                                     .-+         |  |
                                     | `------+--'  |
                   ltmain.sh ------->|ltconfig|-------> libtool
                                     |        |     |
                                     `-+------'     |
                                       |config.guess|
                                       | config.sub |
                                       `------------'

 

.--------,
                   Makefile ------>|        |
                   config.h ------>|  make







  |
{project sources} ---------------->|        |--------> {project targets}
                                 .-+        +--,
                                 | `--------'  |
                                 |   libtool   |
                                 |   missing   |
                                 |  install-sh |
                                 |mkinstalldirs|
                                 `-------------'

 

These critical programs are missing or too old: as ld 

http://blog.csdn.net/testcs_dn/article/details/45437903

 onfigure 时出现以下错误:

 

checking for autoconf... no

configure: error:

*** These critical programs are missing or too old: as ld

*** Check the INSTALL file for required versions.

 

问题原因: 

缺少autoconf或版本太低

 

下载安装新版本

 

# wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz

# tar zxvf autoconf-2.68.tar.gz

# cd autoconf-2.68

# ./configure --prefix=/usr/

# make && make install

 

查看当前版本:

 

# autoconf -V

autoconf (GNU Autoconf) 2.68

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+/Autoconf: GNU GPL version 3 or later

<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

 

Written by David J. MacKenzie and Akim Demaille.

 

注意是大写的V。

 

end

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics