AUTOTOOLS

43 篇文章 1 订阅

AUTOTOOLS(转载)

步骤1:编写源码文件。

[root@localhost home]# vi hello.c

内容如下:

#include"hello.h"

int main()

{

printf("Hello world!\n");

}

[root@localhost home]# vi hello.h

内容如下:

#include<stdio.h>

步骤2:在当前目录下建立auto目录。

命令:

[root@localhost home]# mkdir ./auto

步骤3:把hello文件复制到auto目录下。

命令:

[root@localhost home]# cp hello.* ./auto

步骤4:输入命令autoscan。

命令:

[root@localhost home]# cd auto

[root@localhost auto]# autoscan

此时生成了2个文件 ,分别是 autoscan.log configure.scan

Autoscan会在给定的目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目录树中进行检查。它会搜索源文件以寻找一般的移植性问题并创建一个文件configure.scan

步骤5:用vi编写configure.scan,并保存命名为configure.in,configure.in是autoconf的脚本配置文件。

命令:

[root@localhost auto]# vi configure.scan

修改内容如下:

# -*- Autoconf -*-

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

AC_PREREQ(2.57)

AC_INIT(hello,1.0)

AM_INIT_AUTOMAKE(hello,1.0)

AC_CONFIG_SRCDIR([hello.c])

AM_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下面对这个脚本文件进行解释:

AC_PREREQ宏声明本文件要求的autoconf版本,本例使用的版本为2.57

AC_INIT宏用来定义软件的名称和版本等信息

AM_INIT_AUTOMAKE是笔者另加的,它是automake所必备的宏。

AC_CONFIG_SRCDIR宏用来侦测所指定的源码文件是否存在,来确定源码目录的有效性,在此处为当前目录下的hello.c

AC_CONFIG_HEADER宏用于生成config.h文件,以便autoheader使用。

步骤6:运行命令aclocal

命令:

[root@localhost auto]# aclocal

生成文件aclocal.m4,该文件主要处理本地的宏定义。

步骤7:运行autoconf

命令:

[root@localhost auto]# autoconf

生成2个文件:分别为autom4te.cache configure

步骤8:运行autoheader

命令:

[root@localhost auto]# autoheader

生成config.h.in

步骤9:用vi编辑Makefile.am

[root@localhost auto]# vi Makefile.am

内容如下:

AUTOMAKE_OPTIONS=foreign

bin_PROGRAMS=hello

hello_SOURCES=hello.c hello.h

步骤10:运行automake

命令:

[root@localhost auto]# automake --add-missing

可以让automake自动添加一些必需的脚本文件。

生成configure depcomp install-sh missing mkinstalldirs

步骤11:运行./configure

命令:

[root@localhost auto]# ./configure

步骤12:运行make

命令:

[root@localhost auto]# make

显示内容如下:

make all-am

make[1]: Entering directory `/home/auto'

source='hello.c' object='hello.o' libtool=no \

depfile='.deps/hello.Po' tmpdepfile='.deps/hello.TPo' \

depmode=gcc3 /bin/sh ./depcomp \

gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c `test -f 'hello.c' || echo './'`hello.c

gcc -g -O2 -o hello hello.o

make[1]: Leaving directory `/home/auto'

此时生成hello可执行文件。

步骤13:执行./hello

命令:

[root@localhost auto]# ./hello

显示结果如下:

Hello world!

步骤14:运行make install

命令:

[root@localhost auto]# make install

把程序安装到系统目录下。

[root@localhost auto]# hello

Hello world!

步骤15:运行make dist

命令:

[root@localhost auto]# make dist

出现问题

make: *** No rule to make target `README', needed by `distdir'. Stop.

没有生成hello-1.o.tar.gz

步骤16:运行make clean

命令:

[root@localhost auto]# make clean

显示如下:

test -z "hello" || rm -f hello

rm -f *.o core *.core

此时.o文件及可执行文件都会删除,也就是说hello及hello.o文件都删除了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值