configure 深层解读!
author:hjjdebug
date: 2019年 12月 28日 星期六 22:06:34 CST
这是hello world 简单c程序运行configure 的输出信息,它们到底是什么含义呢?
./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
搞清清这个问题,除了阅读configure.ac, 还要阅读configure 文件,才能知道其含义
下面对以上每一条输出,说明其来历.
我看了,我忘了, 我做了,我懂了!
configure 文件是一个shell 脚本文件
------------------------------------------------------------
checking for a BSD-compatible install... /usr/bin/install -c
------------------------------------------------------------
沿着path路径搜索install(包括ginstall,scoinst),找到后,建立两个测试文件conftest.one, conftest.two, 并把他们用install -c
安装到conftest.dir目录下,然后测试这4个文件都存在(test -s),表示这个install 是可以工作的, 把这个install 打印在后面
------------------------------------------------------------
checking whether build environment is sane... yes
------------------------------------------------------------
用set 设置一个环境变量,检查这个变量的值看是否一致.
------------------------------------------------------------
checking for a thread-safe mkdir -p... /bin/mkdir -p
------------------------------------------------------------
沿path搜索mkdir(包括gmkdir), 发现其为文件 -f, 可运行 -x, 检查其版本号有相关关键字, 则留存,输出yes
------------------------------------------------------------
checking for gawk... gawk
------------------------------------------------------------
沿路径搜索gawk...
------------------------------------------------------------
checking whether make sets $(MAKE)... yes
------------------------------------------------------------
它创建一个conftest.make, 检查$(MAKE)是否被设置. 与期望对应为yes
------------------------------------------------------------
checking whether make supports nested variables... yes
------------------------------------------------------------
用make -f - 来检查,能通过就yes
------------------------------------------------------------
checking for gcc... gcc
------------------------------------------------------------
沿路径搜索gcc,是文件,可运行
------------------------------------------------------------
checking whether the C compiler works... yes
------------------------------------------------------------
调用gcc conftest.c, 然后检查可执行文件,a.out,conftest,conftest.exe等,判断
是否存在确定其是否可以工作
------------------------------------------------------------
checking for C compiler default output file name... a.out
------------------------------------------------------------
上边检查时已查出结果
------------------------------------------------------------
checking for suffix of executables...
------------------------------------------------------------
执行 gcc -o conftest conftest.c,检查返回值
------------------------------------------------------------
checking whether we are cross compiling... no
------------------------------------------------------------
执行编译生成conftest后,执行调用./conftest, 检查返回值可知是否是交叉编译
------------------------------------------------------------
checking for suffix of object files... o
------------------------------------------------------------
执行 gcc -c conftest.c 检查生成了什么文件
------------------------------------------------------------
checking whether we are using the GNU C compiler... yes
------------------------------------------------------------
其实就是编译conftest.c 无错误就是yes
------------------------------------------------------------
checking whether gcc accepts -g... yes
------------------------------------------------------------
用-g 选项编译,无错误为yes
------------------------------------------------------------
checking for gcc option to accept ISO C89... none needed
------------------------------------------------------------
写一个复杂的测试文件conftest.c,然后编译, 加上c89选项(现在没人用了),
加不加都没错误就是 不需要该标记.
------------------------------------------------------------
checking whether gcc understands -c and -o together... yes
------------------------------------------------------------
这个意义比较明确,两个选项放一起做个测试
------------------------------------------------------------
checking for style of include used by make... GNU
------------------------------------------------------------
写一个简单的被包含的1.make文件,再写t.make include 1.make文件
测试make -f t.make, 无错误为GNU, 如果要写成.include来包含,则是BSD格式了.
------------------------------------------------------------
checking dependency style of gcc... gcc3
------------------------------------------------------------
这个测试步骤比较多,准备文件也多,它要找出是gcc,msvc还是msys等,
------------------------------------------------------------
checking that generated files are newer than configure... done
------------------------------------------------------------
与config 执行的同时,还创建了一个一秒的sleep进程,要等那个一秒的进程先结束
然后再输出done
下面开始创建文件:
------------------------------------------------------------
configure: creating ./config.status
------------------------------------------------------------
下面是运行./configure.status 的输出, 还是shell脚本,就不分析了.
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
configure 脚本阅读:
向config.log 输出信息:
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
1. $as_echo 是什么? 是printf %s\n
2. $as_me 是什么? 是configure, 是./configure --参数的basename
3. ${as_lineno} 是什么? 有可能没定义,也有可能定义了
4. $LINENO 是什么? 这是bash或者sh 的一个内置变量,代表了行号,我到处找不到它,在bash手册页中找到了.
它的出处曾经令我很困惑.
5. &5 是什么?
exec 5>>config.log
直接把文件的第五项文件描述符定向到config.log,从而之后所有向5号文件描述符输出的内容都将会放在config.log文件中。
config.log中记录了configure的命令行参数,环境及后面的配置过程记录等.
exec 6>&1 ,同理,把6重定向到1