关于automake的重要性已经在上一篇文章中作了说明。上一篇‘大家’写的文章讲得十分详细,在这里鄙人还是要啰嗦一下,记下自己使用时的各种问题。
1,新建一个目录:auto,其中存放本项目所需的两个源文件:hello.c和hello.h,具体内容如下:
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ cat hello.c
- #include "hello.h"
- int main()
- {
- printf("Hello everyone!\n");
- }
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ cat hello.h
- #include <stdio.h>
2,使用命令:autoscan
3,修改configure.scan文件如下:
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ cat configure.scan
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
- AC_PREREQ([2.63])
- AC_INIT(hello,1.0)
- AM_INIT_AUTOMAKE(hello,1.0)
- AC_CONFIG_SRCDIR([hello.h])
- AC_CONFIG_HEADERS([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_CONFIG_FILES([Makefile])
- AC_OUTPUT
4,保存退出,并cp configure.scan configure.in
5,运行aclocal
6,运行autoconf
7,运行autoheader
8,用VI编辑Makefile.am文件
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ vi Makefile.am
- AUTOMAKE_OPTIONS=foreign
- bin_PROGRAMS=hello
- hello_SOURCES=hello.c hello.h
9,运行automake --add-missing(一定要加上后面这个参数,不然下一步没法做)
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ automake --add-missing
- configure.in: installing `./install-sh'
- configure.in: installing `./mkinstalldirs'
- configure.in: installing `./missing'
- Makefile.am: installing `./depcomp
10,运行./configure
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ ./configure
- checking for a BSD-compatible install... /usr/bin/install -c
- checking whether build environment is sane... yes
- checking for a thread-safe mkdir -p... /bin/mkdir -p
- checking for gawk... gawk
- checking whether make sets $(MAKE)... yes
- checking for gcc... gcc
- checking for C compiler default output file name... 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 ISO C89... 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
11,运行make
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ make
- cd . && /bin/bash /home/lihacker/workspace/makefile/auto/missing --run autoheader
- rm -f stamp-h1
- touch config.h.in
- cd . && /bin/bash ./config.status config.h
- config.status: creating config.h
- config.status: config.h is unchanged
- make all-am
- make[1]: Entering directory `/home/lihacker/workspace/makefile/auto'
- make[1]: Leaving directory `/home/lihacker/workspace/makefile/auto
12,运行./hello
- lihacker@lihacker-laptop:~/workspace/makefile/auto$ ./hello
- Hello
附录:autotools生成makefile流程如下图
阅读(1609) | 评论(0) | 转发(1) |