autotools归纳,autotools


最近接触到许多linux项目,其编译都是使用的autotools。
autotools是一个自动化的编译工具。个人理解它的最主要功能就是生成Makefile。
因为直接写Makefiel,其依赖关系还是比较复杂的。

一般的我们下载的源码包只要通过以下3条命令,就可完成编译和安装:
./configure
make
sudo make install

但是autotools其本来还是非常复杂的,下面给出参考
以下是命令列表:
autoscan        扫描给定的目录及其子目录,以搜寻普通的可移植性问题,比如检查编译器,库,头文件等。
                生成的configure.scan是configure.ac文件的原型。

aclocal         是一个收集宏的过程。
                将已经安装的宏、用户定义宏和acinclude.m4文件中的宏集中定义到文件aclocal.m4中。

autoheader      生成宏定义的模板文件config.h.in。
                宏定义模板文件被后面的命令所需要。

automake        根据configure.ac和Makefile.am中定义的结构,生成Makefile.in文件。

libtoolize      如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOO,automake将会调用此命令。

autoconf        生成configure脚本文件。

make distclean  清除所有生成的文件

./configure     生成Makefile。

make            编译。

make install    把程序安装到系统目录中去。

make uninstall  卸载程序。

make clean      清除生成的目标文件及过程中产生的文件。

make distclean  清除所有产生的文件。

make dist       将程序和相关的文档打包为一个.tar.gz压缩文件以供发布。

autoupdate      如果更新了Autoconf工具的版本,此命令可更新configure.in。
autoreconfig    如果更新了Autoconf工具的版本,此命令可更新产生的配置文件。
ifname          扫描C源程序文件,在标准输出上输出那些出现在#if,#elif,#ifdef或#ifndef中的标识符,
                每个标识符显示为一行,其后跟一空格和所属的文件名。

command       input              output
--------------------------------------------------
autoscan      [source]           configure.scan
                                 autoscan.log

aclocal       configure.ac       aclocal.m4

autoheader    aclocal.m4         autoconfig.h.in

automake      configure.ac       INSTALL
              makefile.am        Makefile.in
                                 COPYING
                                 install-sh
                                 missing
                                 mkinstalldirs
                                 stamp-h.in

libtoolize                       config.guess
                                 config.sub
                                 ltmain.sh
                                 ltconfig

autoconf      configure.ac       configure
              aclocal.m4
              autoconfig.h.in


command         input                      output
-----------------------------------------------------------------
configure       configure                  Makefile
                Makefile.in                config.h
                cofnig.h.in                config.log
                XXXXX.pc.in                config.status
                XXXXX-uninstalled.pc.in    libtool
                                           XXXXX.pc
                                           XXXXX-uninstalled.pc
                                           stamp-h1

make            Makefile

make install    Makefile

make uninstall  Makefile

make clean      Makefile

make distclean  Makefile

make dist       Makefile

linux中怎安装autotools系列工具

autotools使用流程
正如前面所言,autotools是系列工具,读者首先要确认系统是否装了以下工具(可以用which命令进行查看)。
· aclocal
· autoscan
· autoconf
· autoheader
· automake
使用autotools主要就是利用各个工具的脚本文件以生成最后的Makefile。其总体流程是这样的:
· 使用aclocal生成一个“aclocal.m4”文件,该文件主要处理本地的宏定义;
· 改写“configure.scan”文件,并将其重命名为“configure.in”,并使用autoconf文件生成configure文件。
接下来,笔者将通过一个简单的hello.c例子带领读者熟悉autotools生成makefile的过程,由于在这过程中有涉及到较多的脚本文件,为了更清楚地了解相互之间的关系,强烈建议读者实际动手操作以体会其整个过程。
1.autoscan
它会在给定目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目录树中进行检查。它会搜索源文件以寻找一般的移植性问题并创建一个 文件“configure.scan”,该文件就是接下来autoconf要用到的“configure.in”原型。如下所示:
[root@localhost automake]# autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@localhost automake]# ls
autoscan.log configure.scan hello.c
如上所示,autoscan首先会尝试去读入“configure.ac”(同configure.in的配置文件)文件,此时还没有创建该配置文件,于是它会自动生成一个“configure.in”的原型文件“configure.scan”。
2.autoconf
configure.in是autoconf的脚本配置文件,它的原型文件“configure.scan”如下所示:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
#The next one is modified by sunq
#AC_INIT(FULL-PACKAGE-NAME,VERSION,BUG-REPORT-ADDRESS)
AC_INIT(hello,1.0)
# The next one is added by sunq
AM_INIT_AUTOMAKE(hello,1.0)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
下......余下全文>>
 

Linux autotools有什用

一般的项目编译安装的过程:
o bootstrap:检测autoconf、automake、libtool及其版本并完成初始化,生成configure;
o configure:检测系统平台及软硬件环境,确定适用本地环境的编译策略,生成Makefiles;
o make:编译、链接;
o make install:安装;
o ldconfig:配置环境变量。
对于开发者而言,则需要通过autotools的autoconf、automake为用户组织起上面的过程。
 

相关内容

    暂无相关文章