autoconf-patches
[Top][All Lists]
Advanced

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

21-fyi-as-require.patch


From: Akim Demaille
Subject: 21-fyi-as-require.patch
Date: Mon, 08 Oct 2001 10:29:42 +0200

The goal is to have M4sh initializations issued in their own section,
as demonstrated in the example of AS_REQUIRE below:

      m4_defun([_FOO_PREPARE], [foo=foo])
      m4_defun([FOO],
      [m4_require([_FOO_PREPARE])dnl
      echo $foo])

      m4_defun([_BAR_PREPARE], [bar=bar])
      m4_defun([BAR],
      [AS_REQUIRE([_BAR_PREPARE])dnl
      echo $bar])

      AS_INIT
      foo1=`FOO`
      foo2=`FOO`
      bar1=`BAR`
      bar2=`BAR`

 gives

      #! /bin/sh
      bar=bar

      foo1=`foo=foo
      echo $foo`
      foo2=`echo $foo`
      bar1=`echo $bar`
      bar2=`echo $bar`

because currently:

/tmp % cat foo.as                                                    Err 1 remo
AS_INIT
foo=`AS_DIRNAME_EXPR(foo)`
/tmp % autom4te -l m4sh foo.as                                       16:27 remo
#! /bin/sh

foo=`if expr a : '\(a\)' >/dev/null 2>&1; then
  as_expr=expr
else
  as_expr=false
fi

$as_expr Xfoo : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
         Xfoo : 'X\(//\)[^/]' \| \
         Xfoo : 'X\(//\)$' \| \
         Xfoo : 'X\(/\)' \| \
         .     : '\(.\)'`


(note that it is not only cosmetics: being set in backquotes, as_expr
is *not* defined in the top level of the shell script).

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * lib/m4sugar/m4sugar.m4 (m4_provide_ifelse): Rename as...
        (m4_provide_if): this.
        * lib/m4sugar/m4sh.m4 (AS_REQUIRE): New.
        * lib/autoconf/general.m4 (AS_DEFUN, AC_DEFUN_ONCE, AC_BEFORE)
        (AC_REQUIRE, AC_PROVIDE, AC_PROVIDE_IFELSE): Be exact copy of the
        M4sugar peer, i.e., drop the `AC_PROVIDE_$1' broken marker.

Index: lib/autoconf/general.m4
--- lib/autoconf/general.m4 Sun, 07 Oct 2001 14:11:51 +0200 akim
+++ lib/autoconf/general.m4 Sun, 07 Oct 2001 16:14:38 +0200 akim
@@ -157,76 +157,31 @@ m4_define([_m4_divert(INIT_PREPARE)],
 m4_copy([m4_divert_pop], [AC_DIVERT_POP])


-## ------------------------------- ##
-## Defining macros in autoconf::.  ##
-## ------------------------------- ##

-
-# AC_DEFUN(NAME, EXPANSION)
-# -------------------------
-# Same as `m4_define' but equip the macro with the needed machinery
-# for `AC_REQUIRE'.
-#
-# We don't use this macro to define some frequently called macros that
-# are not involved in ordering constraints, to save m4 processing.
-m4_define([AC_DEFUN],
-[m4_defun([$1], [$2[]AC_PROVIDE([$1])])])
+## ------------------------------------ ##
+## Defining/requiring Autoconf macros.  ##
+## ------------------------------------ ##


+# AC_DEFUN(NAME, EXPANSION)
 # AC_DEFUN_ONCE(NAME, EXPANSION)
-# ------------------------------
-# As AC_DEFUN, but issues the EXPANSION only once, and warns if used
-# several times.
-m4_define([AC_DEFUN_ONCE],
-[m4_defun_once([$1], [$2[]AC_PROVIDE([$1])])])
+# AC_BEFORE(THIS-MACRO-NAME, CALLED-MACRO-NAME)
+# AC_REQUIRE(STRING)
+# AC_PROVIDE(MACRO-NAME)
+# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
+# -----------------------------------------------------------
+m4_copy([m4_defun],       [AC_DEFUN])
+m4_copy([m4_defun_once],  [AC_DEFUN_ONCE])
+m4_copy([m4_before],      [AC_BEFORE])
+m4_copy([m4_require],     [AC_REQUIRE])
+m4_copy([m4_provide],     [AC_PROVIDE])
+m4_copy([m4_provide_if],  [AC_PROVIDE_IFELSE])


 # AC_OBSOLETE(THIS-MACRO-NAME, [SUGGESTION])
 # ------------------------------------------
 m4_define([AC_OBSOLETE],
 [AC_DIAGNOSE([obsolete], [$1 is obsolete$2])])
-
-
-
-
-
-
-## ----------------------------- ##
-## Dependencies between macros.  ##
-## ----------------------------- ##
-
-
-# AC_BEFORE(THIS-MACRO-NAME, CALLED-MACRO-NAME)
-# ---------------------------------------------
-m4_define([AC_BEFORE],
-[AC_PROVIDE_IFELSE([$2], [AC_DIAGNOSE([syntax], [$2 was called before $1])])])
-
-
-# AC_REQUIRE(STRING)
-# ------------------
-# If STRING has never been AC_PROVIDE'd, then expand it. A macro must
-# be AC_DEFUN'd if either it is AC_REQUIRE'd, or it AC_REQUIRE's.
-m4_copy([m4_require], [AC_REQUIRE])
-
-
-# AC_PROVIDE(MACRO-NAME)
-# ----------------------
-# Ideally we should just use `m4_provide($1)', but unfortunately many
-# third party macros know that we use `AC_PROVIDE_$1' and they depend
-# on it.
-m4_define([AC_PROVIDE],
-[m4_define([AC_PROVIDE_$1])m4_provide([$1])])
-
-
-# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
-# -----------------------------------------------------------
-# If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED.
-# The purpose of this macro is to provide the user with a means to
-# check macros which are provided without letting her know how the
-# information is coded.
-m4_define([AC_PROVIDE_IFELSE],
-[m4_ifdef([AC_PROVIDE_$1],
-          [$2], [$3])])



Index: lib/m4sugar/m4sh.m4
--- lib/m4sugar/m4sh.m4 Sun, 07 Oct 2001 14:20:55 +0200 akim
+++ lib/m4sugar/m4sh.m4 Sun, 07 Oct 2001 16:17:19 +0200 akim
@@ -96,6 +96,43 @@ m4_define([_m4_divert(BODY)],
 ## ------------------------- ##


+# AS_REQUIRE(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
+# -----------------------------------------------------------
+# BODY-TO-EXPAND is some initialization which must be expanded in the
+# M4SH-INIT section when expanded (required or not).  For instance:
+#
+#      m4_defun([_FOO_PREPARE], [foo=foo])
+#      m4_defun([FOO],
+#      [m4_require([_FOO_PREPARE])dnl
+#      echo $foo])
+#
+#      m4_defun([_BAR_PREPARE], [bar=bar])
+#      m4_defun([BAR],
+#      [AS_REQUIRE([_BAR_PREPARE])dnl
+#      echo $bar])
+#
+#      AS_INIT
+#      foo1=`FOO`
+#      foo2=`FOO`
+#      bar1=`BAR`
+#      bar2=`BAR`
+#
+# gives
+#
+#      #! /bin/sh
+#      bar=bar
+#
+#      foo1=`foo=foo
+#      echo $foo`
+#      foo2=`echo $foo`
+#      bar1=`echo $bar`
+#      bar2=`echo $bar`
+#
+m4_define([AS_REQUIRE],
+[m4_provide_if([$1], [],
+               [m4_divert_text([M4SH-INIT], [$1])])])
+
+
 # AS_SHELL_SANITIZE
 # -----------------
 # Try to be as Bourne and/or POSIX as possible.
Index: lib/m4sugar/m4sugar.m4
--- lib/m4sugar/m4sugar.m4 Sun, 16 Sep 2001 15:14:29 +0200 akim
+++ lib/m4sugar/m4sugar.m4 Sun, 07 Oct 2001 16:08:50 +0200 akim
@@ -1193,9 +1193,9 @@ m4_define([$1],
 m4_define([m4_defun_once],
 [m4_define([m4_location($1)], m4_location)dnl
 m4_define([$1],
-          [m4_provide_ifelse([$1],
-                             [m4_warn([syntax], [$1 invoked multiple times])],
-                             [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])])
+          [m4_provide_if([$1],
+                         [m4_warn([syntax], [$1 invoked multiple times])],
+                         [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])])


 # m4_pattern_forbid(ERE)
@@ -1220,8 +1220,8 @@ m4_define([m4_pattern_allow], [])
 # m4_before(THIS-MACRO-NAME, CALLED-MACRO-NAME)
 # ---------------------------------------------
 m4_define([m4_before],
-[m4_provide_ifelse([$2],
-                   [m4_warn([syntax], [$2 was called before $1])])])
+[m4_provide_if([$2],
+               [m4_warn([syntax], [$2 was called before $1])])])


 # m4_require(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
@@ -1262,17 +1262,17 @@ m4_define([m4_require],
          [m4_fatal([$0: circular dependency of $1])])dnl
 m4_ifndef([_m4_divert_dump],
           [m4_fatal([$0: cannot be used outside of an m4_defun'd macro])])dnl
-m4_provide_ifelse([$1],
-                  [],
-                  [m4_divert_push(m4_eval(m4_divnum - 1))dnl
+m4_provide_if([$1],
+              [],
+              [m4_divert_push(m4_eval(m4_divnum - 1))dnl
 m4_default([$2], [$1])
 m4_divert(m4_defn([_m4_divert_dump]))dnl
 m4_undivert(m4_defn([_m4_divert_diversion]))dnl
 m4_divert_pop(m4_defn([_m4_divert_dump]))])dnl
-m4_provide_ifelse([$1],
-                  [],
-                  [m4_warn([syntax],
-                           [$1 is m4_require'd but is not m4_defun'd])])dnl
+m4_provide_if([$1],
+              [],
+              [m4_warn([syntax],
+                       [$1 is m4_require'd but is not m4_defun'd])])dnl
 m4_expansion_stack_pop()dnl
 ])

@@ -1282,9 +1282,9 @@ m4_define([m4_require],
 # If TEXT has never been expanded, expand it *here*.  Use WITNESS as
 # as a memory that TEXT has already been expanded.
 m4_define([m4_expand_once],
-[m4_provide_ifelse(m4_ifval([$2], [[$2]], [[$1]]),
-                   [],
-                   [m4_provide(m4_ifval([$2], [[$2]], [[$1]]))[]$1])])
+[m4_provide_if(m4_ifval([$2], [[$2]], [[$1]]),
+               [],
+               [m4_provide(m4_ifval([$2], [[$2]], [[$1]]))[]$1])])


 # m4_provide(MACRO-NAME)
@@ -1293,13 +1293,13 @@ m4_define([m4_provide],
 [m4_define([m4_provide($1)])])


-# m4_provide_ifelse(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
-# -----------------------------------------------------------
+# m4_provide_if(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
+# -------------------------------------------------------
 # If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED.
 # The purpose of this macro is to provide the user with a means to
 # check macros which are provided without letting her know how the
 # information is coded.
-m4_define([m4_provide_ifelse],
+m4_define([m4_provide_if],
 [m4_ifdef([m4_provide($1)],
           [$2], [$3])])




reply via email to

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