免费注册 查看新帖 |

Chinaunix

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

automake autoconf 学习笔记(转载) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-19 16:47 |只看该作者 |倒序浏览
不知为什么,看英文资料总是记不住,看过就忘,还是记下来的好. 所以Linux的中文版无论对谁都是很重要的.
通俗地说:
automake 用于 Makefile.am ->Makefile.in
autoconf 用于 configure.ac ->configure
configure 用于 Makfile.in -> Makefile
注: configure.ac 以前也称 configuer.in,但和 Makefile.in 容易混淆.
autoscan 是个很不错的工具,它自动检查当前目录(或者指定的目录)下的源代码,生成
configure.scan 指出哪些功能是需要检测的. configure.scan 可以作为 configure.ac 的模板.附上 autoscan man page的第一段:
Examine  source  files  in  the  directory  tree rooted at SRCDIR, or the
current directory if none is given.  Search the  source files for common
portability problems, check for incompleteness of `configure.ac',  and  create  a  file  `configure.scan' which is a preliminary `configure.ac' for that
package.
automake  与 autoconf 的关系很紧密,理由也很简单, autoconf 生成的configure脚本部分功能是替换 Makefile.in 里的变量以生成 Makefile (按 autoconf 文档的说法是:实例化Makfile.in),configure 可以实例化任何文件,一般都是 .in 后缀的。
以下是 SMTH_BBS 顶层目录里的 configure.ac
AC_INIT(smthbbs, 2.0dev, SYSOP@smth.org)
AM_INIT_AUTOMAKE([foreign dist-bzip2])  //configure.ac里用了 automake 的宏
                                     //automake 根据 Makfile.am 生成 Makefile.in
                                     //要读于 configure.ac ,此处 automake初始化
AC_CANONICAL_TARGET
case "${host}" in
  i*86-*-freebsd*)
        OSTYPE="FREEBSD"
        ;;      
  *-*-solaris*)
        OSTYPE="SOLARIS"
        LIBS="$LIBS -lnsl -lsocket"
        ;;  
  *-*-sunos*)
        OSTYPE="SUNOS"
        LIBS="$LIBS -lnsl -lsocket"
        ;;  
  *-*-linux*)        
        OSTYPE="LINUX"
        ;;  
  *-*-cygwin*)        
        OSTYPE="CYGWIN"
        LIBS="$LIBS -lcygipc"
        ;;  
  *)        
        OSTYPE="GENERIC"
        ;;        
