autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Generic mechanism to detect shell features


From: bonzini
Subject: [PATCH] Generic mechanism to detect shell features
Date: Mon, 12 Jan 2004 14:21:37 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031020 Debian/1.5-1

This patch adds to m4sh a generic mechanism to detect required or desirable shell features, and when looping over the shells, avoid shells that do not require the former and prefer shells that have the latter.

The idea is to pass tests to AS_DETECT_REQUIRED and AS_DETECT_SUGGESTED: for now both $LINENO tests and shell functions tests go into AS_DETECT_SUGGESTED, but as soon as they will be used functions will automatically be required.

Could anybody please test it on a poor shell? If it is ok there, ok to commit?

Paolo

2003-01-12  Paolo Bonzini  <address@hidden>

       * lib/m4sugar/m4sh.m4 (M4SH-SANITIZE): New diversion.
       (AS_INIT): Output shell initialization there.  Removed optional
       parameter.  Call AS_SHELL_FN_SPY.
       (AS_INIT_WITH_SHELL_FN): Removed.
       (AS_SHELL_FN_SPY): New macro.
       (AS_DETECT_REQUIRED, AS_DETECT_SUGGESTED): New
       macros.
       (AS_SHELL_SANITIZE): Remove loop to find better shell.
       (_AS_DETECT_BETTER_SHELL, _AS_DETECT_SUGGESTED_FEATURES,
       _AS_DETECT_REQUIRED_FEATURES): Move it here.
       (_AS_SHELL_FN_WORK): Remove shell invocation, leave
       the test only.
       (AS_REQUIRE_SHELL_FN): Require shell functions when
       it is used.
       (_AS_LINENO_WORKS): Put around braces, we do not
       trigger the bash bug anymore.
       * lib/autotest/general.m4: Document M4SH-SANITIZE, do not
       use AS_INIT_WITH_SHELL_FN.

Index: lib/autotest/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autotest/general.m4,v
retrieving revision 1.155
diff -u -r1.155 general.m4
--- lib/autotest/general.m4     5 Jan 2004 07:05:22 -0000       1.155
+++ lib/autotest/general.m4     12 Jan 2004 12:58:34 -0000
@@ -60,7 +60,8 @@
 #    1. HEADER-REVISION
 #    2. HEADER-COMMENT
 #    3. HEADER-COPYRIGHT
-#    4. M4SH-INIT
+#    4. M4SH-SANITIZE
+#    5. M4SH-INIT
 # 1000. BODY
 #
 # Defined below:
@@ -142,7 +143,7 @@
          m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1], [: $1]))
 m4_define([AT_ordinal], 0)
 m4_define([AT_banner_ordinal], 0)
-AS_INIT_WITH_SHELL_FN
+AS_INIT
 AS_PREPARE
 m4_divert_push([DEFAULTS])dnl
 
Index: lib/m4sugar/m4sh.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.111
diff -u -r1.111 m4sh.m4
--- lib/m4sugar/m4sh.m4 5 Jan 2004 07:43:48 -0000       1.111
+++ lib/m4sugar/m4sh.m4 12 Jan 2004 12:58:35 -0000
@@ -64,9 +64,10 @@
 #   Purpose of the script etc.
 # - HEADER-COPYRIGHT
 #   Copyright notice(s)
+# - M4SH-SANITIZE
+#   M4sh's shell setup
 # - M4SH-INIT
-#   M4sh's initializations
-#
+#   M4sh initialization
 # - BODY
 #   The body of the script.
 
@@ -81,7 +82,8 @@
 m4_define([_m4_divert(HEADER-REVISION)],   1)
 m4_define([_m4_divert(HEADER-COMMENT)],    2)
 m4_define([_m4_divert(HEADER-COPYRIGHT)],  3)
-m4_define([_m4_divert(M4SH-INIT)],         4)
+m4_define([_m4_divert(M4SH-SANITIZE)],     4)
+m4_define([_m4_divert(M4SH-INIT)],         5)
 m4_define([_m4_divert(BODY)],           1000)
 
 # Aaarg.  Yet it starts with compatibility issues...  Libtool wants to
