本文章是自己通过阅读configure的总结笔记,可能部分理解有错误,希望大家不吝指出,大家共同学习
通过configure用户选项进行配置,加上测试系统支持的特性,生成配置结果,根据配置结果替换编译系统中的变量,从而实现根据配置改变编译的结果
一般是将 xxx.in 根据配置替换其中的变量 变为 xxx, 后缀in表示input的意思
在configure中定义了ac_subst_vars,这里面就是包含可以替换的变量
ac_user_opts 用户的选项
ac_precious_vars 配置变量,可以通过环境变量或者命令行进行赋值
configure是一个shell脚本,通过用户选项ac_user_opts 和 配置变量ac_precious_vars 的值,然后对系统环境进行测试,生成config.status 文件
: "${CONFIG_STATUS=./config.status}"
cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
#! $SHELL
# Generated by $as_me.
# Run this file to recreate the current configuration.
# Compiler output produced by configure, useful for debugging
# configure, is in config.log if it exists.
debug=false
ac_cs_recheck=false
ac_cs_silent=false
SHELL=\${CONFIG_SHELL-$SHELL}
export SHELL
_ASEOF
...
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
exec 5>>config.log
{
echo
sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
$as_echo "$ac_log"
} >&5
_ACEOF
# configure is writing to config.log, and then calls config.status.
# config.status does its own redirection, appending to config.log.
# Unfortunately, on DOS this fails, as config.log is still kept open
# by configure, so config.status won't be able to write to it; its
# output is simply discarded. So we exec the FD to /dev/null,
# effectively closing config.log, so it can be properly (re)opened and
# appended to by config.status. When coming back to configure, we
# need to make the FD available again.
if test "$no_create" != yes; then
ac_cs_success=:
ac_config_status_args=
test "$silent" = yes &&
ac_config_status_args="$ac_config_status_args --quiet"
exec 5>/dev/null
$SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
exec 5>>config.log
# Use ||, not &&, to avoid exiting from the if with $? = 1, which
# would make configure fail if this is the last instruction.
$ac_cs_success || as_fn_exit 1
fi
config.status是一个shell脚本,configure生成config.status后,然后执行config.status
$SHELL $CONFIG_STATUS $ac_config_status_args
configure生成的log放在config.log中,执行config.status生成的log也append在config.log后面
confdefs.h只是配置的中间结果,最终会被处理写入config.status文件中
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use libcap-ng" >&5
$as_echo_n "checking whether to use libcap-ng... " >&6; }
if test x$CAPNG_LDADD != x ; then
$as_echo "#define HAVE_LIBCAP_NG 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
...
# Transform confdefs.h into an awk script `defines.awk', embedded as
# here-document in config.status, that substitutes the proper values into
# config.h.in to produce config.h.
config.status需要替换哪些文件中的变量呢?
config_files=" Makefile lib/Makefile lib/audit.pc lib/test/Makefile"
config_headers=" config.h"
config_commands=" depfiles libtool"
分别记录了哪些文件需要config,也即是需要替换
# Handling of arguments.
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
"depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
"libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;
其他的细节
1.设置好环境,然后重新执行自己,也就是重新执行configure
if test "x$as_myself" = x; then
as_myself=$0
fi
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
exec 6>&1
test "$silent" = yes && exec 6>/dev/null
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by audit $as_me 2.8.4, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
_ACEOF
exec 5>>config.log
后面配置过程中的打印
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
$as_echo_n "checking build system type... " >&6; }
&6主要打印在终端,&5打印到config.log中,如果设置了silent=yes,那么终端将不打印任何消息。
ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias`
ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias`
ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias`
config.guess是一个shell脚本,主要是在没有指定build时去猜测
config.sub 也是一个shell脚本, 主要用于构建echo $basic_machine$os
例如:
ac_cv_build=x86_64-pc-linux-gnu
ac_cv_host=arm-unknown-linux-gnueabihf
ac_cv_target=arm-unknown-linux-gnueabihf
至于是build,host, target的区别:
build: 当前构建系统的类型
host : 构建的程序哪个系统上运行
target : 程序运行生成的文件在哪个系统上运行,例如编译器gcc