Autoconf 学习笔记(1)

1. 建立源码目录

mkdir  hello
cd  hello
mkdir  src

2. 编辑源码

/*
 * hello.c
 *
 * 2008-01-14, mymtom
 
*/
 

#include 
< stdio.h >  

int  main( void )
{
        printf(
"Hello, Automake! ");
        
return 0;
}

3. 编写Makefile.am和src/Makefile.am

 

#
# Makefile.am
#
# 2008-01-14, mymtom


AUTOMAKE_OPTIONS 
=  foreign
SUBDIRS 
=  src

 

#
# src/Makefile.am
#
# 2008-01-14, mymtom


bin_PROGRAMS 
=  hello
hello_SOURCES 
=  hello . c

4. 运行用autoscan产生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([src
/ 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_CONFIG_FILES([Makefile
                 src
/ Makefile])
AC_OUTPUT

5. 以configure.scan为基础, 编写configure.ac

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


AC_INIT(hello
,   1.0 ,  mymtom @hotmail . com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src
/ 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_CONFIG_FILES([Makefile
                 src
/ Makefile])
AC_OUTPUT

6. 运行aclocal, autoheader, autoconf和automake

aclocal
autoheader
autoconf
automake --add-missing

7. 运行./configure

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
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 src/Makefile
config.status: creating config.h
config.status: executing depfiles commands

8. 运行make

make  all-recursive
Making all in src
if gcc -DHAVE_CONFIG_H -I. -I. -I..      -g -O2 -MT hello.o -MD -MP -MF ".deps/hello.Tpo" -c -o hello.o hello.c;  then mv -f ".deps/hello.Tpo" ".deps/hello.Po"; else rm -f ".deps/hello.Tpo"; exit 1; fi
gcc  -g -O2   -o hello  hello.o

你可能感兴趣的:(makefile,compiler,gcc,output,header,include)