]> git.cworth.org Git - gzip/blob - m4/shell.m4
7eb470761eb244bc6f06f3c56e0a5b152a41cecb
[gzip] / m4 / shell.m4
1 #serial 4
2
3 # AC_PROG_SHELL
4 # -------------
5 # Check for a working (i.e. POSIX-compatible) shell.
6 # Written by Paul Eggert <eggert@twinsun.com>,
7 # from an idea suggested by Albert Chin-A-Young <china@thewrittenword.com>.
8 AC_DEFUN([AC_PROG_SHELL],
9   [AC_MSG_CHECKING([for a POSIX-compliant shell])
10    AC_CACHE_VAL(ac_cv_path_shell,
11      [ac_command='
12         # Test the noclobber option, using the portable POSIX.2 syntax.
13         set -C
14         rm -f conftest.c
15         >conftest.c || exit
16         >|conftest.c || exit
17         !>conftest.c || exit
18       '
19       ac_cv_path_shell=no
20
21       case $SHELL in
22       /*)
23         rm -f conftest.c
24         if ("$SHELL" -c "$ac_command") 2>/dev/null; then
25           ac_cv_path_shell=$SHELL
26         fi;;
27       esac
28
29       case $ac_cv_path_shell in
30       no)
31         # Prefer shells that are more likely to be installed in the
32         # same place on all hosts of this platform.  Therefore, prefer
33         # shells in /bin and /usr/bin to shells in the installer's
34         # PATH.  Also, loop through PATH first and then through
35         # shells, since less-"nice" shells in /bin and /usr/bin are
36         # more likely to be installed than "nicer" shells elsewhere.
37         as_save_IFS=$IFS; IFS=:
38         for as_dir in /bin /usr/bin $PATH
39         do
40           IFS=$as_save_IFS
41           case $as_dir in
42           /*)
43             for ac_base in sh bash ksh sh5; do
44               rm -f conftest.c
45               if ("$as_dir/$ac_base" -c "$ac_command") 2>/dev/null; then
46                 ac_cv_path_shell=$as_dir/$ac_base
47                 break
48               fi
49             done
50             case $ac_cv_path_shell in
51             /*) break;;
52             esac;;
53           esac
54         done
55         rm -f conftest.c;;
56       esac])
57    AC_MSG_RESULT($ac_cv_path_shell)
58    SHELL=$ac_cv_path_shell
59    if test "$SHELL" = no; then
60      SHELL=/bin/sh
61      AC_MSG_WARN([using $SHELL, even though it does not conform to POSIX])
62    fi
63    AC_SUBST(SHELL)])