autoconf 和 automake工具介绍

0)准备工作:
[root@yznvm1 helloworld]# uname -a
Linux yznvm1 2.6.18-238.el5 #1 SMP Thu Jan 13 15:51:15 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@yznvm1 yzn]# rpm -qa |grep autoconf
autoconf-2.59-12
[root@yznvm1 yzn]# rpm -qa |grep automake
automake15-1.5-16.el5.2
automake14-1.4p6-13.el5.1
automake-1.9.6-2.3.el5
automake17-1.7.9-7.el5.2
automake16-1.6.3-8.el5.1
[root@yznvm1 yzn]# rpm -qa |grep perl
perl-String-CRC32-1.4-2.fc6
perl-5.8.8-32.el5_5.2
perl-URI-1.35-3
newt-perl-1.08-9.2.2
[root@yznvm1 yzn]# rpm -qa |grep m4
m4-1.4.5-3.el5.1
[root@yznvm1 yzn]# whereis aclocal,autoscan
aclocal,autoscan:
[root@yznvm1 yzn]# whereis aclocal autoscan
aclocal: /usr/bin/aclocal /usr/share/aclocal
autoscan: /usr/bin/autoscan /usr/share/man/man1/autoscan.1.gz
[root@yznvm1 yzn]# whereis aclocal autoscan autoconf autoheader automake
aclocal: /usr/bin/aclocal /usr/share/aclocal
autoscan: /usr/bin/autoscan /usr/share/man/man1/autoscan.1.gz
autoconf: /usr/bin/autoconf /usr/share/autoconf /usr/share/man/man1/autoconf.1.gz
autoheader: /usr/bin/autoheader /usr/share/man/man1/autoheader.1.gz
automake: /usr/bin/automake

1) 编辑hellworld.c文件

#include<stdio.h>
int main(int argc, char** argv)
{
printf("Hello world, Lvping.com !n");
return 0;
}
2)autoscan-〉configure.scan
[root@yznvm1 helloworld]# autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@yznvm1 helloworld]# ls
autoscan.log  configure.scan  helloworld.c
[root@yznvm1 helloworld]# cat configure.scan
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([helloworld.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

3)编辑configure.ac
[root@yznvm1 helloworld]# cp configure.scan configure.ac  
[root@yznvm1 helloworld]# vi configure.ac 
[root@yznvm1 helloworld]# cat configure.ac
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(helloworld, 1.0, yanzhenan@126.com)
AM_INIT_AUTOMAKE(helloworld,1.0)
AC_CONFIG_SRCDIR([helloworld.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(Makefile)
4)aclocal-〉aclocal.m4
[root@yznvm1 helloworld]# aclocal
[root@yznvm1 helloworld]# ls
aclocal.m4  autom4te.cache  autoscan.log  configure.ac  configure.scan  helloworld.c
5)autoconf -〉configure
[root@yznvm1 helloworld]# autoconf
[root@yznvm1 helloworld]# ls
aclocal.m4  autom4te.cache  autoscan.log  configure  configure.ac  configure.scan  helloworld.c
6)autoheader ->config.h.in
[root@yznvm1 helloworld]# find / -name acconfig.h
/usr/src/kernels/2.6.18-238.el5-x86_64/include/acpi/acconfig.h
[root@yznvm1 helloworld]# autoheader
[root@yznvm1 helloworld]# ls
aclocal.m4  autom4te.cache  autoscan.log  config.h.in  configure  configure.ac  configure.scan  helloworld.c
[root@yznvm1 helloworld]# more config.h.in
/* config.h.in.  Generated from configure.ac by autoheader.  */

/* Name of package */
#undef PACKAGE

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Version number of package */
#undef VERSION