@@ -141,8 +143,7 @@
 # xx_REQUIRE macros, BODY-TO-EXPAND is mandatory.
 #
 m4_define([AS_REQUIRE_SHELL_FN],
-[m4_provide_if([AS_INIT_WITH_SHELL_FN],
-              [m4_warn([syntax], [AS_INIT_WITH_SHELL_FN not called.])])dnl
+[AS_REQUIRE([AS_DETECT_SHELL_FN], [AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])])
 m4_provide_if([AS_SHELL_FN_$1], [],
                [m4_provide([AS_SHELL_FN_$1])m4_divert_text([M4SH-INIT], [$1() {
 $2
@@ -167,14 +168,87 @@
 ])
 
 
-# _AS_SHELL_FN_WORK(TESTED-SHELL)
-# --------------------------------------------------
+# AS_DETECT_REQUIRED(TEST)
+# ------------------------
+# Refuse to execute under a shell that does not pass
+# the given TEST.
+m4_define([_AS_DETECT_REQUIRED_BODY], [])
+m4_define([AS_DETECT_REQUIRED],
+[_AS_DETECT_BETTER_SHELL[]dnl
+m4_append([_AS_DETECT_REQUIRED_BODY], [{ $1 } || { AS_EXIT(1) }
+])])
+
+m4_define([_AS_DETECT_REQUIRED_FEATURES],
+[{ _AS_QUOTE([$1]) <<\_ASEOF
+_AS_BOURNE_COMPATIBLE
+_AS_DETECT_REQUIRED_BODY
+_ASEOF
+} >/dev/null 2>&1])
+
+# AS_DETECT_SUGGESTED(TEST)
+# ------------------------
+# Prefer to execute under a shell that passes the given TEST.
+m4_define([_AS_DETECT_SUGGESTED_BODY], [])
+m4_define([AS_DETECT_SUGGESTED],
+[_AS_DETECT_BETTER_SHELL[]dnl
+m4_append([_AS_DETECT_SUGGESTED_BODY], [{ $1 } || { AS_EXIT(1) }
+])])
+
+m4_define([_AS_DETECT_SUGGESTED_FEATURES],
+[m4_ifset([_AS_DETECT_SUGGESTED_BODY], [{ _AS_QUOTE([$1]) <<\_ASEOF
+_AS_BOURNE_COMPATIBLE
+_AS_DETECT_SUGGESTED_BODY
+_ASEOF
+} >/dev/null 2>&1], [:])])
+
+
+# _AS_DETECT_BETTER_SHELL
+# -----------------------
+# The real workhorse for detecting a shell with the correct
+# features.
+m4_define([_AS_DETECT_BETTER_SHELL],
+[m4_expand_once([m4_wrap([m4_divert_text([M4SH-SANITIZE], [
+if test "x$CONFIG_SHELL" = x; then
+  AS_IF([_AS_DETECT_REQUIRED_FEATURES([$SHELL])], [as_have_required=yes], 
[as_have_required=no])
+  AS_IF([test $as_have_required = yes && 
_AS_DETECT_SUGGESTED_FEATURES([$SHELL])],
+    [CONFIG_SHELL="$SHELL"],
+    [_AS_PATH_WALK([/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH],
+      [case $as_dir in
+        /*)
+          for as_base in sh sh5 ksh zsh bash; do
+            if test -f $as_dir/$as_base; then
+              AS_IF([_AS_DETECT_REQUIRED_FEATURES([$as_dir/$as_base])],
+                    [CONFIG_SHELL=$as_dir/$as_base
+                    as_have_required_yes
+                    AS_IF([_AS_DETECT_SUGGESTED_FEATURES([$as_dir/$as_base])], 
[break])])
+            fi
+          done
+       esac])
+
+    if test $as_have_required = no; then
+      echo This script requires a shell more modern than all the
+      echo shells that I found on your system.  Please install a
+      echo modern shell, or manually run the script under such a
+      echo shell if you do have one.
+      AS_EXIT(1)
+    fi
+
+    if test "$SHELL" != "$CONFIG_SHELL"; then
+      AS_UNSET([ENV])
+      AS_UNSET([BASH_ENV])
+      export CONFIG_SHELL
+      exec "$CONFIG_SHELL" "$as_myself" ${1+"address@hidden"}
+    fi])
+fi
+])])])])
+
+
+# _AS_SHELL_FN_WORK
+# -----------------
 # This is a spy to detect "in the wild" shells that do not support shell
 # functions correctly.  It is based on the m4sh.at Autotest testcases.
 m4_define([_AS_SHELL_FN_WORK],
-[{ $1 2>/dev/null <<\_ASEOF
-_AS_BOURNE_COMPATIBLE
-func_return () {
+[func_return () {
   (exit [$]1)
 }
 
@@ -212,13 +286,10 @@
   echo func_ret_failure succeeded.
 ])
 AS_EXIT($exitcode)
-_ASEOF
-}])
+])
 
-# AS_SHELL_SANITIZE(WHAT-IF-SHELL-FUNCTIONS-DO-NOT-WORK)
-# ------------------------------------------------------
-# The parameter is temporary; it will go away and you
-# should not rely on it.
+# AS_SHELL_SANITIZE
+# -----------------
 m4_defun([AS_SHELL_SANITIZE],
 [## --------------------- ##
 ## M4sh Initialization.  ##
@@ -248,28 +319,6 @@
   AS_ERROR([cannot find myself; rerun with an absolute path])
 fi
 
-dnl In the future, the `else' branch will be that in AS_INIT_WITH_SHELL_FN.
-AS_IF([_AS_SHELL_FN_WORK([$SHELL])], [], [
-  case $CONFIG_SHELL in
-  '')
-    _AS_PATH_WALK([/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH],
-      [for as_base in sh bash ksh sh5; do
-        case $as_dir in
-        /*)
-          AS_IF([_AS_SHELL_FN_WORK([$as_dir/$as_base])], [
-            AS_UNSET(BASH_ENV)
-            AS_UNSET(ENV)
-            CONFIG_SHELL=$as_dir/$as_base
-            export CONFIG_SHELL
-            exec "$CONFIG_SHELL" "$as_myself" ${1+"address@hidden"}
-          ]);;
-        esac
-       done]);;
-  *)
-    $1;;
-  esac
-])
-
 # Work around bugs in pre-3.0 UWIN ksh.
 $as_unset ENV MAIL MAILPATH
 PS1='$ '
@@ -632,12 +681,13 @@
 # cause "bash -c '_ASLINENO_WORKS'" to fail (with Bash 2.05, anyway),
 # but that bug is irrelevant to our use of LINENO.
 m4_define([_AS_LINENO_WORKS],
-[
+[{
   as_lineno_1=$LINENO
   as_lineno_2=$LINENO
   as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
   test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x$as_lineno_3"  = "x$as_lineno_2"])
+  test "x$as_lineno_3"  = "x$as_lineno_2"
+}])
 
 # _AS_LINENO_PREPARE
 # ------------------
@@ -649,6 +699,7 @@
 # configure.
 m4_define([_AS_LINENO_PREPARE],
 [AS_REQUIRE([_AS_CR_PREPARE])dnl
+AS_DETECT_SUGGESTED([_AS_LINENO_WORKS])
 _AS_LINENO_WORKS || {
 
   # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
@@ -1188,12 +1239,27 @@
 [m4_popdef([$1])])
 
 
-
 ## ----------------- ##
 ## Setting M4sh up.  ##
 ## ----------------- ##
 
 
+# AS_SHELL_FN_SPY
+# ---------------
+# This temporary macro checks "in the wild" for shells that do
+# not support shell functions.
+m4_define([AS_SHELL_FN_SPY],
+[AS_DETECT_SUGGESTED([_AS_SHELL_FN_WORK])
+m4_divert_text([M4SH-INIT], [
+{ $SHELL 2> /dev/null <<\_ASEOF
+_AS_SHELL_FN_WORK
+_ASEOF
+} || {
+  echo No shell found that supports shell functions.
+  echo Please tell address@hidden about your system.
+}])])
+
+
 # AS_INIT(WHAT-IF-SHELL-FUNCTIONS-DO-NOT-WORK)
 # --------------------------------------------
 # The parameter is temporary; it will go away and you
@@ -1206,26 +1272,10 @@
 
 # Bangshe and minimal initialization.
 m4_divert_text([BINSH], address@hidden:@! /bin/sh])
-m4_divert_text([M4SH-INIT], [AS_SHELL_SANITIZE([m4_default([$1], [
-echo Found no shell that has working shell functions.
-echo
-echo Please tell address@hidden about your system.
-])])])
+m4_divert_text([M4SH-SANITIZE], [AS_SHELL_SANITIZE])
+AS_SHELL_FN_SPY
 
 # Let's go!
 m4_wrap([m4_divert_pop([BODY])[]])
 m4_divert_push([BODY])[]dnl
 ])
-
-# AS_INIT_WITH_SHELL_FN
-# ---------------------
-# Same as AS_INIT, but exit if shell functions are
-# not supported.
-m4_define([AS_INIT_WITH_SHELL_FN],
-[AS_INIT([
-echo Shell functions are not supported on any shell I could find 
-echo on your system.  This script requires shell functions: please
-echo install a modern shell, or manually run the script under such
-echo a shell if you do have one.
-AS_EXIT(1)
-])])

reply via email to

[Prev in Thread] Current Thread [Next in Thread]