Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1068971
  • 博文数量: 139
  • 博客积分: 1823
  • 博客等级: 上尉
  • 技术积分: 3403
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-05 09:54
文章存档

2014年(7)

2013年(16)

2012年(48)

2011年(68)

分类: LINUX

2012-04-13 09:36:47

关于automake的重要性已经在上一篇文章中作了说明。上一篇‘大家’写的文章讲得十分详细,在这里鄙人还是要啰嗦一下,记下自己使用时的各种问题。

1,新建一个目录:auto,其中存放本项目所需的两个源文件:hello.c和hello.h,具体内容如下:

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ cat hello.c
  2. #include "hello.h"
  3. int main()
  4. {
  5.     printf("Hello everyone!\n");
  6. }

 

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ cat hello.h
  2. #include <stdio.h>

2,使用命令:autoscan

3,修改configure.scan文件如下:

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ cat configure.scan
  2. # -*- Autoconf -*-
  3. # Process this file with autoconf to produce a configure script.

  4. AC_PREREQ([2.63])
  5. AC_INIT(hello,1.0)
  6. AM_INIT_AUTOMAKE(hello,1.0)
  7. AC_CONFIG_SRCDIR([hello.h])
  8. AC_CONFIG_HEADERS([config.h])

  9. # Checks for programs.
  10. AC_PROG_CC

  11. # Checks for libraries.

  12. # Checks for header files.

  13. # Checks for typedefs, structures, and compiler characteristics.

  14. # Checks for library functions.

  15. AC_CONFIG_FILES([Makefile])
  16. AC_OUTPUT

4,保存退出,并cp configure.scan configure.in

5,运行aclocal

6,运行autoconf

7,运行autoheader

8,用VI编辑Makefile.am文件

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ vi Makefile.am
  2. AUTOMAKE_OPTIONS=foreign
  3. bin_PROGRAMS=hello
  4. hello_SOURCES=hello.c hello.h

9,运行automake --add-missing(一定要加上后面这个参数,不然下一步没法做)

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ automake --add-missing
  2. configure.in: installing `./install-sh'
  3. configure.in: installing `./mkinstalldirs'
  4. configure.in: installing `./missing'
  5. Makefile.am: installing `./depcomp

10,运行./configure

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ ./configure
  2. checking for a BSD-compatible install... /usr/bin/install -c
  3. checking whether build environment is sane... yes
  4. checking for a thread-safe mkdir -p... /bin/mkdir -p
  5. checking for gawk... gawk
  6. checking whether make sets $(MAKE)... yes
  7. checking for gcc... gcc
  8. checking for C compiler default output file name... a.out
  9. checking whether the C compiler works... yes
  10. checking whether we are cross compiling... no
  11. checking for suffix of executables...
  12. checking for suffix of object files... o
  13. checking whether we are using the GNU C compiler... yes
  14. checking whether gcc accepts -g... yes
  15. checking for gcc option to accept ISO C89... none needed
  16. checking for style of include used by make... GNU
  17. checking dependency style of gcc... gcc3
  18. configure: creating ./config.status
  19. config.status: creating Makefile
  20. config.status: creating config.h
  21. config.status: executing depfiles commands

11,运行make

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ make
  2. cd . && /bin/bash /home/lihacker/workspace/makefile/auto/missing --run autoheader
  3. rm -f stamp-h1
  4. touch config.h.in
  5. cd . && /bin/bash ./config.status config.h
  6. config.status: creating config.h
  7. config.status: config.h is unchanged
  8. make all-am
  9. make[1]: Entering directory `/home/lihacker/workspace/makefile/auto'
  10. make[1]: Leaving directory `/home/lihacker/workspace/makefile/auto

12,运行./hello

  1. lihacker@lihacker-laptop:~/workspace/makefile/auto$ ./hello
  2. Hello

附录:autotools生成makefile流程如下图






 

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