autoconf-patches
[Top][All Lists]
Advanced

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

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


From: Ralf Wildenhues
Subject: AS_CASE (was: call AC_DISABLE_SHARED "conditionally" for a certain host)
Date: Tue, 14 Feb 2006 23:46:27 +0100
User-agent: Mutt/1.5.9i

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
--- NEWS        31 Jan 2006 12:07:40 -0000      1.351
+++ NEWS        14 Feb 2006 22:45:45 -0000
@@ -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 -0000      1.946
+++ doc/autoconf.texi   14 Feb 2006 22:45:53 -0000
@@ -9000,6 +9000,13 @@
 implementation-specific actions.
 @end defmac
 
address@hidden AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, 
@dots{}, @ovar{default})
address@hidden
+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.
address@hidden 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
 
address@hidden AS_IF (@var{test}, @ovar{RUN-IF-TRUE}, @ovar{RUN-IF-FALSE})
address@hidden AS_IF (@var{test}, @ovar{run-if-true}, @ovar{run-if-false})
 @asindex{IF}
-Run shell code address@hidden  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 -0000      1.158
+++ lib/m4sugar/m4sh.m4 14 Feb 2006 22:45:53 -0000
@@ -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 -0000      1.43
+++ tests/m4sh.at       14 Feb 2006 22:45:53 -0000
@@ -533,3 +533,36 @@
 ]])
 
 AT_CLEANUP
+
+
+## ------------------- ##
+## AS_IF and AS_CASE.  ##
+## ------------------- ##
+
+AT_SETUP([AS@&address@hidden and AS@&address@hidden)
+
+AT_DATA_M4SH([script.as], [[dnl
+AS_INIT
+# Syntax checks: cope with empty arguments.
+AS_IF([:], [], [echo wrong])
+AS_IF([:], [:], [echo wrong])
+AS_IF([false], [echo wrong], [:])
+AS_IF([false], [echo wrong])
+AS_CASE([foo])
+AS_CASE([foo], [:])
+AS_CASE([foo],
+        [foo], [:],
+        [echo wrong])
+AS_CASE([foo],
+        [foo], [:],
+        [*],   [echo wrong])
+AS_CASE([foo],
+        [bar], [echo wrong],
+        [foo], [:],
+        [*],   [echo wrong])
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP




reply via email to

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