PostgreSQL数据库源码安装第一步——configure脚本分析(环境检测)

  源码编译PG8.4.1时,需要在安装完几个依赖的开发库后,在源代码目录下运行configure脚本。下面我们就分析一下该名为configure的shell脚本。其主要功能是猜测系统依赖变量的值并创建Makefiles。

一、环境检测

下面的代码是为了照顾zsh这种极品Shell,因为不使用zsh,所以这里不对代码进行分析。这里提一点emulate sh 到底是干什么的呢?Zsh can emulate sh, ksh, or csh. (csh is not fully emulated). zsh does an outstanding job in its sh and ksh emulation. You can start emulating another shell by running emulate some_shell from the command line. If you add the -R flag, all options will be reset to their default values. You can also create a link called 'csh', or 'ksh', or 'sh' that points to zsh. Zsh will notice that it was invoked with a different name, and do its best to behave like the shell you specify.

 1 # Be more Bourne compatible
 2 DUALCASE=1; export DUALCASE # for MKS sh
 3 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
 4   emulate sh
 5   NULLCMD=:
 6   # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
 7   # is contrary to our usage.  Disable this feature.
 8   alias -g '${1+"$@"}'='"$@"'
 9   setopt NO_GLOB_SUBST
10 else
11   case `(set -o) 2>/dev/null` in
12   *posix*) set -o posix ;;
13 esac
14 fi

 

PATH需要CR,避免依赖于Character Ranges,这里把所有字母和数字列出来。

1 as_cr_letters='abcdefghijklmnopqrstuvwxyz'
2 as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
3 as_cr_Letters=$as_cr_letters$as_cr_LETTERS
4 as_cr_digits='0123456789'
5 as_cr_alnum=$as_cr_Letters$as_cr_digits

检测PATH_SEPATATOR,即PATH变量的分隔符为;还是:。

 1 if test "${PATH_SEPARATOR+set}" != set; then
 2   echo "#! /bin/sh" >conf$$.sh
 3   echo  "exit 0"   >>conf$$.sh
 4   chmod +x conf$$.sh
 5   if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
 6     PATH_SEPARATOR=';'
 7   else
 8     PATH_SEPARATOR=:
 9   fi
10   rm -f conf$$.sh
11 fi

在可用的情况下,需要支持unset

1 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
2   as_unset=unset
3 else
4   as_unset=false
5 fi

 需要空格,tab,新行以顺序排列,放置编辑器出现关于space-tab兼容性问题。如果调用_AS_PATH_WALK时IFS没有设置,将会通过将IFS设置为空值,关闭word splitting。

1 as_nl='
2 '
3 IFS=" ""    $as_nl"

查找出运行该脚本的用户

 1 # Find who we are.  Look in the path if we contain no directory separator.
 2 case $0 in
 3   *[\\/]* ) as_myself=$0 ;;
 4   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 5 for as_dir in $PATH
 6 do
 7   IFS=$as_save_IFS
 8   test -z "$as_dir" && as_dir=.
 9   test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
10 done
11 IFS=$as_save_IFS
12 
13      ;;
14 esac

如果没有发现用户,可能是通过sh COMMAND运行的

1 if test "x$as_myself" = x; then
2   as_myself=$0
3 fi
4 if test ! -f "$as_myself"; then
5   echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
6   { (exit 1); exit 1; }
7 fi

Work around bugs in pre-3.0 UWIN ksh.

1 for as_var in ENV MAIL MAILPATH
2 do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
3 done
4 PS1='$ '
5 PS2='> '
6 PS4='+ '

NLS nuisances.

 1 for as_var in \
 2   LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
 3   LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
 4   LC_TELEPHONE LC_TIME
 5 do
 6   if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
 7     eval $as_var=C; export $as_var
 8   else
 9     ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
10   fi
11 done

 

 

basename 命令

$ basename /usr/bin/sort       输出"sort"。

$ basename ./include/stdio.h .h  输出"stdio"。

为basename指定一个路径,basename命令会删掉所有的前缀包括最后一个slash(‘/’)字符,然后将字符串显示出来。

basename命令格式:
basename [pathname] [suffix]
basename [string] [suffix]
 suffix为后缀,如果suffix被指定了,basename会将pathname或string中的suffix去掉。
 1 # Required to use basename.
 2 if expr a : '\(a\)' >/dev/null 2>&1 &&
 3    test "X`expr 00001 : '.*\(...\)'`" = X001; then
 4   as_expr=expr
 5 else
 6   as_expr=false
 7 fi
 8 
 9 if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
10   as_basename=basename
11 else
12   as_basename=false
13 fi

可执行文件的名字

 1 # Name of the executable.
 2 as_me=`$as_basename -- "$0" ||
 3 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
 4      X"$0" : 'X\(//\)$' \| \
 5      X"$0" : 'X\(/\)' \| . 2>/dev/null ||
 6 echo X/"$0" |
 7     sed '/^.*\/\([^/][^/]*\)\/*$/{
 8         s//\1/
 9         q
10       }
11       /^X\/\(\/\/\)$/{
12         s//\1/
13         q
14       }
15       /^X\/\(\/\).*/{
16         s//\1/
17         q
18       }
19       s/.*/./; q'`

 

对系统的命令的测试

 1   if test $as_have_required = yes &&      (eval ":
 2 (as_func_return () {
 3   (exit \$1)
 4 }
 5 as_func_success () {
 6   as_func_return 0
 7 }
 8 as_func_failure () {
 9   as_func_return 1
10 }
11 as_func_ret_success () {
12   return 0
13 }
14 as_func_ret_failure () {
15   return 1
16 }
17 
18 exitcode=0
19 if as_func_success; then
20   :
21 else
22   exitcode=1
23   echo as_func_success failed.
24 fi
25 
26 if as_func_failure; then
27   exitcode=1
28   echo as_func_failure succeeded.
29 fi
30 
31 if as_func_ret_success; then
32   :
33 else
34   exitcode=1
35   echo as_func_ret_success failed.
36 fi
37 
38 if as_func_ret_failure; then
39   exitcode=1
40   echo as_func_ret_failure succeeded.
41 fi
42 
43 if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
44   :
45 else
46   exitcode=1
47   echo positional parameters were not saved.
48 fi
49 
50 test \$exitcode = 0) || { (exit 1); exit 1; }
51 
52 (
53   as_lineno_1=\$LINENO
54   as_lineno_2=\$LINENO
55   test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" &&
56   test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; }
57 ") 2> /dev/null; then

 

 

 1 else
 2   as_candidate_shells=
 3     as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 4 for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
 5 do
 6   IFS=$as_save_IFS
 7   test -z "$as_dir" && as_dir=.
 8   case $as_dir in
 9      /*)
10        for as_base in sh bash ksh sh5; do
11          as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
12        done;;
13        esac
14 done
15 IFS=$as_save_IFS
16 
17 
18       for as_shell in $as_candidate_shells $SHELL; do
19      # Try only shells that exist, to save several forks.
20      if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
21         { ("$as_shell") 2> /dev/null <<\_ASEOF
22 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
23   emulate sh
24   NULLCMD=:
25   # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
26   # is contrary to our usage.  Disable this feature.
27   alias -g '${1+"$@"}'='"$@"'
28   setopt NO_GLOB_SUBST
29 else
30   case `(set -o) 2>/dev/null` in
31   *posix*) set -o posix ;;
32 esac
33 
34 fi

 

posted @ 2020-10-30 23:46  肥叔菌  阅读(413)  评论(0)    收藏  举报