Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1871922
  • 博文数量: 283
  • 博客积分: 10141
  • 博客等级: 上将
  • 技术积分: 2931
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-21 14:33
文章分类

全部博文(283)

文章存档

2013年(2)

2012年(2)

2011年(17)

2010年(36)

2009年(17)

2008年(18)

2007年(66)

2006年(105)

2005年(20)

分类:

2005-12-26 21:46:22

以前写的笔记. 对于某些CVS下来的东西不错。

所需工具:
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]$

阅读(1097) | 评论(0) | 转发(0) |
0

上一篇:Linux Server Hacks(1)

下一篇:不是开篇的开篇

给主人留下些什么吧!~~