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. go语言之进阶篇通过select实现斐波那契数列

    一.select作用 Go里面提供了一个关键字select,通过select可以监听channel上的数据流动. select的用法与switch语言非常类似,由select开始一个新的选择块,每个选 ...

  2. COCO数据集深入理解

    TensorExpand/TensorExpand/Object detection/Data_interface/MSCOCO/ 深度学习数据集介绍及相互转换 Object segmentation ...

  3. mysql主从备份及原理分析

    一.mysql主从备份(复制)的基本原理mysql支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.mysql复制基于主服务器在二进制日志中跟踪所有对数据库的更 ...

  4. 转:Parameter Server 详解

    Parameter Server 详解   本博客仅为作者记录笔记之用,不免有很多细节不对之处. 还望各位看官能够见谅,欢迎批评指正. 更多相关博客请猛戳:http://blog.csdn.net/c ...

  5. Visual stuido 项目路径的奇怪问题

    从别人那里以zip的形式接受了一个solution, 然后在接收目录解压缩,然后剪切到其他的目录.此时报错,说找不到项目文件,看Visual studio 寻找的详细路径,发现它还是到解压缩的那个目录 ...

  6. 定制加载loading 图片

    项目中要使用一个动态加载图片,找了好久都没有合适的最后发现了这个网站,自由定制需要的gif图片,完全免费啊 http://preloaders.net/en/

  7. Direct2D教程VII——变换几何(TransformedGeometry)对象

    目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...

  8. C#.NET常见问题(FAQ)-如何让文本框textbox内容靠右显示

    对于TextBox,我可以设置Text-Align属性为right,就可以让文字靠右了   对于Label而言,需要修改AutoSize为False,并修改TextAlign为MiddleRight, ...

  9. ArcGIS10.4 Runtime Error R6034

    现在甲方采购的ArcGIS Desktop正版,一般都是较高的版本(10.4或10.4.1),但10.4经常报出C++ Runtime R6034错误. 问题 "Microsoft Visu ...

  10. android中动态修改ImageView控件的宽高度

    本例实现了动态修改ImageView控件的宽高度,有两个按钮,一个按钮实现放大image,一个按钮实现缩小image activity_main.xml <?xml version=" ...