PHP源码之configure文件代码语法解析 —可以从中学习SHELL
configure文件的解析1.
#!/bin/sh
解析:
符号#!用来告诉系统执行该脚本的程序
2.#设置分隔符:变量(PATH_SEPARATOR)值
if test "X${PATH_SEPARATOR+set}" != Xset; then
UNAME=${UNAME-`uname 2>/dev/null`}
case X$UNAME in
*-DOS) lt_cv_sys_path_separator=';' ;;
*) lt_cv_sys_path_separator=':' ;;
esac
echo $UNAME
fi
解析:
1) X${PATH_SEPARATOR+set}
意思是如果设置了PATH_SEPARATOR,则用set置换变量,否则不进行置换.
语法
:变量=${参数+word}:如果设置了参数,则用word置换变量,否则不进行置换.
代码样例:
t1="ok"
echo "X${t1+set}" # output Xset
echo "X${t2+set}" # output X
exit 0;
2) ${UNAME-`uname 2>/dev/null`}
语法:
(1)
${UNAME-`uname 2>/dev/null`}
如果设置了UNAME值则用UNAME值置换变量的值,否则用`uname 2>/dev/null`置换.
变量=${参数-word} 如果设置了参数的值,则用参数值进行置换,否则用word置换.
样例:
#!/bin/sh
t1="t1value"
echo ${t1-word}
echo ${t2-word}
exit 0;
结果:
(2)
> /dev/null
就是将标准输出和标准出错的信息屏蔽不显示
2>/dev/null
:表示将命令的错误输出重定向到 /dev/null
1>/dev/nul
l:表示将命令的标准输出重定向到 /dev/null
3.用于打印帮助信息
ac_help=
ac_help="$ac_help
440 --with-libdir=NAME Look for libraries in .../NAME rather than .../lib"
.
.
.
4.指定安装目录
ac_default_prefix=/usr/local
5.运行在正确的SHELL终端下
SHELL=${CONFIG_SHELL-/bin/sh}
解析:
如果设置了CONFIG_SHELL则用CONFIG_SHELL,否则用/bin/sh置换变量SHELL.
6.定义ECHO
case X$ECHO in
X*--fallback-echo)
# Remove one level of quotation (which was required for Make).
ECHO=`echo "$ECHO" | sed 's,\\\\\$\\$0,'$0','`
;;
esac
解析:
1) sed 's,\\\\\$\\$0,'$0','
:
2) $0:表示当前执行的进程名,script 本身的名字,或者在正则表达式中表示整行输出
7.输出变量控制
echo=${ECHO-echo}
8.shift就是用掉一个位置参数,那么原来的$2就变成现在的$1了
9. 指定echo
for dir in $PATH /usr/ucb; do
IFS="$lt_save_ifs"
if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
test "X$echo_testing_string" = "X$echo_test_string"; then
echo="$dir/echo"
break
fi
done
解析:
(1) for dir in $PATH /usr/ucb; do
:dir的值为$PATH和/usr/ucb
10.数字具体表示(整个shell中也使用)
# File descriptor usage:
# 0 standard input
# 1 file creation
# 2 errors and warnings
# 3 some systems may open it to /dev/tty
# 4 used on the Kubota Titan
# 6 checking for... messages and results
# 5 compiler messages saved in config.log
if test "$silent" = yes; then
exec 6>/dev/null
else
exec 6>&1
fi
exec 5>./config.log
11.生成文件conftest.$ac_ext —— 用"cat >"方式生成
cat > conftest.$ac_ext <<EOF
#line 1932 "configure"
#include "confdefs.h"
int main() {
return __MINGW32__;
; return 0; }
EOF
页:
[1]