+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>
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
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}
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:
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
#
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],
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
_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
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
])
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
[{ (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
[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
[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
# 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],
[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
eight
nine
ten
+eleven
+twelve
+thirteen
+fourteen
foo1=1 bar1=1
foo2=2 bar2=
foo3=3 bar3=