bootstrap: adopt autoconf echo normalization code.

Dash shipped with Ubutu-11.10 as /bin/sh, among others, still
has a crippled echo builtin that mis-handles backslashes.
* build-aux/options-parser (bs_echo): Adopt the autoconf echo
normalization code to find a suitable replacement for buggy echo
commands.
Adjust all uses of echo to $bs_echo.
* build-aux/extract-trace (func_extract_trace, func_main):
Likewise.
* bootstrap: To retain some execution speed on platforms with
buggy builtin echo, replace most occurrences of `echo' with
`$bs_echo' - except where its arguments will obviously never
contain backslashes or be overly long.
Reported by Reuben Thomas.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
This commit is contained in:
Gary V. Vaughan 2011-12-18 14:32:40 +07:00
parent 4099c121a1
commit 51c1877e70
3 changed files with 64 additions and 24 deletions

View File

@ -1051,7 +1051,7 @@ func_require_buildreq_automake ()
# ...and AM_INIT_AUTOMAKE is declared...
test -n "$func_extract_trace_result" && {
automake_version=`echo "$func_extract_trace_result" \
automake_version=`$bs_echo "$func_extract_trace_result" \
|$SED 's|[^0-9]*||; s| .*$||'`
test -n "$automake_version" || automake_version=-
@ -1798,8 +1798,8 @@ func_ifcontains ()
{
$debug_cmd
# The embedded echo is to squase whitespace before globbing.
_G_wslist=`echo " "$1" "`
# The embedded echo is to squash whitespace before globbing.
_G_wslist=`$bs_echo " "$1" "`
_G_member=$2
_G_yes_cmd=$3
_G_no_cmd=${4-":"}
@ -1833,7 +1833,7 @@ func_append_u ()
{
$debug_cmd
eval _G_current_value='`echo $'$1'`'
eval _G_current_value='`$bs_echo $'$1'`'
_G_delim=`expr "$2" : '\(.\)'`
case $_G_delim$_G_current_value$_G_delim in
@ -1851,7 +1851,7 @@ func_strpad ()
$debug_cmd
_G_width=`expr "$2" - 1`
func_strpad_result=`echo "$1" |$SED '
func_strpad_result=`$bs_echo "$1" |$SED '
:a
s|^.\{0,'"$_G_width"'\}$|&'"$3"'|
ta
@ -1868,7 +1868,7 @@ func_strrpad ()
$debug_cmd
_G_width=`expr "$2" - 1`
func_strrpad_result=`echo "$1" |$SED '
func_strrpad_result=`$bs_echo "$1" |$SED '
:a
s|^.\{0,'"$_G_width"'\}$|'"$3"'&|
ta
@ -1953,7 +1953,7 @@ func_strtable ()
# Strip off the indent, and make a divider with `-' chars, then
# reindent.
_G_divider=`echo "$func_strrow_result" \
_G_divider=`$bs_echo "$func_strrow_result" \
|$SED 's|[^ ]|-|g
:a
s|- |--|g
@ -2111,8 +2111,8 @@ func_insert_sorted_if_absent ()
func_grep_q "$str" "$file" \
&& func_verbose "inserting \`$str' into \`$file'"
echo "$str" |sort -u - "$file" |func_cmp_s - "$file" \
|| echo "$str" |sort -u - "$file" -o "$file" \
$bs_echo "$str" |sort -u - "$file" |func_cmp_s - "$file" \
|| $bs_echo "$str" |sort -u - "$file" -o "$file" \
|| func_permissions_error "$file"
done
}
@ -2177,7 +2177,7 @@ func_get_version ()
# Rather than uncomment the sed script in-situ, strip the comments
# programatically before passing the result to $SED for evaluation.
sed_get_version=`echo '# extract version within line
sed_get_version=`$bs_echo '# extract version within line
s|.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*|\1|
t done

View File

