From: Eric Blake Date: Thu, 30 Oct 2008 12:56:44 +0000 (-0600) Subject: Work around Solaris /bin/sh case bug. X-Git-Tag: v2.63b~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a78b49741374d1f4f18fc6f19158c346caad36cf;p=thirdparty%2Fautoconf.git Work around Solaris /bin/sh case bug. * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT): Always provide a non-empty command list. (AS_CASE): Always guarantee that a case will match. * doc/autoconf.texi (Limitations of Builtins) : Document the Solaris bug, and mention AS_CASE. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 8d2cd2596..e19a3f601 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-10-30 Eric Blake + + Work around Solaris /bin/sh case bug. + * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT): Always provide + a non-empty command list. + (AS_CASE): Always guarantee that a case will match. + * doc/autoconf.texi (Limitations of Builtins) : Document the + Solaris bug, and mention AS_CASE. + 2008-10-30 Paolo Bonzini Require _AS_CR_PREPARE where appropriate. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 1a2f748ff..d2997ef15 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -14842,6 +14842,19 @@ ash-0.3.8 $ @kbd{case foo in esac;} @error{}Syntax error: ";" unexpected (expecting ")") @end example +Posix requires @command{case} to give an exit status of 0 if no cases +match. However, @command{/bin/sh} in Solaris 10 does not obey this +rule. Meanwhile, it is unclear whether a case that matches, but +contains no statements, must also change the exit status to 0. The M4sh +macro @code{AS_CASE} works around these inconsistencies. + +@example +$ @kbd{bash -c 'case `false` in ?) ;; esac; echo $?'} +0 +$ @kbd{/bin/sh -c 'case `false` in ?) ;; esac; echo $?'} +255 +@end example + @item @command{cd} @c --------------- diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index a67c30d51..1f1f5999d 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -492,16 +492,19 @@ _AS_UNSET_PREPARE # | *) DEFAULT ;; # | esac # The shell comments are intentional, to work around people who don't -# realize the impacts of using insufficient m4 quoting. +# realize the impacts of using insufficient m4 quoting. This macro +# always provides a default case, to work around a Solaris /bin/sh +# bug regarding the exit status when no case matches. m4_define([_AS_CASE], [ [@%:@(] - $1[)] $2 ;;]) + $1[)] m4_default([$2], [:]) ;;]) m4_define([_AS_CASE_DEFAULT], [ [@%:@(] - *[)] $1 ;;]) + *[)] m4_default([$1], [:]) ;;]) m4_defun([AS_CASE], -[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT], m4_shift($@)) +[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT], + m4_shift($@m4_if(m4_eval([$# & 1]), [1], [,]))) esac])# AS_CASE