esac              
CFLAGS="$CFLAGS -D$OSTYPE"
//确保源代码目录的完整性,通过检查当前目录是否包含 config.h.in
AC_CONFIG_SRCDIR([config.h.in])
//生成 config.h 头文件,其它就是实例化 config.h.in  
//运行autoheader 命令会根据此指令生成 config.h.in
AM_CONFIG_HEADER(config.h)
//设定 prefix 的默认值
AC_PREFIX_DEFAULT(/home/bbs)
m4_include(config.icc)
// --enable-innbbsd 参数
AC_ARG_ENABLE(innbbsd,
[  --enable-innbbsd
                enable innbbsd  support(need innbbsd package)],
[
        if test "$enableval" = "yes" ; then
                if test -d innbbsd; then
                    //实例化innbbsd 下的 Makfile.in生成 Makefile,
                    //并运行 linkinnd.sh转链接。
                       AC_CONFIG_FILES(innbbsd/Makefile
                                    innbbsd/linkinnd.sh)
                    BBSSUBDIRS="$BBSSUBDIRS innbbsd"
                else
                        AC_MSG_ERROR([can't find innbbsd package,please get it first!])
                fi
        fi
])
//--enable-ssh 参数
AC_ARG_ENABLE(ssh,
[  --enable-ssh
                enable ssh bbsd  support(need sshbbsd package)],
[
        if test "$enableval" = "yes" ; then
                if test -d sshbbsd; then
                    //在 sshbbsd 目录下运行 configure 命令
                    //而不是实例化 Makefile. sshbbsd 有相对的独立性
                        AC_CONFIG_SUBDIRS(sshbbsd)
            BBSSUBDIRS="$BBSSUBDIRS sshbbsd"
                else
                        AC_MSG_ERROR([can't find sshbbsd package,please get it first!])
                fi
        fi
])
if [ test -z "$enable_www" ]; then
        enable_www=yes
fi
//--enable-www
AC_ARG_ENABLE(www,
[  --enable-www
        enable web support(need bbs2www package)],
[
        if test "$enableval" = "yes" ; then
                if test -d bbs2www; then
            //实例化 bbs2www目录的Makefile 及 config.m4 文件
           AC_CONFIG_FILES([bbs2www/Makefile
                             bbs2www/lib/Makefile
                             bbs2www/phplib/Makefile
                             bbs2www/phplib/config.m4])
            BBSSUBDIRS="$BBSSUBDIRS bbs2www"
                else
                        AC_MSG_ERROR([can't find bbs2www package,please get it first!])
                fi
                CONFIG_HAVE_WWW=1
        else
                CONFIG_HAVE_WWW=0
        fi
])
//替换各 *.in 文件中的 @CONFIG_HAVE_WWW@ 变量
AC_SUBST(CONFIG_HAVE_WWW)
AC_SUBST(BBSSUBDIRS)
m4_include(bbs2www.in)
//一些由 autoscan 自动生成的check
# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h malloc.h netdb.h netinet/in.h sgtty.h stdlib.h string.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h termio.h termios.h unistd.h utime.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STAT
AC_C_CONST
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_CHECK_TYPES([struct utimbuf],[],[],[#include ])
AC_CHECK_SIZEOF(int *)
AC_CHECK_SIZEOF(long long int)
AC_CHECK_SIZEOF(long int)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(int64)
AC_CHECK_SIZEOF(int32)
# Checks for library functions.
AC_CONFIG_LIBOBJ_DIR(lib)
AC_FUNC_ALLOCA
AC_FUNC_FORK
AC_FUNC_GETLOADAVG
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_MMAP
AC_FUNC_SETPGRP
AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRFTIME
AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([alarm atexit bzero dup2 ftruncate getcwd gethostbyaddr gethostbyname gethostname inet_ntoa isascii memchr memset mkdir munmap rmdir select socket strcasecmp strcasestr strchr strdup strerror strncasecmp strpbrk strrchr strstr strtol utime memmem flock inet_aton inet_pton isblank])
AC_CHECK_TYPES(bool)
AC_CHECK_TYPES(sig_t,,,[#include ])
dnl Select Error language
//--enable-site
AC_ARG_ENABLE(site,
[  --enable-site=sitename
                          select site special files (see site dir) ],
[
    BBSSITE=$enableval
],[BBSSITE="smth"
SITEDIR=site])
if test -f $srcdir/site/$BBSSITE.c; then
        SITEDIR=site
else
  if test -f $srcdir/sites/$BBSSITE.c; then
        SITEDIR=sites
  else
        AC_MSG_ERROR([ERROR! Unknown site $BBSSITE, see site/])
  fi
fi
//替换各 *.in 文件中的@BBSSITE@ 变量
AC_SUBST(BBSSITE)
# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_YACC
m4_include(config.lib)
# Checks for libraries.
//作文件的软链接。当 libBBS 及site目录的源文件链入 src 目录
AC_CONFIG_LINKS(libBBS/site.c:$SITEDIR/$BBSSITE.c
                libBBS/site.h:$SITEDIR/$BBSSITE.h
                src/site.c:$SITEDIR/$BBSSITE.c
                src/site.h:$SITEDIR/$BBSSITE.h
                libBBS/default.c:$SITEDIR/default.c
                libBBS/default.h:$SITEDIR/default.h
                src/default.c:$SITEDIR/default.c
                src/default.h:$SITEDIR/default.h
                )
cd libBBS; for i in *.[[ch]] ; do
AC_CONFIG_LINKS(src/$i:libBBS/$i)
done
cd ..
ORIGIN_LIBTOOL=$LIBTOOL
AC_SUBST(ORIGIN_LIBTOOL)
AC_SUBST(SED)
abssrcdir=`cd $srcdir && pwd`
LIBTOOL="$abssrcdir/wrapper.sh"
//替换 *.in文件中的 @abssrcdir@ 变量
AC_SUBST(abssrcdir)
//实例化
AC_CONFIG_FILES([Makefile
                 libBBS/Makefile
                 libsystem/Makefile
                 rzsz/Makefile
                 daemon/Makefile
                 mail2bbs/Makefile
                 local_utl/Makefile
                 service/Makefile
                 service/pip/Makefile
                 service/worker/Makefile
                 service/personaldns/Makefile
                 src/bbsconfig.h
                 src/Makefile])
AC_CONFIG_FILES(wrapper.sh, chmod +x wrapper.sh)
AC_OUTPUT  


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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP