http://www.gnu.org/software/m4/m4.html

GNU M4 is an implementation of the traditional Unix macro processor. It is mostly SVR4 compatible although it has some extensions (for example, handling more than 9 positional parameters to macros). GNU M4 also has built-in functions for including files, running shell commands, doing arithmetic, etc.
GNU M4 is a macro processor in the sense that it copies its input to the output expanding macros as it goes. Macros are either builtin or user-defined and can take any number of arguments. Besides just doing macro expansion, m4 has builtin functions for including named files, running UNIX commands, doing integer arithmetic, manipulating text in various ways, recursion etc... m4 can be used either as a front-end to a compiler or as a macro processor in its own right.

M4是一个Unix宏处理器, 用于将输入赋值到模板中并展开成输出. 可以使用简单的运算和字符串操作, 主要用于编译前的预处理. 主要是因为autoconf而使用. M4存在于各种类Unix系统中, 并且已经被POSIX(Portable Operating System Interface)标准化 .

http://www.gnu.org/software/autoconf/autoconf.html

Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages. These scripts can adapt the packages to many kinds of UNIX-like systems without manual user intervention. Autoconf creates a configuration script for a package from a template file that lists the operating system features that the package can use, in the form of M4 macro calls.
Autoconf 是一个可扩展的M4宏集合, 用于产生shell脚本来自动配置软件源码. 这些脚本可以自动适配多种类Unix的操作系统. 需要与automake, libtool合用产生可移植的软件.

在软件发布时, 如果只是使用Autoconf, 涉及的文件和步骤如下

your source files --> [autoscan*] --> [configure.scan] --> configure.ac

configure.ac --.
| .------> autoconf* -----> configure
[aclocal.m4] --+---+
| `-----> [autoheader*] --> [config.h.in]
[acsite.m4] ---' Makefile.in

如果还使用了Automake, 则需要额外的一些文件:

[acinclude.m4] --.
|
[local macros] --+--> aclocal* --> aclocal.m4
|
configure.ac ----' configure.ac --.
+--> automake* --> Makefile.in
Makefile.am ---'

在软件配置过程中涉及的文件:

                      .-------------> [config.cache]
configure* ------------+-------------> config.log
|
[config.h.in] -. v .-> [config.h] -.
+--> config.status* -+ +--> make*
Makefile.in ---' `-> Makefile ---'

流程图

Autoconf 语法

Autoconf 语言与其他语言不一样, 其对待文本和代码是一样的所以需要用quotation来区分文本.

在调用宏方法时, 宏名称和括号之间不能有空格, 例如

     AC_INIT ([oops], [1.0]) # 错误
AC_INIT([hello], [1.0]) # 正确

参数应当由引用符号'['和']'包围, 并使用逗号分隔. 除非被引用符号包围, 参数前的空格和换行都会被忽略, 所以对所有可能包含宏名称, 逗号, 括号, 和前置空格的参数, 都应当加上引用符号. 例如

     AC_CHECK_HEADER([stdio.h],
[AC_DEFINE([HAVE_STDIO_H], [1],
[Define to 1 if you have <stdio.h>.])],
[AC_MSG_ERROR([sorry, can't do anything for you])])

上面是安全的做法, 也可以简化为

     AC_CHECK_HEADER([stdio.h],
[AC_DEFINE([HAVE_STDIO_H], 1,
[Define to 1 if you have <stdio.h>.])],
[AC_MSG_ERROR([sorry, can't do anything for you])])

因为'1'不可能是一个宏调用.  这里 AC_MSG_ERROR 的参数必须加引用符号, 否则它的逗号就会被误认为是参数分隔符. AC_CHECK_HEADER的第二和第三个参数必须用引用符号, 因为它们包含宏调用.  ‘HAVE_STDIO_H’, ‘stdio.h’, 和 ‘Define to 1 if you have <stdio.h>.’ 这三个参数不需要引用符号, 但是如果你恰巧定义了一个名称为'Define'或'stdio'的宏, 你就需要加上引用符号了. 谨慎的Autoconf用户会保留引用符号, 但是也有很多用户觉得麻烦, 写成:

     AC_CHECK_HEADER(stdio.h,
[AC_DEFINE(HAVE_STDIO_H, 1,
[Define to 1 if you have <stdio.h>.])],
[AC_MSG_ERROR([sorry, can't do anything for you])])

这是安全的, 只要你保持良好的命名规则, 不要使用‘HAVE_STDIO_H’, ‘stdio’, or ‘h’这样的名称. 虽然省略‘Define to 1 if you have <stdio.h>.’的引用符号在这里也是安全的, 但是这个做法不推荐, 因为消息字符串包含逗号的可能性很大. 下面的例子就是错误并且不安全的:

     AC_CHECK_HEADER(stdio.h,
AC_DEFINE(HAVE_STDIO_H, 1,
Define to 1 if you have <stdio.h>.),
AC_MSG_ERROR([sorry, can't do anything for you]))

In other cases, you may have to use text that also resembles a macro call. You must quote that text even when it is not passed as a macro argument. For example, these two approaches in configure.ac (quoting just the potential problems, or quoting the entire line) will protect your script in case autoconf ever adds a macro AC_DC:

echo "Hard rock was here!  --[AC_DC]"
     [echo "Hard rock was here!  --AC_DC"]
which results in this text in configure:

echo "Hard rock was here!  --AC_DC"
     echo "Hard rock was here!  --AC_DC"
When you use the same text in a macro argument, you must therefore have an extra quotation level (since one is stripped away by the macro substitution). In general, then, it is a good idea to use double quoting for all literal string arguments, either around just the problematic portions, or over the entire argument:

AC_MSG_WARN([[AC_DC] stinks  --Iron Maiden])
     AC_MSG_WARN([[AC_DC stinks  --Iron Maiden]])
However, the above example triggers a warning about a possibly unexpanded macro when running autoconf, because it collides with the namespace of macros reserved for the Autoconf language. To be really safe, you can use additional escaping (either a quadrigraph, or creative shell constructs) to silence that particular warning:

echo "Hard rock was here!  --AC""_DC"
     AC_MSG_WARN([[AC@&t@_DC stinks  --Iron Maiden]])
You are now able to understand one of the constructs of Autoconf that has been continually misunderstood... The rule of thumb is that whenever you expect macro expansion, expect quote expansion; i.e., expect one level of quotes to be lost. For instance:

AC_COMPILE_IFELSE(AC_LANG_SOURCE([char b[10];]), [],
      [AC_MSG_ERROR([you lose])])
is incorrect: here, the first argument of AC_LANG_SOURCE is ‘char b[10];’ and is expanded once, which results in ‘char b10;’; and the AC_LANG_SOURCE is also expanded prior to being passed to AC_COMPILE_IFELSE. (There was an idiom common in Autoconf's past to address this issue via the M4 changequote primitive, but do not use it!) Let's take a closer look: the author meant the first argument to be understood as a literal, and therefore it must be quoted twice; likewise, the intermediate AC_LANG_SOURCE macro should be quoted once so that it is only expanded after the rest of the body of AC_COMPILE_IFELSE is in place:

AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char b[10];]])], [],
       [AC_MSG_ERROR([you lose])])
Voilà, you actually produce ‘char b[10];’ this time!

On the other hand, descriptions (e.g., the last parameter of AC_DEFINE or AS_HELP_STRING) are not literals—they are subject to line breaking, for example—and should not be double quoted. Even if these descriptions are short and are not actually broken, double quoting them yields weird results.

Some macros take optional arguments, which this documentation represents as [arg] (not to be confused with the quote characters). You may just leave them empty, or use ‘[]’ to make the emptiness of the argument explicit, or you may simply omit the trailing commas. The three lines below are equivalent:

AC_CHECK_HEADERS([stdio.h], [], [], [])
     AC_CHECK_HEADERS([stdio.h],,,)
     AC_CHECK_HEADERS([stdio.h])
It is best to put each macro call on its own line in configure.ac. Most of the macros don't add extra newlines; they rely on the newline after the macro call to terminate the commands. This approach makes the generated configure script a little easier to read by not inserting lots of blank lines. It is generally safe to set shell variables on the same line as a macro call, because the shell allows assignments without intervening newlines.

You can include comments in configure.ac files by starting them with the ‘#’. For example, it is helpful to begin configure.ac files with a line like this:
     # Process this file with autoconf to produce a configure script.

m4, autoconf的更多相关文章

  1. 手动安装m4, autoconf, automake, libtool

    转自http://ruby-china.org/topics/2434 系列文章原载于自己的博客,TOPI.CO (http://topi.co) ,某天不小心就push错啦,懒得从头再来,上传到Ru ...

  2. 安装m4,autoconf,automake

    ###安装m4 wget http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz \ && tar -xzvf m4-1.4.13.tar. ...

  3. PHP7 redis扩展安装

    1.安装redis (1)下载:https://github.com/phpredis/phpredis/tree/php7 或下载http://pan.baidu.com/s/1i5DFrjn用sa ...

  4. Linux安装pdo_mysql模块

    网站不能访问 查看apache日志 PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find dr ...

  5. centos 7.0 phpize 扩展php

    phpize扩展php模块 phpize 所在目录 /usr/etc/php/bin/phpize 查看当前php配置情况 /usr/etc/php/bin/下面的php [root@localhos ...

  6. CentOS7安装memcached

    三台linux服务器系统CentOS7 一台memcached IP:192.168.155.134 一台Apache IP:192.168.155.130 一台nginx IP:192.168.15 ...

  7. php 安装redis扩展

    大家可以去http://code.google.com/p/redis/downloads/list这个地址找最近的下载wget http://redis.googlecode.com/files/r ...

  8. linux下为php添加mongodb扩展

    基于本博客yum安装的lamp环境,phpize 位于 /usr/bin,php-config 位于/usr/bin,php.ini 位于/etc/ 1.首先从http://pecl.php.net/ ...

  9. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

随机推荐

  1. tensorflow报错屏蔽的方法

    之前是报这样的错: OpKernel ('op: "BestSplits" device_type: "CPU"') for unknown op: BestS ...

  2. Laravel SQL 查询语句集锦

    1.从数据表中取得单一数据列 $user= DB::table('users')->where('name','John')->first(); 2.检索表中的所有行 复制代码代码如下: ...

  3. (转)NGUI中深度depth和z轴关系

    先列出转载链接: http://game.ceeger.com/forum/read.php?tid=8917 转载原文: 问题源自一个帖子,因为上传的图比较多,就另开了这个贴写下自己的试验结果,原帖 ...

  4. 闲聊DNN CTR预估模型

    原文:http://www.52cs.org/?p=1046 闲聊DNN CTR预估模型 Written by b manongb 作者:Kintocai, 北京大学硕士, 现就职于腾讯. 伦敦大学张 ...

  5. Creating fields using CSOM

      When creating a field, whether you are using CAML, server-side object mode, or one of the client-s ...

  6. 这次要好好吐槽下idea呢还是SpringMVC ?

    特么的!(我为什么要骂脏话,因为这个问题弱智+不能理解) 相信很多人遇到过 org.springframework.web.servlet.PageNotFound - No mapping foun ...

  7. [Canvas]New Running Dog

    欲看效果请下载后用Chrome浏览器打开index.html观看,下载地址:https://files.cnblogs.com/files/xiandedanteng/51-NewRunningDog ...

  8. (纪录片)《星际穿越》中的科学 The Science of Interstellar

    简介: 导演: Gail Willumsen编剧: Gail Willumsen主演: 克里斯托弗·诺兰 / 乔纳森·诺兰 / 基普·索恩 / 马修·麦康纳类型: 纪录片 / 短片制片国家/地区: 美 ...

  9. Class.isAssignableFrom(Class clz)方法 与 instanceof 关键字的区别

    Class.isAssignableFrom()是用来判断一个类Class1和另一个类Class2是否相同或是另一个类的子类或接口.   格式为:        Class1.isAssignable ...

  10. C#正则表达式 - 精通版

    1.正则所需要的命名空间是 using System.Text.RegularExpressions 2.创建Regex对象 new Regex(string pattern,RegexOptions ...