]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Alter default value of AS_EXIT.
authorEric Blake <ebb9@byu.net>
Wed, 19 Nov 2008 03:58:19 +0000 (20:58 -0700)
committerEric Blake <ebb9@byu.net>
Wed, 19 Nov 2008 04:00:34 +0000 (21:00 -0700)
* lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): Let as_func_exit
parameter be optional.
(AS_EXIT): Use it to make better default.
(_AS_DETECT_BETTER_SHELL): Use new default.
* bin/autoconf.as (exit_missing_arg, getopt): Likewise.
* lib/autoconf/status.m4 (AC_OUTPUT): Likewise.
* tests/m4sh.at (AS@&t@_EXIT): Update test.
* doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Mention
new default behavior.
(Limitations of Builtins) <trap>: Adjust to use new default.
* NEWS: Mention the semantic change.
Suggested by Ralf Wildenhues.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
NEWS
bin/autoconf.as
doc/autoconf.texi
lib/autoconf/status.m4
lib/m4sugar/m4sh.m4
tests/m4sh.at

index a817ee220bcc6fa6aa688ed72c522423cd8a1e21..7ce0fa59df39abb1d869b190818be56c16a566f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2008-11-18  Eric Blake  <ebb9@byu.net>
 
+       Alter default value of AS_EXIT.
+       * lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): Let as_func_exit
+       parameter be optional.
+       (AS_EXIT): Use it to make better default.
+       (_AS_DETECT_BETTER_SHELL): Use new default.
+       * bin/autoconf.as (exit_missing_arg, getopt): Likewise.
+       * lib/autoconf/status.m4 (AC_OUTPUT): Likewise.
+       * tests/m4sh.at (AS@&t@_EXIT): Update test.
+       * doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Mention
+       new default behavior.
+       (Limitations of Builtins) <trap>: Adjust to use new default.
+       * NEWS: Mention the semantic change.
+       Suggested by Ralf Wildenhues.
+
        Update example to match actual Tru64 behavior.
        * doc/autoconf.texi (Limitations of Builtins) <trap>: Correct
        the example.
diff --git a/NEWS b/NEWS
index b67d82ce607a808b1ba870438f7ff0cf6f102f7f..6ef072591c1ca5518144a4b809495d2cba5e87c2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,7 +33,9 @@ GNU Autoconf NEWS - User visible changes.
    AS_LINENO_PREPARE  AS_ME_PREPARE  AS_SET_STATUS  AS_VAR_APPEND
    AS_VAR_ARITH  AS_VAR_COPY
 
-** The following m4sh macros are documented now:
+** The following m4sh macros are documented now, but in some cases
+   with slightly different semantics than what the previous
+   undocumented version had:
    AS_ECHO  AS_ECHO_N  AS_EXIT  AS_LITERAL_IF  AS_UNSET  AS_VAR_IF
    AS_VAR_POPDEF  AS_VAR_PUSHDEF  AS_VAR_SET  AS_VAR_SET_IF
    AS_VAR_TEST_SET  AS_VERSION_COMPARE
