一、生成configure过程中各文件之间的关系图

二、详细介绍

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

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

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

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

三、实例

1.测试代码(定义两个文件hello.h和hello.c)

/*hello.c*/
#include <iostream>
#include "hello.h" using namespace std; int main()
{
CHello a;
return ;
}
/*hello.h*/
#ifndef __HELLO_H__
#define __HELLO_H__ #include<iostream>
using namespace std; class CHello
{
public:
CHello(){ cout<<"Hello!"<<endl;}
~CHello(){ cout<<"Bye!"<<endl;}
}; #endif

2.操作步骤

(1)安装依赖的包

[root@bogon autoconfig]# yum -y install automake autoconf

automake包括:aclocal、automake等

autoconf包括:autoscan、autoconf等

(2)autoscan

[root@bogon autoconfig]# ll
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h
[root@bogon autoconfig]# autoscan
[root@bogon autoconfig]# ll
total
-rw-r--r-- root root Jun autoscan.log
-rw-r--r-- root root Jun configure.scan
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h

(3)aclocal

[root@bogon autoconfig]# mv configure.scan configure.ac
[root@bogon autoconfig]# vim configure.ac /*将下面红色加粗的部分修改掉*/
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(hello, 1.0, admin@163.com)
AM_INIT_AUTOMAKE(hello, 1.0)
AC_CONFIG_SRCDIR([hello.cpp])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC # Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile)
[root@bogon autoconfig]# aclocal
[root@bogon autoconfig]# ll
total
-rw-r--r-- root root Jun aclocal.m4
drwxr-xr-x root root Jun autom4te.cache
-rw-r--r-- root root Jun autoscan.log
-rw-r--r-- root root Jun configure.ac
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h

