不过,却是现在才对autoconf & automake 有了深入的理解。
转载几篇参考博客:
http://www.ibm.com/developerworks/cn/linux/l-makefile/
http://blog.youkuaiyun.com/kasagawa/article/details/6885998
http://www.cnblogs.com/itech/archive/2010/11/28/1890220.html
http://linux.chinaunix.net/techdoc/system/2009/02/05/1060775.shtml
练习实例:
$cd ~
$mkdir helloworld
$cd helloworld
$vim helloworld.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[])
{
printf("Hello World!\n");
return 0;
}
$autoscan
生成如下文件:
autoscan.log configure.scan helloworld.c
$mv -v configure.scan configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([helloworld.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT
将configure.scan 重命名为configure.in, 并将其内容修改如下:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT(helloworld, 1.0, qc@gmail.com)
AC_CONFIG_SRCDIR([helloworld.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(helloworld, 1.0)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile)
$aclocal
生成aclocal.m4 文件
$autoconf
生成 configure文件。
$autoheader
生成config.h.in 文件
$ vim Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
hello_SOURCES=helloworld.c
$ automake --add-missing
$ ./configure
$ make
至此为止就完成了helloworld.c 的Makefile 生成,到最终的make 编译。
当然可以继续make install 将helloworld 程序安装到/usr/local/bin 目录下面。
make dist 将程序打包成压缩包。