@ -254,8 +254,8 @@ func_extract_trace ()
$require_configure_ac
$require_gnu_m4
_G_m4_traces=`echo "--trace=$1" |$SED 's%,% --trace=%g'`
_G_re_macros=`echo "($1)" |$SED 's%,%|%g'`
_G_m4_traces=`$bs_echo "--trace=$1" |$SED 's%,% --trace=%g'`
_G_re_macros=`$bs_echo "($1)" |$SED 's%,%|%g'`
_G_macros="$1"; shift
test $# -gt 0 || {
set dummy $configure_ac
@ -357,7 +357,7 @@ func_extract_trace ()
# Save the command pipeline results for further use by callers of
# this function.
func_extract_trace_result=`echo "$_G_mini" \
func_extract_trace_result=`$bs_echo "$_G_mini" \
|$M4 -daq --prefix $_G_m4_traces - "$@" 2>&1 1>/dev/null \
|$SED -n -e "$_G_transform"`
}
@ -382,7 +382,7 @@ func_main ()
# Display results.
test -n "$func_extract_trace_result" \
&& echo "$func_extract_trace_result"
&& $bs_echo "$func_extract_trace_result"
# The End.
exit $EXIT_SUCCESS

View File

@ -173,6 +173,46 @@ basename='s|^.*/||'
nl='
'
# There are still modern systems that have problems with `echo' mis-
# handling backslashes, among others, so make sure $bs_echo is set to a
# command that correctly interprets backslashes.
# (this code from Autoconf 2.62)
# Printing a long string crashes Solaris 7 /usr/bin/printf.
bs_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
bs_echo=$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo
bs_echo=$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo$bs_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
&& (test "X`print -r -- $bs_echo`" = "X$bs_echo") 2>/dev/null; then
bs_echo='print -r --'
bs_echo_n='print -rn --'
elif (test "X`printf %s $bs_echo`" = "X$bs_echo") 2>/dev/null; then
bs_echo='printf %s\n'
bs_echo_n='printf %s'
else
if test "X`(/usr/ucb/echo -n -n $bs_echo) 2>/dev/null`" = "X-n $bs_echo"; then
bs_echo_body='eval /usr/ucb/echo -n "$1$nl"'
bs_echo_n='/usr/ucb/echo -n'
else
bs_echo_body='eval expr "X$1" : "X\\(.*\\)"'
bs_echo_n_body='eval
arg=$1;
case $arg in #(
*"$nl"*)
expr "X$arg" : "X\\(.*\\)$nl";
arg=`expr "X$arg" : ".*$nl\\(.*\\)"`;;
esac;
expr "X$arg" : "X\\(.*\\)" | tr -d "$nl"
'
export bs_echo_n_body
bs_echo_n='sh -c $bs_echo_n_body bs_echo'
fi
export bs_echo_body
bs_echo='sh -c $bs_echo_body bs_echo'
fi
# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
# is ksh but when the shell is invoked as "sh" and the current value of
# the _XPG environment variable is not equal to 1 (one), the special
@ -181,7 +221,7 @@ nl='
progpath=$0
# The name of this program.
progname=`echo "$progpath" |$SED "$basename"`
progname=`$bs_echo "$progpath" |$SED "$basename"`
## ------------------------- ##
@ -252,7 +292,7 @@ func_remove_hook ()
{
$debug_cmd
eval ${1}_hooks='`echo "\$'$1'_hooks" |$SED "s| '$2'||"`'
eval ${1}_hooks='`$bs_echo "\$'$1'_hooks" |$SED "s| '$2'||"`'
}
@ -541,7 +581,7 @@ func_echo ()
IFS=$nl
for _G_line in $_G_message; do
IFS=$save_IFS
echo "$progname: $_G_line"
$bs_echo "$progname: $_G_line"
done
IFS=$save_IFS
}
@ -561,7 +601,7 @@ func_error ()
IFS=$nl
for _G_line in $_G_message; do
IFS=$save_IFS
echo "$_G_prefix$tc_bold$_G_line$tc_reset" 1>&2
$bs_echo "$_G_prefix$tc_bold$_G_line$tc_reset" 1>&2
_G_prefix="$progname: "
done
IFS=$save_IFS
@ -586,8 +626,8 @@ func_fatal_help ()
{
$debug_cmd
eval echo \""Usage: $usage"\"
eval echo \""$fatal_help"\"
eval $bs_echo \""Usage: $usage"\"
eval $bs_echo \""$fatal_help"\"
func_error ${1+"$@"}
exit $EXIT_FAILURE
}
@ -601,7 +641,7 @@ func_help ()
$debug_cmd
func_usage_message
echo "$long_help_message"
$bs_echo "$long_help_message"
exit 0
}
@ -725,7 +765,7 @@ func_usage ()
$debug_cmd
func_usage_message
echo "Run \`$progname --help |${PAGER-more}' for full usage"
$bs_echo "Run \`$progname --help |${PAGER-more}' for full usage"
exit 0
}
@ -737,11 +777,11 @@ func_usage_message ()
{
$debug_cmd
eval echo \""$usage"\"
eval $bs_echo \""$usage"\"
echo
$SED -n 's|^# ||;/^Written by/{x;p;x;};h' < "$progpath"
echo
eval echo \""$usage_message"\"
eval $bs_echo \""$usage_message"\"
}