AS_CASE (was: call AC_DISABLE_SHARED conditionally for a certain host)

2006-02-14 Thread Ralf Wildenhues
Playing the ball back to autoconf-patches..

* Ralf Wildenhues wrote on Tue, Feb 14, 2006 at 03:01:41PM CET:
 This will not work:
*snip*

 because the arguments to LT_INIT are interpreted at m4 time already.
 And this
   case $host in
   foo) LT_INIT([disable-shared]) ;;
   *)   LT_INIT ;;
   esac
 
 will cause *major* breakage (thanks to AC_REQUIRE).  :-/

 Another lesson learned: There should be an AS_CASE.

OK to apply this patch?

Cheers,
Ralf

* lib/m4sugar/m4sh.m4 (AS_CASE): New macro.
(_AS_CASE): Private helper macro.
* tests/m4sh.at: Basic tests for AS_IF and AS_CASE.
* doc/autoconf.texi (Programming in M4sh): Document AS_CASE.
Fix syntax of AS_IF description
(Prerequisite Macros): Mention AS_IF and AS_CASE as workarounds
for the AC_REQUIRE mess.
* NEWS: Mention AS_CASE, AS_BOURNE_COMPATIBLE, and
AS_SHELL_SANITIZE.

Index: NEWS
===
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.351
diff -u -r1.351 NEWS
--- NEWS31 Jan 2006 12:07:40 -  1.351
+++ NEWS14 Feb 2006 22:45:45 -
@@ -64,6 +64,9 @@
 ** AS_HELP_STRING
   The macro correctly handles quadrigraphs now.
 
+** AS_BOURNE_COMPATIBLE, AS_SHELL_SANITIZE, AS_CASE
+  These macros are new or published now.
+
 ** AT_COPYRIGHT
   New macro for copyright notices in testsuite files.
 
Index: doc/autoconf.texi
===
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.946
diff -u -r1.946 autoconf.texi
--- doc/autoconf.texi   13 Feb 2006 18:46:04 -  1.946
+++ doc/autoconf.texi   14 Feb 2006 22:45:53 -
@@ -9000,6 +9000,13 @@
 implementation-specific actions.
 @end defmac
 
[EMAIL PROTECTED] AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, 
@dots{}, @ovar{default})
[EMAIL PROTECTED]
+Expand into a shell @samp{case} statement, where @var{word} is matched
+against one or more patterns.  @var{if-matched} is run if the
+corresponding pattern matched @var{word}, else @var{default} is run.
[EMAIL PROTECTED] defmac
+
 @defmac AS_DIRNAME (@var{file-name})
 @asindex{DIRNAME}
 Return the directory portion of @var{file-name}, using the algorithm
@@ -9008,11 +9015,12 @@
 @command{dirname} command.
 @end defmac
 
[EMAIL PROTECTED] AS_IF (@var{test}, @ovar{RUN-IF-TRUE}, @ovar{RUN-IF-FALSE})
[EMAIL PROTECTED] AS_IF (@var{test}, @ovar{run-if-true}, @ovar{run-if-false})
 @asindex{IF}
-Run shell code [EMAIL PROTECTED]  If TEST exits with a zero status then run 
shell code
-RUN-IF-TRUE, else run shell code RUN-IF-FALSE, with simplifications if either
-RUN-IF-TRUE or RUN-IF-FALSE is empty.
+Run shell code @var{test}.  If @var{test} exits with a zero status then
+run shell code @var{run-if-true}, else run shell code @var{run-if-false},
+with simplifications if either @var{run-if-true} or @var{run-if-false}
+is empty.
 @end defmac
 
 @defmac AS_MKDIR_P (@var{file-name})
@@ -9421,9 +9429,11 @@
 @end group
 @end example
 
-
-You are encouraged to put all @code{AC_REQUIRE}s at the beginning of a
-macro.  You can use @code{dnl} to avoid the empty lines they leave.
+The helper macros @code{AS_IF} and @code{AS_CASE} may be used to
+enforce expansion of required macros outside of shell conditional
+constructs.  You are furthermore encouraged to put all @code{AC_REQUIRE}s
+at the beginning of a macro.  You can use @code{dnl} to avoid the empty
+lines they leave.
 
 @node Suggested Ordering
 @subsection Suggested Ordering
Index: lib/m4sugar/m4sh.m4
===
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sh.m4,v
retrieving revision 1.158
diff -u -r1.158 m4sh.m4
--- lib/m4sugar/m4sh.m4 13 Feb 2006 18:46:04 -  1.158
+++ lib/m4sugar/m4sh.m4 14 Feb 2006 22:45:53 -
@@ -460,6 +460,30 @@
 ])# AS_IF
 
 
+# AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])
+# 
+# Expand into
+# | case WORD in
+# | PATTERN1) IF-MATCHED1 ;;
+# | ...
+# | *) DEFAULT ;;
+# | esac
+m4_define([_AS_CASE],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+   [$#], 1, [  *) $1 ;;],
+   [$#], 2, [  $1) m4_default([$2], [:]) ;;],
+   [  $1) m4_default([$2], [:]) ;;
+$0(m4_shiftn(2, $@))])dnl
+])
+m4_defun([AS_CASE],
+[m4_ifval([$2$3],
+[case $1 in
+_AS_CASE(m4_shift($@))
+esac
+])dnl
+])# AS_CASE
+
+
 # _AS_UNSET_PREPARE
 # -
 # AS_UNSET depends upon $as_unset: compute it.
Index: tests/m4sh.at
===
RCS file: /cvsroot/autoconf/autoconf/tests/m4sh.at,v
retrieving revision 1.43
diff -u -r1.43 m4sh.at
--- tests/m4sh.at   11 Jan 2006 08:05:55 -  1.43
+++ tests/m4sh.at   14 Feb 2006 22:45:53 -
@@ -533,3 +533,36 @@
 ]])
 
 AT_CLEANUP
+
+
+## --- ##
+## AS_IF and AS_CASE

Re: AS_CASE

2006-02-14 Thread Paul Eggert
Ralf Wildenhues [EMAIL PROTECTED] writes:

 OK to apply this patch?

Yes, it looks good to me, except please change this:

AT_SETUP([AS@[EMAIL PROTECTED] and AS@[EMAIL PROTECTED])

to this:

AT_SETUP([AS@[EMAIL PROTECTED] and AS@[EMAIL PROTECTED])

Thanks.


___
Bug-libtool mailing list
Bug-libtool@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-libtool


Re: AS_CASE

2006-02-14 Thread Ralf Wildenhues
Hi Paul,

* Paul Eggert wrote on Wed, Feb 15, 2006 at 05:58:59AM CET:
 Ralf Wildenhues [EMAIL PROTECTED] writes:
 
  OK to apply this patch?
 
 Yes, it looks good to me, except please change this:
 
 AT_SETUP([AS@[EMAIL PROTECTED] and AS@[EMAIL PROTECTED])

Changed and installed.  Thanks for the review!

Cheers,
Ralf


___
Bug-libtool mailing list
Bug-libtool@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-libtool