From: Eric Blake Date: Mon, 10 Nov 2008 15:28:48 +0000 (-0700) Subject: Try 'print -r --' as a non-forking variant of 'printf %s\\n'. X-Git-Tag: v2.63b~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b78b1ae088255de3108bf7497857ea133aa604b;p=thirdparty%2Fautoconf.git Try 'print -r --' as a non-forking variant of 'printf %s\\n'. * lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Cater to Solaris ksh. * doc/autoconf.texi (Limitations of Builtins) : Document the print workaround. Idea by Paolo Bonzini. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 5ddd2f778..6dd25c6f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-11-10 Eric Blake + + Try 'print -r --' as a non-forking variant of 'printf %s\\n'. + * lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Cater to Solaris ksh. + * doc/autoconf.texi (Limitations of Builtins) : Document + the print workaround. + Idea by Paolo Bonzini. + 2008-11-10 Eric Blake Provide a section on all tools allowed in GNU Coding Standards. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index f59be60b7..86bed7f8d 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -15291,6 +15291,12 @@ example, @file{/usr/bin/printf} is buggy, so when using @command{/bin/sh} the command @samp{printf %010000x 123} normally dumps core. +Since @command{printf} is not always a shell builtin, there is a +potential speed penalty for using @code{printf %s\\n} as a replacement +for an @command{echo} that does not interpret @samp{\} or leading +@samp{-}. With Solaris @command{ksh}, it is possible to use @code{print +-r --} for this role instead. + @item @command{pwd} @c ---------------- diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index a506ef06d..e0b7c55b8 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -875,7 +875,7 @@ m4_defun_init([AS_ECHO_N], # _AS_ECHO_PREPARE # ----------------- # Arrange for $as_echo 'FOO' to echo FOO without escape-interpretation; -# and similarly for $as_echo_foo, which omits the trailing newline. +# and similarly for $as_echo_n, which omits the trailing newline. # 'FOO' is an optional single argument; a missing FOO is treated as empty. m4_defun([_AS_ECHO_PREPARE], [[as_nl=' @@ -885,7 +885,13 @@ export as_nl as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then +# 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 -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else