原创 autotools魔鬼使用[原]

2007-10-5 23:30 3137 5 5 分类: MCU/ 嵌入式
呵呵!刚刚又练了一下用autotools来生成makefile,呵呵,感觉比前一次好多拉。
[root@localhost root]# mkdir -m 777 ./hello         //新建一个文件夹放源文件,其实这相当于一个项目工程文件夹
[root@localhost root]# cd hello
[root@localhost hello]# vim hello.c          //新建一个hello.c的文件,输入如下内容
#include<stdio.h>
int main(void)
{
        printf("Hello, Lammy!\n");
        return 0;
}//呵呵,简单吧
//接下来就开始使用autotools来生成Makefile
[root@localhost hello]# ls
hello.c
[root@localhost hello]# autoscan      //利用它来生成configure.in的原型文件
configure.scan
[root@localhost hello]# ls               //发现有什么不一样了没有
autoscan.log  configure.scan  hello.c
//然后修改
configure.scan,并保存为configure.in
[root@localhost hello]# vim configure.scan

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
                                                                               
AC_PREREQ(2.57)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
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_OUTPUT

//把它修改为如下:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
                                                                               
AC_PREREQ(2.57)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
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_CONFIG_FILES用于生成Makefile的宏
AC_OUTPUT


//保存为configure.in,注意紫罗兰色部分,具体为什么可以看看http://seul.org/docs/autotut/,上面有关各个宏观的作用,不过是英文的
[root@localhost hello]# aclocal    //生成
aclocal.m4
[root@localhost hello]# autoconf   //生成
configure   
[root@localhost hello]# ls      //又多了东西
aclocal.m4      autoscan.log  configure.in    hello.c
autom4te.cache  configure     configure.scan
[root@localhost hello]# autoheader    //生成
config.h.in
[root@localhost hello]# ls
aclocal.m4      autoscan.log  configure     configure.scan
autom4te.cache  config.h.in   configure.in  hello.c
//新建一个Makefile.am,它是automake的脚本,很简单
[root@localhost hello]# vim Makefile.am
//输入如下,具体什么我就不介绍啦,记住就行

AUTOMAKE_OPTIONS=foreign

bin_PRONGRAMS =hello
hello_SOURCES =hello.c
[root@localhost hello]# automake --add-missing   //生成configure.in
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
[root@localhost hello]# ls
aclocal.m4      config.h.in   configure.scan  install-sh   missing
autom4te.cache  configure     depcomp         Makefile.am  mkinstalldirs
autoscan.log    configure.in  hello.c         Makefile.in

[root@localhost hello]# ./configure      //生成Makefile
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@localhost hello]# make      //编译并生成可运行的运行文件
make  all-am
make[1]: Entering directory `/root/hello'
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 `/root/hello'
[root@localhost hello]# ls      //看到它了没有
aclocal.m4      config.log      depcomp     Makefile       stamp-h1
autom4te.cache  config.status   hello       Makefile.am
autoscan.log    configure       hello.c     Makefile.in
config.h        configure.in    hello.o     missing
config.h.in     configure.scan  install-sh  mkinstalldirs
[root@localhost hello]# ./hello   //运行下看看
Hello, Lammy!

//可以看看Makefile发现挺大的,呵呵,不管,能用就行,另外附加几个心得:
1>如果你的源文件有问题,在 make时它会有提示的,所以
Makefile的生成和你的源文件正确与否没有联系,所以你修改了源文件时,只要文件名没有改,那么你可以直接从 make开始
2>
AC_INIT(hello,1.0)

AM_INIT_AUTOMAKE(hello,1.0)

                                                                               

AC_CONFIG_SRCDIR([hello.c])

AM_CONFIG_HEADER([config.h])//
这几个宏顺序别弄反啦哦


更具体的请看http://seul.org/docs/autotut/。


文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /2 下一条