summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-03-13 14:50:50 -0400
committerZack Weinberg <zackw@panix.com>2020-03-13 14:50:50 -0400
commit8a09003664733eb6bef031f56ef9cd575e403023 (patch)
tree4c56c2d4a963fcb7f37b0ccbbceefa8462ff82c8
parentb2e4b6333785aa55814bfd8f8747a9ce948fa88e (diff)
downloadautoconf-8a09003664733eb6bef031f56ef9cd575e403023.tar.gz
Define $as_echo and $as_echo_n for backward compatibility.
Commit 2b59b6f8a79b8bf77e178ff4e5aa0ede433d39cf removed the internal shell variables $as_echo and $as_echo_n. It turns out that these are used by several widely-used third-party m4 files (notably both gnulib-common.m4 from gnulib, and ax_pthread.m4 from the Autoconf macro archive) as well as any number of existing configure.ac’s. Restore these shell variables, unconditionally defining them to use printf. Issue -Wobsolete warnings if they are used, recommending the use of AS_ECHO and AS_ECHO_N respectively. Add a test which checks both that they do work and that they trigger warnings.
-rw-r--r--NEWS6
-rw-r--r--lib/m4sugar/m4sh.m428
-rw-r--r--tests/m4sh.at74
3 files changed, 103 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 24aec0f6..3cb2876d 100644
--- a/NEWS
+++ b/NEWS
@@ -17,9 +17,13 @@ GNU Autoconf NEWS - User visible changes.
by autoreconf.
** Use of printf is now recommended instead of working around bugs in
- echo. Macros AS_ECHO and AS_ECHO_N now expand unconditionally to
+ echo. The macros AS_ECHO and AS_ECHO_N now expand unconditionally to
'printf "%s\n"' and 'printf %s'.
+** Use of the undocumented internal shell variables $as_echo and
+ $as_echo_n now elicits a warning in the 'obsolete' category.
+ The macros AS_ECHO and AS_ECHO_N should be used instead.
+
** AC_CHECK_HEADER and AC_CHECK_HEADERS now default to doing only a
compilation test. This completes the transition from preprocessor-
based header tests begun in Autoconf 2.56.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 4af31517..af286857 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -813,8 +813,11 @@ m4_defun_init([_AS_ECHO_LOG],
# in a command substitution prints only the first character of the output
# with ksh version M-11/16/88f on AIX 6.1; it needs to be reset by another
# backquoted echo.
-m4_defun([_AS_ECHO_N_PREPARE],
-[ECHO_C= ECHO_N= ECHO_T=
+m4_defun([_AS_ECHO_N_PREPARE], [
+# Determine whether it's possible to make 'echo' print without a newline.
+# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
+# for compatibility with existing Makefiles.
+ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in @%:@(((((
-n*)
case `echo 'xy\c'` in
@@ -826,6 +829,13 @@ case `echo -n x` in @%:@(((((
*)
ECHO_N='-n';;
esac
+
+# For backward compatibility with old third-party macros, we provide
+# the shell variables $as_echo and $as_echo_n. New code should use
+# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
+dnl The @&t@ prevents a spurious deprecation diagnostic.
+as_@&t@echo='printf %s\n'
+as_@&t@echo_n='printf %s'
])# _AS_ECHO_N_PREPARE
@@ -1032,16 +1042,26 @@ fi
# Output WORD followed by a newline. WORD must be a single shell word
# (typically a quoted string). The bytes of WORD are output as-is, even
# if it starts with "-" or contains "\".
-m4_defun([AS_ECHO],
+m4_define([AS_ECHO],
[printf "%s\n" $1])
+# Deprecation warning for the former internal shell variable $as_echo.
+m4_define([as_echo],
+[m4_warn([obsolete],
+ [$as_echo is obsolete; use AS_ECHO(["message"]) instead])as_@&t@echo])
+
# AS_ECHO_N(WORD)
# ---------------
# Like AS_ECHO(WORD), except do not output the trailing newline.
-m4_defun([AS_ECHO_N],
+m4_define([AS_ECHO_N],
[printf %s $1])
+# Deprecation warning for the former internal shell variable $as_echo_n.
+m4_define([as_echo_n],
+[m4_warn([obsolete],
+ [$as_echo_n is obsolete; use AS_ECHO_N(["message"]) instead])as_@&t@echo_n])
+
# AS_TEST_X
# ---------
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 16a0f168..9fd84558 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -557,6 +557,80 @@ AT_CHECK([$CONFIG_SHELL ./script])
AT_CLEANUP
+# Obsolete shell variables with the same functionality as above.
+AT_SETUP([obsolete $as@&t@_echo and $as@&t@_echo_n])
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+AS_REQUIRE([_AS_ECHO_N_PREPARE])
+
+m4_define([ECHO_TEST],
+[echo=`$as_echo '$1'`
+test "X$echo" = 'X$1' ||
+ echo "\$as@&t@_echo '$1' outputs '$echo'" >&2
+
+echo=`$as_echo_n '$1'`
+test "X$echo" = 'X$1' ||
+ echo "\$as@&t@_echo_n '$1' outputs '$echo'" >&2])
+
+ECHO_TEST([-])
+ECHO_TEST([--])
+ECHO_TEST([---...---])
+ECHO_TEST([ ])
+ECHO_TEST([-e])
+ECHO_TEST([-E])
+ECHO_TEST([-n])
+ECHO_TEST([-n -n])
+ECHO_TEST([-e -n])
+ECHO_TEST([ab\ncd])
+ECHO_TEST([abcd\c])
+ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
+ECHO_TEST([ab
+cd
+e])
+ECHO_TEST([
+ ])
+ECHO_TEST([
+\c])
+AS_EXIT(0)
+]])
+
+AT_CHECK_M4SH([-Wobsolete], 0, [],
+[[script.as:13: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:13: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:14: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:14: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:15: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:15: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:16: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:16: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:17: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:17: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:18: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:18: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:19: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:19: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:20: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:20: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:21: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:21: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:22: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:22: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:23: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:23: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:24: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:24: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:25: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:25: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:28: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:28: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+script.as:30: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
+script.as:30: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
+]])
+AT_CHECK([$CONFIG_SHELL ./script])
+
+AT_CLEANUP
## ----------------- ##