Autotools上手指南1——autoconf基本思想
来源:互联网 发布:nginx能干什么 编辑:程序博客网 时间:2024/05/17 09:04
转自:http://blog.dccmx.com/2011/01/autotools-1/
要想弄懂Autotools并使用它,必须先要了解一下M4这个怪物。
那么何为M4呢,M4的名称取自Macro(M后面跟4个字母…)。它和C预处理器里的宏是一个概念(其实,M4和C预处理器都K&R操刀设计的!!),用来处理文本替换。也就是说,M4是bash里的预处理器。
取自维基的例子:
divert(-1)
This `divert' discards this text. Note that I had to quote the `divert'
in the comment so it wouldn't get undiverted.
This starts the count at ONE as the incr is a preincrement.
define(`H2_COUNT', 0)
The define H2_COUNT is redefined every time the H2 macro is used.
The dnl deletes everything on the line after it in the output (ie this bit)
define(`H2', `define(`H2_COUNT', incr(H2_COUNT))'dnl
`<h2>H2_COUNT. $1</h2>')
divert(0)dnl diversion to 0 means back to normal dnl removes this line.
H2(First Section)
H2(Second Section)
H2(Conclusion)
这段M4宏用m4处理输出的结果就是:
123<h2>1. First Section</h2>
<h2>2. Second Section</h2>
<h2>3. Conclusion</h2>
简单说下:
1.M4的语法跟C里面宏的语法差不多,都很像函数,名字加括号。
2.M4里的参数即使声明了也是可以忽略的,如果一个宏一个参数都不加的话,括号都可以忽略。
懂了吧。就当你懂了。
autoconf就是基于M4这个工具来生成configure脚本的。
我们来看一个最简单的autoconf输入,将下面代码存为configure.ac:
123AC_INIT([test], [1.0])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
再新建一个文件Makefile.in内容如下:
1234all: @PACKAGE_NAME@_bin
@PACKAGE_NAME@_bin: test.c
gcc -o @PACKAGE_NAME@_bin test.c
好,下面执行命令:
12$ autoconf
$ ./configure
看看,是不是生成了Makefile,是不是下面这样:
1234all: test_bin
test_bin: test.c
gcc -o test_bin test.c
中间发生了什么?停我慢慢道来。
首先,autoconf读取configure.ac里的宏,并调用M4处理这些宏,做些检查,如果你很感兴趣,这些宏的实现可以在/usr/share/autoconf/autoconf/*.m4里找到这些宏的定义(看了不要发疯)。检查完会生成两个文件:configure。执行configure脚本生成config.status和config.log。config.log里面是执行的记录,config.status是下一步执行的脚本,用来生成Makefile,configure生成完这个脚本会自动调用的。
那Makefile.in又是什么呢?那是第二个宏AC_CONFIG_FILES([Makefile])执行时的默认输入。方括号是用来表示参数的。就像上面的‘`’一样。Makefile.in就是一个模板,用来生成Makefile。执行configure脚本时(实际上是config.status脚本),里面的%变量%会被替换成相应的内容。有哪些变量?看看config.log就知道了。
好了,autoconf的基本原理就这样了,本质上就做了件检查环境和变量替换的事。其他的事情以后慢慢讲。
- Autotools上手指南1——autoconf基本思想
- Autotools上手指南Autotools上手指南1——autoconf基本思想
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》第一章<GNU Autotools简要介绍>
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》第一章<GNU Autotools简要介绍>
- autotools —— autoconf和automake生成Makefile文件(源文件位于多个子文件夹)
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》第三章<用Autoconf配置你的项目>
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》第三章<用Autoconf配置你的项目>
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》第二章<理解GNU编码标准>
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》第二章<理解GNU编码标准>
- autotools automake autoconf libtool 笔记
- automake/autotools/autoconf simple guide
- autotools automake autoconf libtool 笔记
- Autotools: Autoconf, Automake and Libtool
- Elasticsearch上手——熟悉基本操作
- GNU Autotools (autoconf, automake, libtool, etc.) 自动化编译 (1) 简单示例
- 用autotools(Automake\Autoconf)生成Makefile
- Linux下如何使用autotools(autoconf/automake)
- SendMessage
- PCI小结
- ASP.NET网站建设笔记1—页面居中
- Materials Studio 5.5 集群安装拾遗
- STRUTS2为ACTION配置METHOD属性
- Autotools上手指南1——autoconf基本思想
- HTML---- 渐变颜色, P强制不换行、自动换行、强制换行
- SharePoint Online 沙盒解决方案开发小结
- MyEclipse更改默认字符集
- VIE结构是什么?互联网公司
- 压缩感知基本原理
- java 将一个字符串解析为日期 将日期转为自己定义的格式以字符串输出
- Oracle11g卸载详解
- 轻松搞定面试中的链表题目