分类:
2005-12-26 21:46:22
所需工具:
GN U Automake
GNU Autoconf
GNU m4
perl
GNU Libtool
制作Makefile的步骤:
以~/test/hello.c为例
[icymoon@icymoon test]$ cat hello.c
#include
int main(int argc,char **argv)
{
printf("%s
","Hello, World!");
return 0;
}
利用autoscan工具产生一个configure.in文件的模板文件configure.scan文件
[icymoon@icymoon test]$ autoscan
[icymoon@icymoon test]$ ls
autoscan.log configure.scan hello.c
[icymoon@icymoon test]$
把configure.scan文件更名为configure.in文件,并编辑
[icymoon@icymoon test]$ mv configure.scan configure.in
[icymoon@icymoon test]$ cat configure.in
# -*- 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
[icymoon@icymoon test]$ vi configure.in
[icymoon@icymoon test]$ cat configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT(hello, 1.0, )
AM_INIT_AUTOMAKE(hello,1.0)
AC_CONFIG_SRCDIR(hello.c)
# 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)
执行aclocal,会产生aclocal.m4文件
[icymoon@icymoon test]$ aclocal
[icymoon@icymoon test]$ ls
aclocal.m4 autoscan.log configure.in hello.c
[icymoon@icymoon test]$
执行autoconf,会产生confiure文件
[icymoon@icymoon test]$ autoconf
[icymoon@icymoon test]$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c
[icymoon@icymoon test]$
创建文件Makefile.am并编辑其内容如下:
[icymoon@icymoon test]$ vi Makefile.am
[icymoon@icymoon test]$ cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello //编译后可执行文件名
hello_SOURCES=hello.c//源文件列表
[icymoon@icymoon test]$
执行automake程序,automake程序会根据Makefile.am产生一些文件,
其中最重要的是Makefile.in文件
[icymoon@icymoon test]$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
[icymoon@icymoon test]$
下面就是./configure make了
[icymoon@icymoon test]$ ./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... 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
[icymoon@icymoon test]$ make
source='hello.c' object='hello.o' libtool=no
depfile='.deps/hello.Po' tmpdepfile='.deps/hello.TPo'
depmode=gcc3 /bin/sh ./depcomp
gcc -DPACKAGE_NAME="hello" -DPACKAGE_TARNAME="hello" -DPACKAGE_VERSION="1.0
" -DPACKAGE_STRING="hello 1.0" -DPACKAGE_BUGREPORT=""
-DPACKAGE="hello" -DVERSION="1.0" -I. -I. -g -O2 -c `test -f 'hello.c'
|| echo
'./'`hello.c
gcc -g -O2 -o hello hello.o
[icymoon@icymoon test]$
[icymoon@icymoon test]$ ls
aclocal.m4 config.log configure.in hello.c Makefile missing
autom4te.cache config.status depcomp hello.o Makefile.am mkinstalld
irs
autoscan.log configure hello install-sh Makefile.in
[icymoon@icymoon test]$ ./hello
Hello, World!
[icymoon@icymoon test]$