Subject: bug#17471: closed (Re: bug#17471: On Solaris 10, grep snapshot apparently hit by bleeding-edge Autoconf bug)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 12 May 2014 18:46:02 +0000

Your bug report

#17471: On Solaris 10, grep snapshot apparently hit by bleeding-edge Autoconf bug

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
17471: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17471
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#17471: On Solaris 10, grep snapshot apparently hit by bleeding-edge Autoconf bug
From: Paul Eggert <[email-masked]>
To: Jim Meyering <[email-masked]>
Cc: Autoconf bugs <[email-masked]>, [email-masked]
Date: Mon, 12 May 2014 11:44:46 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 05/12/2014 10:33 AM, Jim Meyering wrote:
> Does anyone see a way to make it more efficient with a POSIX shell?

Yes. Eric's earlier message convinced me that grep shouldn't rely on 
Autoconf guaranteeing a shell that supports substrings in parameter 
expansion, so I came up with the attached patch (which keeps the shell 
efficient with a POSIX shell) and pushed it before I got around to 
reading your message.  I tested on Solaris 10 with the shell 
artificially set to /bin/sh, so I'm marking this as done.

 From an Autoconf point of view it might be nice to have a good way to 
say "I need a POSIX shell" or at least "I need a shell that does 
substrings", but that's merely a wishlist item.
>From 0ca1f6d79514189ef8db6e931f285cbaec9789ec Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Mon, 12 May 2014 11:38:28 -0700
Subject: [PATCH] egrep, fgrep: port to Solaris 10 /bin/sh

This old shell doesn't grok ${0%/*}; see: http://bugs.gnu.org/17471
* src/Makefile.am (egrep fgrep): Don't assume the shell does substrings.
* src/egrep.sh (dir): New var, so that the substring calculation is
done only once (which is a small win even with newer shells),
and so that the calculation is easier to edit on older shells.
---
 src/Makefile.am | 7 +++++++
 src/egrep.sh    | 5 +++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index f8c9415..e2c82a4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,7 +47,14 @@ EXTRA_DIST = dosbuf.c egrep.sh
 egrep fgrep: egrep.sh Makefile
 	$(AM_V_GEN)grep=`echo grep | sed -e '$(transform)'`	&& \
 	case $@ in egrep) option=-E;; fgrep) option=-F;; esac	&& \
+	shell_does_substrings='set x/y && d=$${1%/*} && test "$$d" = x' && \
+	if $(SHELL) -c "$$shell_does_substrings" 2>/dev/null; then \
+	  edit_substring='s,X,X,'; \
+	else \
+	  edit_substring='s,\$${0%/\*},`expr "X$$0" : '\''X\\(.*\\)/'\''`,g'; \
+	fi && \
 	sed -e 's|[@]SHELL@|$(SHELL)|g' \
+	    -e "$$edit_substring" \
 	    -e "s|[@]grep@|$$grep|g" \
 	    -e "s|[@]option@|$$option|g" <$(srcdir)/egrep.sh >$@-t
 	$(AM_V_at)chmod +x $@-t
diff --git a/src/egrep.sh b/src/egrep.sh
index f1b4146..1a03d2a 100644
--- a/src/egrep.sh
+++ b/src/egrep.sh
@@ -2,8 +2,9 @@
 grep=grep
 case $0 in
   */*)
-    if test -x "${0%/*}/@grep@"; then
-      PATH=${0%/*}:$PATH
+    dir=${0%/*}
+    if test -x "$dir/@grep@"; then
+      PATH=$dir:$PATH
       grep=@grep@
     fi;;
 esac
-- 
1.9.0

Subject: On Solaris 10, grep snapshot apparently hit by bleeding-edge Autoconf bug
From: Paul Eggert <[email-masked]>
To: grep mailing list <[email-masked]>
Cc: Autoconf bugs <[email-masked]>
Date: Sun, 11 May 2014 13:48:32 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Following up to the grep snapshot announcement in:

http://lists.gnu.org/archive/html/platform-testers/2014-05/msg00000.html

That snapshot failed to build the shell scripts egrep and fgrep properly 
on Solaris 10, because it set "SHELL = /bin/sh" in src/Makefile, which 
caused the makefile to put "#!/bin/sh" at the top of the shell scripts, 
which breaks because the shell scripts use a construct '${0%/*}' that 
Solaris 10 /bin/sh doesn't grok.  The build should have used SHELL = 
/bin/bash, which is what grep does with my test builds.

We could work around the problem by avoiding that shell construct, but 
I'd rather fix the build machinery because this bug could affect any 
package that uses POSIX shell scripts.  The snapshot was built with an 
experimental version of Autoconf (2.69.117-1717), whereas I had tested 
with the latest stable version (2.69 as shipped with Fedora 20).  The 
two versions differ in how they compute the name of a working shell, so 
it appears that there's a bug in the experimental version of Autoconf.

A quick workaround for grep is to build the next snapshot with Autoconf 
2.69.  In the long run, though, we should fix the Autoconf bug.  I'll 
CC: this to bug-autoconf to give them a heads-up.