1.autoscan
[root@localhost
automake]#
autoscan
它会在给定目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目
录树中进行检查。它会搜索源文件以寻找一般的移植性问题并创建一个文件“configure.scan”,
该文件就是接下来autoconf要用到的“configure.in”原型。
2.autoconf
configure.in是autoconf的脚本配置文件,它的原型文件“configure.scan”如下所示:更改.scan文件,添加一些语句,并保存为configure.in文件。
# -*- 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
接下来首先运行aclocal,生成一个“aclocal.m4”文件,该文件主要处理本地的宏定义。
如下所示:
[root@localhost automake]#
aclocal
再接着运行autoconf,生成“configure”可执行文件。如下所示:
[root@localhost automake]#
autoconf
[root@localhost automake]# ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in
hello.c
3.autoheader
接着使用autoheader 命令,它负责生成config.h.in文件。该工具通常会从“acconfig.h”
文件中复制用户附加的符号定义,因此此处没有附加符号定义,所以不需要创建“acconfig.h”
文件。如下所示:
[root@localhost automake]#
autoheader
4.automake
这一步是创建Makefile 很重要的一步,automake 要用的脚本配置文件是Makefile.am,
用户需要自己创建相应的文件。之后,automake工具转换成Makefile.in。在该例中,笔者创
建的文件为Makefile.am如下所示:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS= hello
hello_SOURCES=
hello.c
automake提供了3 种软件等级:foreign、gnu和gnits,让用户
选择采用,默认等级为gnu。在本例使用foreign等级,它只检测必须的文件
接下来可以使用automake 对其生成“configure.in”文件,在这里使用选项
“—adding-missing”可以让automake自动添加有一些必需的脚本文件。如下所示:
[root@localhost automake]# automake
--add-missing
configure.in: installing
'./install-sh'
configure.in: installing './missing'
Makefile.am: installing 'depcomp'
[root@localhost automake]# ls
aclocal.m4 autoscan.log configure.in hello.c Makefile.am
missing
autom4te.cache configure depcomp install-sh Makefile.in
config.h.in
5.运行configure
在这一步中,通过运行自动配置设置文件configure,把Makefile.in 变成了最终的
Makefile。如下所示:
[root@localhost automake]# ./configure
6.make
键入make默认执行“make
all”命令,即目标体为all,其执行情况如下所示:
[root@localhost
automake]# make
此时在本目录下就生成了可执行文件“hello”,运行“./hello”能出现正常结果,如下
所示:
[root@localhost
automake]# ./hello
Hello!Autoconf!