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.
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
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.
exec >&2
AS_ECHO(["$as_me: invalid option $[1]"])
AS_ECHO(["$help"])
- AS_EXIT([1]) ;;
+ AS_EXIT ;;
* )
break ;;
esac
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)
*) 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.
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})
@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}
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
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
[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 = :])
[[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])
]])
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
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