CRI Radio

May 11, 2007

使用autoconf 和 automake 生成 Makefile 文件

生成Makefile流程图如下:
image 

步骤:
>mkdir demo && cd demo
>vi helloworld.c

      1 int main(int argc, char** argv)
      2 {
      3 printf("Hello, Linux World!\n");
      4 return 0;
      5 }
>autoscan
>cp configure.scan configure.in
>vi configure.in
      1 # -*- Autoconf -*-
      2 # Process this file with autoconf to produce a configure script.
      3
      4 AC_INIT(helloworld.c)
      5 AM_INIT_AUTOMAKE(helloworld, 1.0)
      6
      7 # Checks for programs.
      8 AC_PROG_CC
      9
     10 # Checks for libraries.
     11
     12 # Checks for header files.
     13
     14 # Checks for typedefs, structures, and compiler characteristics.
     15
     16 # Checks for library functions.
     17 AC_OUTPUT(Makefile)
> aclocal   
> autoconf
> ls

aclocal.m4      autoscan.log  configure.in    helloworld.c
autom4te.cache  configure     configure.scan
>vi Makefile.am
      1 AUTOMAKE_OPTIONS=foreign
      2 bin_PROGRAMS=helloworld
      3 helloworld_SOURCES=helloworld.c
>  automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
> ./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: executing depfiles commands
> make
source='helloworld.c' object='helloworld.o' libtool=no \
depfile='.deps/helloworld.Po' tmpdepfile='.deps/helloworld.TPo' \
depmode=gcc3 /bin/sh ./depcomp \
gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"helloworld\" -DVERSION=\"1.0\"  -I. -I.     -g -O2 -c `test -f 'helloworld.c' || echo './'`helloworld.c
gcc  -g -O2   -o helloworld  helloworld.o 
> ls
aclocal.m4      config.status   depcomp       install-sh   missing
autom4te.cache  configure       helloworld    Makefile     mkinstalldirs
autoscan.log    configure.in    helloworld.c  Makefile.am
config.log      configure.scan  helloworld.o  Makefile.in
> ./helloworld
Hello, Linux World!