下面给出本文件的简要说明(所有以”#”号开始的行为注释):
· AC_PREREQ 宏声明本文件要求的autoconf版本,本例使用的版本为2.59。
· AC_INIT 宏用来定义软件的名称和版本等信息,”FULL-PACKAGE-NAME”为软件包名称,”VERSION”为软件版本号,”BUG-REPORT-ADDRESS”为BUG报告地址(一般为软件作者邮件地址)。
·AC_CONFIG_SRCDIR 宏用来侦测所指定的源码文件是否存在,来确定源码目录的有效性。此处为当前目录下的hello.c。
·AC_CONFIG_HEADER 宏用于生成config.h文件,以便autoheader使用。
·AC_PROG_CC 用来指定编译器,如果不指定,选用默认gcc。
·AC_OUTPUT 用来设定 configure 所要产生的文件,如果是makefile,configure会把它检查出来的结果带入makefile.in文件产生合适的makefile。使用Automake时,还需要一些其他的参数,这些额外的宏用aclocal工具产生。

(3)autoconf

[root@bogon autoconfig]# autoconf
[root@bogon autoconfig]# ll
total
-rw-r--r-- root root Jun aclocal.m4
drwxr-xr-x root root Jun autom4te.cache
-rw-r--r-- root root Jun autoscan.log
-rwxr-xr-x root root Jun configure
-rw-r--r-- root root Jun configure.ac
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h

此时可以看到已经生成了configure

(4)autoheader

[root@bogon autoconfig]# autoheader
[root@bogon autoconfig]# ll
total
-rw-r--r-- root root Jun aclocal.m4
drwxr-xr-x root root Jun autom4te.cache
-rw-r--r-- root root Jun autoscan.log
-rw-r--r-- root root Jun config.h.in
-rwxr-xr-x root root Jun configure
-rw-r--r-- root root Jun configure.ac
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h

autoheader生成了configure.h.in如果在configure.ac中定义了AC_CONFIG_HEADER,那么此文件就需要;

(5)Makefile.am

[root@bogon autoconfig]# vim Makefile.am
[root@bogon autoconfig]# cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.cpp hello.h

· AUTOMAKE_OPTIONS 为设置Automake的选项。由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则Automake执行时会报错。Automake提供了3种软件等级:foreign、gnu和gnits,供用户选择,默认等级为gnu。本例使需用foreign等级,它只检测必须的文件。
· bin_PROGRAMS 定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开。
· hello_SOURCES 定义”hello”这个执行程序所需要的原始文件。如果”hello”这个程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔开。例如:若目标体”hello”需要”hello.c”、”hello.h”两个依赖文件,则定义hello_SOURCES=hello.c hello.h。

(6)automake

[root@bogon autoconfig]# automake --add-missing
configure.ac:: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:: installing './install-sh'
configure.ac:: installing './missing'
[root@bogon autoconfig]# ll
total
-rw-r--r-- root root Jun aclocal.m4
drwxr-xr-x root root Jun autom4te.cache
-rw-r--r-- root root Jun autoscan.log
-rw-r--r-- root root Jun config.h.in
-rwxr-xr-x root root Jun configure
-rw-r--r-- root root Jun configure.ac
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h
lrwxrwxrwx root root Jun install-sh -> /usr/share/automake-1.13/install-sh
-rw-r--r-- root root Jun Makefile.am
-rw-r--r-- root root Jun Makefile.in
lrwxrwxrwx root root Jun missing -> /usr/share/automake-1.13/missing

此步主要是为了生成Makefile.in,加上--add-missing参数后,会补全缺少的脚本;

(6)测试

[root@bogon autoconfig]# ./configure
[root@bogon autoconfig]# make
[root@bogon autoconfig]# ./hello
Hello!
Bye!

和平时安装许多开源软件一样操作

(7)打包

[root@bogon autoconfig]# make dist
[root@bogon autoconfig]# ll
total
-rw-r--r-- root root Jun aclocal.m4
drwxr-xr-x root root Jun autom4te.cache
-rw-r--r-- root root Jun autoscan.log
-rw-r--r-- root root Jun config.h
-rw-r--r-- root root Jun config.h.in
-rw-r--r-- root root Jun config.log
-rwxr-xr-x root root Jun config.status
-rwxr-xr-x root root Jun configure
-rw-r--r-- root root Jun configure.ac
lrwxrwxrwx root root Jun depcomp -> /usr/share/automake-1.13/depcomp
-rwxr-xr-x root root Jun hello
-rw-r--r-- root root Jun hello-1.0.tar.gz
-rw-r--r-- root root Jun hello.cpp
-rw-r--r-- root root Jun hello.h
-rw-r--r-- root root Jun hello.o
lrwxrwxrwx root root Jun install-sh -> /usr/share/automake-1.13/install-sh
-rw-r--r-- root root Jun Makefile
-rw-r--r-- root root Jun Makefile.am
-rw-r--r-- root root Jun Makefile.in
lrwxrwxrwx root root Jun missing -> /usr/share/automake-1.13/missing
-rw-r--r-- root root Jun stamp-h1

如果细心的话可以发现,人群中已经出现了hello-1.0.tar.gz就是将已经编译好的文件进行了打包。

Linux下使用automake、autoconf生成configure文件的更多相关文章

  1. linux下使用automake工具自动生成makefile文件

    linux环境下,当项目工程很大的时候,编译的过程很复杂,所以需要使用make工具,自动进行编译安装,但是手写makefile文件比较复杂,所幸在GNU的计划中,设计出了一种叫做Autoconf/Au ...

  2. mfix添加文件后重新生成configure文件

    mfix给了一些程序接口,大部分时候只用修改现有程序即可满足要求,这种情况不用修改configure文件,但是如果添加了新文件就需要做一些修改. 我用了Jian Cai的程序尝试了一下编译,该学者在2 ...

  3. [转]Linux下用gcc/g++生成静态库和动态库(Z)

    Linux下用gcc/g++生成静态库和动态库(Z) 2012-07-24 16:45:10|  分类: linux |  标签:链接库  linux  g++  gcc  |举报|字号 订阅     ...

  4. linux下使用split 来分割大文件

    linux下使用split 来分割大文件 2010-07-27 15:46:27|  分类: 技术文稿 |  标签:split  分割  linux   |字号 订阅   平常都是使用ssh来进行远程 ...

  5. Sphinx/Coreseek 4.1 执行 buildconf.sh 报错,无法生成configure文件

    参考的网址: http://blog.csdn.net/jcjc918/article/details/39032689 错误现象: 执行 buildconf.sh 报错,无法生成configure文 ...

  6. linux下安装安装pcre-8.32 configure: error: You need a C++ compiler for C++ support

    linux下安装安装pcre-8.32./configure --prefix=/usr/local/pcre 出现以下错误configure: error: You need a C++ compi ...

  7. eclipse下Android无法自动生成apk文件怎么办?

    eclipse下Android无法自动生成apk文件怎么办? 现象:创建android工程后,通过手动build/clean或自动build均无法在bin文件夹下生成.apk文件 解决方法:进入win ...

  8. 【java】 linux下利用nohup后台运行jar文件包程序

    Linux 运行jar包命令如下: 方式一: java -jar XXX.jar 特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出 那如何让窗口不锁定? 方式二 ...

  9. 命令行下使用javah命令生成.h文件,出现“错误: 无法访问android.app.Activity 找不到android.app.Activity的类文件”的解决方法

    在学习NDK中,当我在项目的bin/classes目录下使用javah命令生成头文件时,出现了“错误: 无法访问android.app.Activity 找不到android.app.Activity ...

随机推荐

  1. HtmlHelper用法大全

    HTML扩展类的所有方法都有2个参数: 以textbox为例子 public static string TextBox( this HtmlHelper htmlHelper, string nam ...

  2. 熟练掌握js中this的用法,解析this在不同应用场景的作用

    由于其运行期绑定的特性,JavaScript 中的 this 含义要丰富得多,它可以是全局对象.当前对象或者任意对象,这完全取决于函数的调用方式. JavaScript 中函数的调用有以下几种方式:作 ...

  3. android 8种对话框(Dialog)使用方法汇总

    1.写在前面 Android提供了丰富的Dialog函数,本文介绍最常用的8种对话框的使用方法,包括普通(包含提示消息和按钮).列表.单选.多选.等待.进度条.编辑.自定义等多种形式,将在第2部分介绍 ...

  4. INBOUND_CONNECT_TIMEOUT与SQLNET.INBOUND_CONNECT_TIMEOUT小结

    关于sqlnet.ora的参数SQLNET.INBOUND_CONNECT_TIMEOUT,它表示等待用户认证超时的时间,单位是秒,缺省值是60秒,如果用户认证超时了,服务器日志alert.log显示 ...

  5. 简单阐述下Ajax以get方式请求的步骤 初学,不对的话,跟我说下,谢谢!

    首先, 在GET提交中"=,&"等字符与请求字符串的关键字相混淆.所以: 第一步,先对get提交过来的数据进行编码. 第二步,实例化ajax对象. 第三步,创建对服务器的连 ...

  6. Keepalived+MySQL双主架构

    l  架构准备 Node1 192.168.15.3 Node2 192.168.15.4 VIP 192.168.15.254 l  软件 MySQL 5.6 Keepalive yum insta ...

  7. x01.os.8: 加载内核

    在 x01.os.7 中,借助 freedos,学习了保护模式.但操作系统必须完成引导:boot, 加载内核:loader,kernel,进而管理process,memory,file等. 引导比较简 ...

  8. C# .NET 动态调用webservice的三种方式

    转载自 百度文库 http://wenku.baidu.com/link?url=Q2q50wohf5W6UX44zqotXFEe_XOMaib4UtI3BigaNwipOHKNETloMF4ax4W ...

  9. C# FTP 命令无法获取ServerU目录列表问题

    第一步:  使用C# 的Ftp功能时,发现了一个很奇怪的现象,获取目录列表的命令,在SeverU上面直接返回错误,而在windows自带的FTP上则正常,经过反复试验,终于发现,原来是ServerU默 ...

  10. 【redis使用全解析】常见运维操作

    作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1.1 启动 1.1.1 启动redis $ redis-server redis.conf 常见选项: ./r ...