免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1222 | 回复: 0
打印 上一主题 下一主题

[原]autoconf与automake自动生成Makefile [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-04 20:47 |只看该作者 |倒序浏览

作者:帅得不敢出门 时间: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]#
完成


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/64540/showart_1679963.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP