Allow AS_IF in shell lists.

* lib/m4sugar/m4sh.m4 (AS_IF): Always execute test, in case of
side effects.  Allow continuation of script on same line as fi.
(_AS_DETECT_BETTER_SHELL): Adjust clients.
(AS_VAR_IF, AS_VAR_SET_IF): For now, supply newline no longer
given by AS_IF.
* lib/autoconf/c.m4 (_AC_PROG_PREPROC_WORKS_IFELSE): Likewise.
* lib/autoconf/general.m4 (_AC_ENABLE_IF): Likewise.
(AC_EGREP_CPP, _AC_RUN_IFELSE): Adjust client.
* lib/autoconf/libs.m4 (AC_SEARCH_LIBS): Likewise.
* doc/autoconf.texi (Common Shell Constructs) <AS_IF>: Fix typo.
(Polymorphic Variables): Move mention of dnl to the only two
AS_VAR functions that need it.

Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
Eric Blake 2008-10-20 16:18:05 -06:00
parent 6d4ddfda94
commit b837cd019d
7 changed files with 48 additions and 20 deletions

View File

@ -1,3 +1,19 @@
2008-10-21 Eric Blake <ebb9@byu.net>
Allow AS_IF in shell lists.
* lib/m4sugar/m4sh.m4 (AS_IF): Always execute test, in case of
side effects. Allow continuation of script on same line as fi.
(_AS_DETECT_BETTER_SHELL): Adjust clients.
(AS_VAR_IF, AS_VAR_SET_IF): For now, supply newline no longer
given by AS_IF.
* lib/autoconf/c.m4 (_AC_PROG_PREPROC_WORKS_IFELSE): Likewise.
* lib/autoconf/general.m4 (_AC_ENABLE_IF): Likewise.
(AC_EGREP_CPP, _AC_RUN_IFELSE): Adjust client.
* lib/autoconf/libs.m4 (AC_SEARCH_LIBS): Likewise.
* doc/autoconf.texi (Common Shell Constructs) <AS_IF>: Fix typo.
(Polymorphic Variables): Move mention of dnl to the only two
AS_VAR functions that need it.
2008-10-21 Paolo Bonzini <bonzini@gnu.org>
and Eric Blake <ebb9@byu.net>

View File

@ -11952,7 +11952,7 @@ Redirections can be placed outside the macro invocation.
Run shell code @var{test1}. If @var{test1} exits with a zero status then
run shell code @var{run-if-true1}, else examine further tests. If no test
exits with a zero status, run shell code @var{run-if-false}, with
simplifications if either @var{run-if-true1} or @var{run-if-false1}
simplifications if either @var{run-if-true1} or @var{run-if-false}
is empty. For example,
@example
@ -12046,8 +12046,7 @@ M4sh supports the notion of polymorphic shell variables, making it easy
to write a macro that can deal with either literal or indirect variable
names and output shell code appropriate for both use cases. Behavior is
undefined if expansion of an indirect variable does not result in a
literal variable name. These macros are often followed with @code{dnl},
to avoid excess newlines in the output.
literal variable name.
@defmac AS_LITERAL_IF (@var{expression}, @ovar{if-literal}, @ovar{if-not})
@asindex{LITERAL_IF}
@ -12147,7 +12146,8 @@ composed variable name based on @var{value}, it is easier to declare a
temporary m4 macro @var{m4-name} with @code{AS_VAR_PUSHDEF}, then use
that macro as the argument to subsequent @code{AS_VAR} macros as a
polymorphic variable name, and finally free the temporary macro with
@code{AS_VAR_POPDEF}.
@code{AS_VAR_POPDEF}. These macros are often followed with @code{dnl},
to avoid excess newlines in the output.
Here is an involved example, that shows the power of writing macros that
can handle composed shell variable names:

View File

@ -477,7 +477,8 @@ break])
done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.err conftest.$ac_ext
AS_IF([$ac_preproc_ok], [$1], [$2])])# _AC_PROG_PREPROC_WORKS_IFELSE
AS_IF([$ac_preproc_ok], [$1], [$2])
])# _AC_PROG_PREPROC_WORKS_IFELSE
# AC_PROG_CPP

View File

@ -1433,7 +1433,7 @@ m4_define([_m4_divert(HELP_ENABLE)], _m4_divert(HELP_WITH))
#
m4_define([_AC_ENABLE_IF],
[@%:@ Check whether --$1-$2 was given.
_AC_ENABLE_IF_ACTION([$1], m4_translit([$2], [-.], [__]), [$3], [$4])[]dnl
_AC_ENABLE_IF_ACTION([$1], m4_translit([$2], [-.], [__]), [$3], [$4])
])
m4_define([_AC_ENABLE_IF_ACTION],
@ -2446,7 +2446,7 @@ dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
dnl Quote $1 to prevent m4 from eating character classes
$EGREP "[$1]" >/dev/null 2>&1],
[$3],
[$4])dnl
[$4])
rm -f conftest*
])# AC_EGREP_CPP
@ -2605,7 +2605,7 @@ AS_IF([_AC_DO_VAR(ac_link) && _AC_DO_TOKENS(./conftest$ac_exeext)],
_AC_MSG_LOG_CONFTEST
m4_ifvaln([$3],
[( exit $ac_status )
$3])dnl])[]dnl
$3])dnl])
rm -rf conftest.dSYM
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext m4_ifval([$1],
[conftest.$ac_ext])[]dnl

View File

@ -88,7 +88,7 @@ AS_VAR_COPY([ac_res], [ac_Search])
AS_IF([test "$ac_res" != no],
[test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
$3],
[$4])dnl
[$4])
AS_VAR_POPDEF([ac_Search])dnl
])

View File

@ -241,8 +241,7 @@ dnl Remove any tests from suggested that are also required
echo shells that I found on your system. Please install a
echo modern shell, or manually run the script under such a
echo shell if you do have one.
AS_EXIT(1)])
])
AS_EXIT(1)])])
fi
])# _AS_DETECT_BETTER_SHELL
@ -521,8 +520,8 @@ m4_define([AS_EXIT],
[{ (exit m4_default([$1], 1)); exit m4_default([$1], 1); }])
# AS_IF(TEST1, [IF-TRUE1]...[IF-FALSE])
# -------------------------------------
# AS_IF(TEST1, [IF-TRUE1 = :]...[IF-FALSE = :])
# ---------------------------------------------
# Expand into
# | if TEST1; then
# | IF-TRUE1
@ -543,13 +542,10 @@ m4_define([_AS_IF_ELSE],
[else
$1])])
m4_defun([AS_IF],
[m4_ifval([$2$3],
[if $1; then
m4_default([$2], [:])
m4_map_args_pair([_$0], [_$0_ELSE], m4_shift2($@))dnl
fi
])dnl
])# AS_IF
fi])# AS_IF
# _AS_UNSET_PREPARE
@ -1715,7 +1711,9 @@ m4_define([AS_VAR_IF],
[AS_LITERAL_IF([$1],
[AS_IF([test "x$$1" = x""$2], [$3], [$4])],
[AS_VAR_COPY([as_val], [$1])
AS_IF([test "x$as_val" = x""$2], [$3], [$4])])])
AS_IF([test "x$as_val" = x""$2], [$3], [$4])])
dnl fixme: remove the newline?
])
# AS_VAR_PUSHDEF and AS_VAR_POPDEF
@ -1785,13 +1783,15 @@ m4_define([AS_VAR_SET],
# Implement a shell `if-then-else' depending whether VARIABLE is set
# or not. Polymorphic.
m4_define([AS_VAR_SET_IF],
[AS_IF([AS_VAR_TEST_SET([$1])], [$2], [$3])])
[AS_IF([AS_VAR_TEST_SET([$1])], [$2], [$3])
dnl fixme: remove the newline?
])
# AS_VAR_TEST_SET(VARIABLE)
# -------------------------
# Expands into the `test' expression which is true if VARIABLE
# is set. Polymorphic. Should be dnl'ed.
# is set. Polymorphic.
m4_define([AS_VAR_TEST_SET],
[AS_LITERAL_IF([$1],
[test "${$1+set}" = set],

View File

@ -799,6 +799,13 @@ AS_CASE([foo],
[foo], [echo ten],
[*], [echo wrong])
# check for nesting, lists, and side effects
empty=
AS_IF([AS_IF([$empty], [echo eleven])]) && echo twelve
rm -f file
AS_IF([touch file; false]) && echo thirteen
test -f file && echo fourteen
# check that require works correctly
m4_for([n], 1, 9, [],
[m4_defun([FOO]n, [foo]n[=]n)dnl
@ -844,6 +851,10 @@ seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
foo1=1 bar1=1
foo2=2 bar2=
foo3=3 bar3=