index c678e55ae0a822b6fd109af9c47895cdbf0cd812..c6bb0f653a4c95fcf452c4d8e2f70250dd31a27e 100644 (file)
@@ -81,7 +81,7 @@ Try \`$as_me --help' for more information."
 exit_missing_arg='
   AS_ECHO(["$as_me: option \`$[1]'\'' requires an argument"]) >&2
   AS_ECHO(["$help"]) >&2
-  AS_EXIT([1])
+  AS_EXIT
 ' # restore font-lock: "
 
 # Variables.
@@ -156,7 +156,7 @@ while test $# -gt 0 ; do
        exec >&2
        AS_ECHO(["$as_me: invalid option $[1]"])
        AS_ECHO(["$help"])
-       AS_EXIT([1]) ;;
+       AS_EXIT ;;
     * )
        break ;;
   esac
@@ -175,7 +175,7 @@ case $# in
       infile=configure.in
     else
       AS_ECHO(["$as_me: no input file"]) >&2
-      AS_EXIT([1])
+      AS_EXIT
     fi
     test -z "$traces" && test -z "$outfile" && outfile=configure;;
   1)
@@ -183,7 +183,7 @@ case $# in
   *) exec >&2
      AS_ECHO(["$as_me: invalid number of arguments."])
      AS_ECHO(["$help"])
-     AS_EXIT([1]) ;;
+     AS_EXIT ;;
 esac
 
 # Unless specified, the output is stdout.
index 3cc165bb68e3f07ad0371c3fe4e5cd20d41ee122..0382412d47bd55a7480984405309e2afe03a99d2 100644 (file)
@@ -12010,12 +12010,15 @@ for portability, should not include more than one newline.  The bytes of
 Redirections can be placed outside the macro invocation.
 @end defmac
 
-@defmac AS_EXIT (@dvar{status, 1})
+@defmac AS_EXIT (@dvar{status, max($?/1)})
 @asindex{EXIT}
-Emit code to exit the shell with @var{status}.  This works around shells
-that see the exit status of the command prior to @code{exit} inside a
-@samp{trap 0} handler (@pxref{Limitations of Builtins, , Limitations of
-Shell Builtins}).
+Emit code to exit the shell with @var{status}.  If @var{status} is
+omitted, then @samp{$?} is used, except that a status of zero is
+converted to @samp{1}.  To exit with successful status, it is necessary
+to supply an explicit @var{status} that expands to @samp{0}.  This macro
+works around shells that see the exit status of the command prior to
+@code{exit} inside a @samp{trap 0} handler (@pxref{Limitations of
+Builtins, , Limitations of Shell Builtins}).
 @end defmac
 
 @defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
@@ -15447,7 +15450,7 @@ $ @kbd{sh -c 'set -e; trap '\''echo $?'\'' 0; false'}
 
 @noindent
 Thus, when writing a script in M4sh, rather than trying to rely on
-@samp{set -e}, it is better to append @samp{|| AS_EXIT([$?])} to any
+@samp{set -e}, it is better to append @samp{|| AS_EXIT} to any
 statement where it is desirable to abort on failure.
 
 @item @command{shift}
index c134bb7b5ac109b0556ff03e6f126ac1632db081..fe7835832c297340dc64ff658cfe9b9f3b879291 100644 (file)
@@ -1307,7 +1307,7 @@ if test "$no_create" != yes; then
   exec AS_MESSAGE_LOG_FD>>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_EXIT([1])
+  $ac_cs_success || AS_EXIT
 fi
 dnl config.status should not do recursion.
 AC_PROVIDE_IFELSE([AC_CONFIG_SUBDIRS], [_AC_OUTPUT_SUBDIRS()])dnl
index f056ee315ccf80d73a6b4d1fe0306c75ac2e4dae..c8001081f810f95b6abec2873f007ca10b9ec0cd 100644 (file)
@@ -270,7 +270,7 @@ _m4_defn([AC_PACKAGE_BUGREPORT]), [], [and _m4_defn([AC_PACKAGE_BUGREPORT])])])
 Then install a modern shell, or manually run the script under such a
 shell if you do have one.], [$[]0: ], [], [62])")
   fi
-      AS_EXIT(1)])])
+  AS_EXIT])])
 fi
 SHELL=${CONFIG_SHELL-/bin/sh}
 export SHELL
@@ -539,19 +539,23 @@ m4_defun([_AS_EXIT_PREPARE],
   [AS_FUNCTION_DESCRIBE([as_func_set_status], [STATUS],
     [Set $? to STATUS, without forking.])], [  return $[]1])]dnl
 [AS_REQUIRE_SHELL_FN([as_func_exit],
-  [AS_FUNCTION_DESCRIBE([as_func_exit], [STATUS],
-    [Exit the shell with STATUS, even in a "trap 0" or "set -e" context.])],
-[  set +e
-  as_func_set_status $[]1
-  exit $[]1])])#_AS_EXIT_PREPARE
+  [AS_FUNCTION_DESCRIBE([as_func_exit], [[[STATUS]]],
+    [Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+     If STATUS is omitted, use the maximum of $? and 1.])],
+[  as_status=$?
+  set +e
+  test $as_status = 0 && as_status=1
+  as_func_set_status ${1-$as_status}
+  exit ${1-$as_status}])])#_AS_EXIT_PREPARE
 
 
-# AS_EXIT([EXIT-CODE = 1])
-# ------------------------
+# AS_EXIT([EXIT-CODE = $?/1])
+# ---------------------------
 # Exit, with status set to EXIT-CODE in the way that it's seen
-# within "trap 0", and without interference from "set -e".
+# within "trap 0", and without interference from "set -e".  If
+# EXIT-CODE is omitted, then use $?, except use 1 if $? is 0.
 m4_defun([AS_EXIT],
-[AS_REQUIRE([_AS_EXIT_PREPARE])[]as_func_exit m4_default([$1], 1)])
+[AS_REQUIRE([_AS_EXIT_PREPARE])[]as_func_exit[]m4_ifval([$1], [ $1])])
 
 
 # AS_FOR(MACRO, SHELL-VAR, [LIST = "$@"], [BODY = :])
index 85ad5d8b1cbfd997357fd79bdd097f317bcb229c..1f39bb10cfd067d372c898965da2cfc9461048bb 100644 (file)
@@ -305,11 +305,12 @@ AT_DATA_M4SH([script.as],
 [[AS_INIT
 test x${1} = xa && AS_EXIT
 test x${1} = xb && AS_EXIT([${2}])
-test x${1} = xc && trap 's=$?; echo $s; AS_EXIT([$s])' 0
-test x${2} = xd && set -e
+test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
+test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
+test x${2} = xe && set -e
 AS_SET_STATUS([3])
 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
-test x${2} = xd \
+test x${2} = xe \
   && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
 AS_SET_STATUS([4])
 ]])
@@ -317,9 +318,12 @@ AS_SET_STATUS([4])
 AT_CHECK_M4SH
 AT_CHECK([./script], [4])
 AT_CHECK([./script a], [1])
-AT_CHECK([./script b], [0])
+AT_CHECK([./script b], [1])
+AT_CHECK([./script b 0], [0])
 AT_CHECK([./script b 2], [2])
-AT_CHECK([./script c], [4], [[4
+AT_CHECK([./script c 0], [1])
+AT_CHECK([./script c 2], [2])
+AT_CHECK([./script d], [4], [[4
 ]])
 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
 dnl The rest of this test relies on semi-decent 'set -e' support, even
@@ -327,8 +331,8 @@ dnl though m4sh in general should not try to rely on it because of
 dnl portability nightmares on what constructs are considered errors across
 dnl various shells; therefore, an overall SKIP result is desirable on
 dnl broken shells like Solaris /bin/sh.
-AT_CHECK([./script '' d], [3])
-AT_CHECK([./script c d], [3], [[3
+AT_CHECK([./script '' e], [3])
+AT_CHECK([./script d e], [3], [[3
 ]])
 
 AT_CLEANUP