Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4511229
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: LINUX

2008-12-04 20:47:22

作者:帅得不敢出门 时间:2008-12-4

先写上源代码到源文件中
[root@localhost work]# vi common.h
#include

[root@localhost work]# vi test.c
#include "common.h"
#include"test.h"
void test()
{
        printf("test!");
}

[root@localhost work]# vi main.c
#include"common.h"
#include"test.h"
                                                                               
int main()
{
        printf("hello!\n");
        test();
return 0;
}

[root@localhost work]# vi test.h
void test();

[root@localhost work]# ls
common.h  main.c  test.c  test.h
autoscan产生configure.in的框架configure.scan
[root@localhost work]# autoscan
[root@localhost work]# ls
autoscan.log  common.h  configure.scan  main.c  test.c  test.h
修改configure.scan
[root@localhost work]# vi configure.scan

#                                               -*- 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([common.h])
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


修改成如下:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
                                                                               
AC_PREREQ(2.57)
AC_INIT(test, 1.0, BUG-REPORT-ADDRESS)
AM_INIT_AUTOMAKE(test,1.0)
AC_CONFIG_SRCDIR([common.h])
#AC_CONFIG_HEADER([config.h])
AM_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)
AC_INIT的参数要换成实际的参数
AC_OUTPUT中要指明实际要生成的文件
增加automake的初始化宏AM_INIT_AUTOMAKE


然后改名
[root@localhost work]# mv configure.scan configure.in
[root@localhost work]# ls
autoscan.log  common.h  configure.in  configure.scan~  main.c  test.c  test.h


[root@localhost work]# aclocal
[root@localhost work]# ls
aclocal.m4    common.h      configure.scan~  test.c
autoscan.log  configure.in  main.c           test.h

aclocal根据configure.in文件的内容,自动生成aclocal.m4文件
[root@localhost work]# autoconf
[root@localhost work]# ls
aclocal.m4      autoscan.log  configure     configure.scan~  test.c
autom4te.cache  common.h      configure.in  main.c           test.h

autoheader产生config.h.in
[root@localhost work]# autoheader
[root@localhost work]# ls
aclocal.m4      autoscan.log  config.h.in  configure.in     main.c  test.h
autom4te.cache  common.h      configure    configure.scan~  test.c

新建一个akefile.am
[root@localhost work]# vi MAkefile.am
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = test
test_SOURCES = main.c test.c

automake产生Makefile.in
[root@localhost work]# automake -a
Makefile.am: installing `./depcomp'
[root@localhost work]# ls
aclocal.m4      config.h.in      depcomp      Makefile.in    test.h
autom4te.cache  configure        install-sh   missing
autoscan.log    configure.in     main.c       mkinstalldirs
common.h        configure.scan~  Makefile.am  test.c

./configure产生Makefile
[root@localhost work]# ./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: creating config.h
config.status: executing depfiles commands

编译连接
[root@localhost work]# make
make  all-am
make[1]: Entering directory `/work'
source='test.c' object='test.o' libtool=no \
depfile='.deps/test.Po' tmpdepfile='.deps/test.TPo' \
depmode=gcc3 /bin/sh ./depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -c `test -f 'test.c' || echo './'`test.c
gcc  -g -O2   -o test  main.o test.o
make[1]: Leaving directory `/work'
生成 test

运行它
[root@localhost work]# ./test
hello!
test![root@localhost work]#
完成

阅读(2484) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~