fedora自动化编译autotools的使用(转载)

来源:互联网 发布:mysql 替换 编辑:程序博客网 时间:2024/04/28 21:35

fedora自动化编译autotools的使用

具体操作步骤

l  准备好源码文件helloworld.c  Makefile.am文件。

l  执行autoscan生成configure.scan,将configure.scan改为configure.in并修改configure.in

l  然后执行:

n  aclocal;

n  autoheader;

n  touch README NEWS AUTHORS ChangeLog

n  autoconf;

n  automake --add-missing;

n  ./configure;

n  make;

n  ./helloworld ;         ---运行程序

n  make dist            ---制作发布的包

n  make distcheck            ---制作发布的包并对其进行测试检查

n  make clean        --清除make命令产生的目标文件及可执行文件

automake autoconf 自动化编译说明

利用autotools自动生成makefile文件,自动化编译自己的工程,autotools工具只需要用户输入简单的目标文件、依赖文件、文件目录就可以轻松地生成Makefile了。

首先安装autotools系列工具,包括aclocalautoscanautomakeautoheaderautoconf等。

可以通过rpm –qa | grep auto来查看各个应用程序,如果没有

yum install automake即可安装。

详细步骤:

1.建立自己的工程,编写源文件并创建Makefile.am

1)最顶层目录名为模块名 helloworld

源文件放在模块下面的src子目录,例如helloworld/src

2) src 下面,创建源文件main.c

3) helloworld目录下面创建Makefile.am文件--(为Makefile.in的模板文件,.am扩展名是automake的缩写),内容如下:

SUBDIRS=src

4) helloworld/src 目录下创建Makefile.am文件 内容如下:

bin_PROGRAMS=helloworld

helloworld_SOURCES=main.c

其中,PROGRAMS表示要产生的是可执行文件,有多个可执行文件文件时,可用空格分开,而bin表示可执行文件的安装目录SOURCES表示生成可执行文件需要的源文件,有多个源文件时,也用空格分开。比如想生成两个可执行程序helloworld1helloworld2,那么就需要写成:

bin_PROGRAMS=helloworld1 helloworld2

helloworld1_SOURCES=main1.c

helloworld2_SOURCES=main2.c

2.运行 autoscan --创建autoconf的模板

autoscan      --将生成configure.scanautoscan.log文件,它会在给定目录及其子目录树中检查源文件,若没有给定目录,就在当前目录及其子目录树中进行检查。它会搜索源文件以寻找一般的移植性问题并且创建一个文件configure.scan,通过这个文件我们可以创建autoconf需要的模版文件。

1).目录下面生成了configure.scan 文件,利用命令

mv configure.scan configure.in  --将生成的configure.scan更改为autoconf需要的文件模版configure.in

configure.in 文件为autoconf 的模板文件,内容如下所示,其中#行为注释行:

# -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

 

AC_PREREQ([2.68])

AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

AC_CONFIG_SRCDIR([src/main.c])

AC_CONFIG_HEADERS([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

src/Makefile])

AC_OUTPUT

2). 修改configure.in文件

AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

修改为:

AC_INIT(helloworld, 0.1, shaoguangleo@gmail.com)     =--初始化autoconf

并添加

AM_INIT_AUTOMAKE(helloworld, 0.1)         =--初始化automake 必须的宏,这个如果不添加就会导致在autoconf时出错,信息大概为configure.in:no proper invocation of AM_INIT_AUTOMAKE was found

3.运行 aclocal -- 复制所有的宏命令

aclocal

备注:configure.in 里面包含了一系列的宏命令,运行aclocal的目的是把工程需要的宏命令展开。(aclocal.m4 就是configure.in中用到的宏定义)会生成autom4te.cache文件夹和aclocal.m4文件。

4.运行autoheader --生成配置头文件的模板config.h.in并创建4个必要的文件

autoheader

 

备注:此时再创建4个必要的文件

touch README NEWS AUTHORS ChangeLog

README :描述模块的功能,用法和注意事项
NEWS : 描述模块最新的动态
AUTHORS : 模块的作者及联系方式
ChangeLog : 记录模块的修改历史

上述几个文件可以暂时为空。

5. automake --add-missing   -- 生成Makefiel.in和所需要的脚本

automake --add-missing   --其中add-missing选项会让automake自动添加一些必须的脚本文件。

6. autoconf -- 生成configure脚本

autoconf    

--生成configure脚本

7. ./configure -- 生成最终的Makefile文件

./configure

configure 通常有两个参数

1) --prefix 用来制定安装目录 linux默认/usr/local

2) --host 用于交叉编译

8 make =-- 编译

make

9.make install 安装

make install

 

10.make dist或者make distcheck =--发布软件包

make dist或者make distcheck

生成helloworld-0.1.tar.gz

autotools生成Makefile流程图



转自:http://shaoguangleo.blog.163.com/blog/static/22779832011116700660/
0 0