Chinaunix

标题: linux下autotools的试用 [打印本页]

作者: zhingfe    时间: 2008-11-03 07:40
标题: linux下autotools的试用

                    autotools工具链包括:autoscan,aclocal, autoheader,automake,autoconf
    有了以上工具就可以像大多GNU软件一样编译安装,例如:
./configure
make
make install
看起来是不是很方便啊,而且还可以(主要)还能跟据平台可以移植(UNIX类系统,windows下Cygin),但是用起来就不是那么简单了,光看这么多工具就知道了
    首先新建一个文件夹,因为要产生许多中间文件跟其它文件混到一块的话很乱,在新建的文件夹下再新建源文件hello.c,内容如下:
/* hello.c */
#include
int main()
{
    printf("Hello World!\n");
    return 0;
}
    1.最小化工具链:
  (1):先用运行autoscan命令,生成一个configure.scan文件,我们把它改名为configure.ac,autoconf要用到
  (2):执行autoconf命令,这时在目录下已经生成了configure文件了,但运行configure需要有一个Makefile.in文件,我们手工建立一个内容如下:
#Makefile.in 其中为Tab字符
EXEC := hello
all: $(EXEC)
.PHONY
clean
clean:
rm -f hello *.o
  (3):现在可以执行 ./configure 和 make 了,虽然出了不少错但还是生成了hello
    2.完全工具链:
  (1):跟上边的(1)一样
  (2):修改configure.ac,在AC_INIT()宏之后添加一行(不包括引号)“AM_INIT_AUTOMAKE”,运行aclocal命令
  (3):运行autoheader,生成config.h
  (4):创建Makefile.am,automake要用到,内容如下
bin_PROGRAMS=hello
hello_SOURCES=hello.c
另外运行automake还需要下列文件:
install-sh
missing
INSTALL
NEWS
README
AUTHORS
ChangeLog
COPYING
depcomp
运行automake -a可以生install-sh,missing,INSTALL,COPYING 和 depcomp,其它的要自己创建
然后运行automake
  (5):运行autoconf, ./configure, make, 生成成功
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/80326/showart_1357875.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2