7)编辑Makefile.am文件
[root@yznvm1 helloworld]# cat Makefile.am
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = helloworld
helloworld_SOURCES = helloworld.c
8)automake->makefile.in
[root@yznvm1 helloworld]# automake
configure.ac: required file `./install-sh' not found
configure.ac: required file `./missing' not found
Makefile.am: required file `./depcomp' not found
这样会报错
[root@yznvm1 helloworld]# automake --add-missing
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
Makefile.am: installing `./depcomp'
[root@yznvm1 helloworld]# ls
aclocal.m4  autom4te.cache  autoscan.log  config.h.in  configure  configure.ac  configure.scan  depcomp  helloworld.c  install-sh  Makefile.am  Makefile.in  missing
[root@yznvm1 helloworld]# ls
aclocal.m4      autoscan.log  config.h.in  config.status  configure.ac    depcomp       install-sh  Makefile.am  missing
autom4te.cache  config.h      config.log   configure      configure.scan  helloworld.c  Makefile    Makefile.in  stamp-h1

9)编译运行即可
[root@yznvm1 helloworld]# ./configure
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 file name... 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: config.h is unchanged
config.status: executing depfiles commands
[root@yznvm1 helloworld]# make && make install
make  all-am
make[1]: Entering directory `/home/yzn/helloworld'
if gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -MT helloworld.o -MD -MP -MF ".deps/helloworld.Tpo" -c -o helloworld.o helloworld.c; \
        then mv -f ".deps/helloworld.Tpo" ".deps/helloworld.Po"; else rm -f ".deps/helloworld.Tpo"; exit 1; fi
gcc  -g -O2   -o helloworld  helloworld.o 
make[1]: Leaving directory `/home/yzn/helloworld'
make[1]: Entering directory `/home/yzn/helloworld'
test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
  /usr/bin/install -c 'helloworld' '/usr/local/bin/helloworld'
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/home/yzn/helloworld'

[root@yznvm1 helloworld]# ./helloworld
Hello world, Lvping.com!
[root@yznvm1 helloworld]# make uninstall
 rm -f '/usr/local/bin/helloworld'
[root@yznvm1 helloworld]# make clean
test -z "helloworld" || rm -f helloworld
rm -f *.o
[root@yznvm1 helloworld]# make dist
{ test ! -d helloworld-1.0 || { find helloworld-1.0 -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr helloworld-1.0; }; }
mkdir helloworld-1.0
find helloworld-1.0 -type d ! -perm -755 -exec chmod a+rwx,go+rx {} \; -o \
          ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
          ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
          ! -type d ! -perm -444 -exec /bin/sh /home/yzn/helloworld/install-sh -c -m a+r {} {} \; \
        || chmod -R a+r helloworld-1.0
tardir=helloworld-1.0 && /bin/sh /home/yzn/helloworld/missing --run tar chof - "$tardir" | GZIP=--best gzip -c >helloworld-1.0.tar.gz
{ test ! -d helloworld-1.0 || { find helloworld-1.0 -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr helloworld-1.0; }; }
[root@yznvm1 helloworld]# ls
aclocal.m4      autoscan.log  config.h.in  config.status  configure.ac    depcomp                helloworld.c  Makefile     Makefile.in  stamp-h1
autom4te.cache  config.h      config.log   configure      configure.scan  helloworld-1.0.tar.gz  install-sh    Makefile.am  missing

 

 

调试:

如果需要用gdb 调试

./configure CPPFLAGS='-ggdb3'

这样配置后

make

gdb helloworld

然后输入 (gdb)break main,(gdb)run,(gdb)step等就可调试了。

总结:
http://book.51cto.com/art/200811/97013.htm

http://linux.chinaunix.net/techdoc/develop/2008/03/15/983336.shtml

有比较全面的介绍,不过其中流程图有少许错误,需要注意。
总流程
helloworld.c(autoscan)-〉configure.scan (cp,vi)->configure.ac(aclocal)->aclocal.m4 (autoconf) -〉configure
(autoheader) ->config.h.in
Makefile.am(automake)->makefile.in(automake)->Makefile
Configure
Make&&Make install

posted @ 2011-12-09 19:40  羽化成蝶  阅读(554)  评论(0编辑  收藏  举报