分类: LINUX
2010-03-09 20:49:50
先写上源代码到源文件中
[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]#
完成