From 3b765946c7ef6e3139750ca7956aa72835ff22c3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 1 Mar 2009 18:44:45 +0100 Subject: [PATCH] Re-enable the use of "sed --posix" with sed >= 4.2. --- ChangeLog | 5 +++++ gnulib-tool | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79726a80a..d98c59248 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-01 Bruno Haible + + * gnulib-tool (sed): Do alias as "sed --posix" if sed's version is at + least 4.2. + 2009-03-01 Eric Blake Bruno Haible diff --git a/gnulib-tool b/gnulib-tool index 4f254b4a7..5882c68b7 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -63,28 +63,32 @@ if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then AUTOPOINT="${GETTEXTPATH}autopoint" fi -# Disabled because "sed --posix" is buggy in GNU sed 4.1.5, see +# When using GNU sed, turn off as many GNU extensions as possible, +# to minimize the risk of accidentally using non-portable features. +# However, do this only for gnulib-tool itself, not for the code that +# gnulib-tool generates, since we don't want "sed --posix" to leak +# into makefiles. And do it only for sed versions 4.2 or newer, +# because "sed --posix" is buggy in GNU sed 4.1.5, see # . -if false; then - # When using GNU sed, turn off as many GNU extensions as possible, - # to minimize the risk of accidentally using non-portable features. - # However, do this only for gnulib-tool itself, not for the code that - # gnulib-tool generates, since we don't want "sed --posix" to leak - # into makefiles. - if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then - # Define sed as an alias. - # It is not always possible to use aliases. Aliases are guaranteed to work - # if the executing shell is bash and either it is invoked as /bin/sh or - # is a version >= 2.0, supporting shopt. This is the common case. - # Two other approaches (use of a variable $sed or of a function func_sed - # instead of an alias) require massive, fragile code changes. - # An other approach (use of function sed) requires `which sed` - but - # 'which' is hard to emulate, due to missing "test -x" on some platforms. - if test -n "$BASH_VERSION"; then - shopt -s expand_aliases >/dev/null 2>&1 - fi - alias sed='sed --posix' +if (alias) > /dev/null 2>&1 \ + && echo | sed --posix -e d >/dev/null 2>&1 \ + && case `sed --version | sed -e 's/^[^0-9]*//' -e 1q` in \ + [1-3]* | 4.[01]*) false;; \ + *) true;; \ + esac \ + ; then + # Define sed as an alias. + # It is not always possible to use aliases. Aliases are guaranteed to work + # if the executing shell is bash and either it is invoked as /bin/sh or + # is a version >= 2.0, supporting shopt. This is the common case. + # Two other approaches (use of a variable $sed or of a function func_sed + # instead of an alias) require massive, fragile code changes. + # An other approach (use of function sed) requires `which sed` - but + # 'which' is hard to emulate, due to missing "test -x" on some platforms. + if test -n "$BASH_VERSION"; then + shopt -s expand_aliases >/dev/null 2>&1 fi + alias sed='sed --posix' fi # sed_noop is a sed expression that does nothing. -- 2.11.0