From 685b3f73f75b5ce95ef468dd81d4a2302e2de82f Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sat, 24 May 2014 22:41:21 -0700
Subject: [PATCH 2/2] build: improve rule to generate egrep+fgrep scripts

* src/Makefile.am (egrep fgrep): chmod a=rx generated files,
and remove $@-t before attempting to redirect to it, in case it
is read-only.
---
 src/Makefile.am | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index e2c82a4..0697c63 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,19 +45,20 @@ AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 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	&& \
+	$(AM_V_GEN)rm -f $@-t
+	$(AM_V_at)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 \
+	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" \
+	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
+	$(AM_V_at)chmod a=rx $@-t
 	$(AM_V_at)mv $@-t $@

 CLEANFILES = egrep fgrep *-t
-- 
2.0.0.rc3

