threads / patch / 31489

patchMakefile: quiet shell commands when "make --silent"

Subject: [PATCH] Makefile: quiet shell commands when "make --silent"

## tl;dr

3 messages between Sep 9, 2012 and Sep 10, 2012. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Pete Wyckoff· Sep 9, 2012, 23:09 UTC · lore

Option "--silent", "--quiet" or "-s" to make prevents echoing of commands as they are executed. However, there are some explicit "echo" commands in the Makefile and in the two GIT-VERSION-GEN scripts that always echo.

Quiet the explicit "echo"s in Makefile when MAKEFLAG "s" is set. Pass this information into both GIT-VERSION-GEN helpers so that they can run silently too.

Before:
    $ echo >>git.c
    $ make -s
    GIT_VERSION = 1.7.12.378.gaeb1945.dirty
	* new script parameters
    GITGUI_VERSION = 0.16.GITGUI-dirty
    $
After:
    $ echo >>git.c
    $ make -s
    $
Signed-off-by: Pete Wyckoff <pw@padd.com>
---
Make should be silent when given "--silent".

This may help tools that post-process make output, like the "check-docs" command. Peff noticed in 5fafce0 (check-docs: get documented command list from Makefile, 2012-08-08) that:

> ... make will print extra cruft like
> "GIT-VERSION-FILE is up to date" to stdout.
They now can use "make -s" to avoid filtering out the cruft.
		-- Pete
 GIT-VERSION-GEN         | 11 ++++++++++-
 Makefile                | 13 ++++++++-----
 git-gui/GIT-VERSION-GEN | 11 ++++++++++-
 3 files changed, 28 insertions(+), 7 deletions(-)
Show changes to 3 files +28 −7

GIT-VERSION-GEN, Makefile, git-gui/GIT-VERSION-GEN

diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index d2d2d69..97f0825 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -6,6 +6,12 @@ DEF_VER=v1.7.12.GIT
 LF='
 '
 
+silent=
+if test "${1:-}" = "#"
+then
+	silent=1
+fi
+
 # First see if there is a version file (included in release tarballs),
 # then try git-describe, then default.
 if test -f version
@@ -35,7 +41,10 @@ else
 	VC=unset
 fi
 test "$VN" = "$VC" || {
-	echo >&2 "GIT_VERSION = $VN"
+	if test -z "$silent"
+	then
+		echo >&2 "GIT_VERSION = $VN"
+	fi
 	echo "GIT_VERSION = $VN" >$GVF
 }
 
diff --git a/Makefile b/Makefile
index 66e8216..dac5aab 100644
--- a/Makefile
+++ b/Makefile
@@ -305,7 +305,7 @@ all::
 # "git help" is called without a parameter specifying the format.
 
 GIT-VERSION-FILE: FORCE
-	@$(SHELL_PATH) ./GIT-VERSION-GEN
+	@$(SHELL_PATH) ./GIT-VERSION-GEN "$(SILENT_SH_ECHO)"
 -include GIT-VERSION-FILE
 
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
@@ -1850,6 +1850,9 @@ ifndef V
 	export QUIET_GEN
 	export QUIET_BUILT_IN
 endif
+else
+# in --silent mode, suppress echo command in shell commands
+SILENT_SH_ECHO = \#
 endif
 
 ifdef NO_INSTALL_HARDLINKS
@@ -2074,7 +2077,7 @@ endef
 GIT-SCRIPT-DEFINES: FORCE
 	@FLAGS='$(SCRIPT_DEFINES)'; \
 	    if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
-		echo 1>&2 "    * new script parameters"; \
+		$(SILENT_SH_ECHO)echo 1>&2 "    * new script parameters"; \
 		echo "$$FLAGS" >$@; \
             fi
 
@@ -2451,7 +2454,7 @@ TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
 GIT-PREFIX: FORCE
 	@FLAGS='$(TRACK_PREFIX)'; \
 	if test x"$$FLAGS" != x"`cat GIT-PREFIX 2>/dev/null`" ; then \
-		echo 1>&2 "    * new prefix flags"; \
+		$(SILENT_SH_ECHO)echo 1>&2 "    * new prefix flags"; \
 		echo "$$FLAGS" >GIT-PREFIX; \
 	fi
 
@@ -2460,7 +2463,7 @@ TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):$(USE_GETTEXT_SCHEME)
 GIT-CFLAGS: FORCE
 	@FLAGS='$(TRACK_CFLAGS)'; \
 	    if test x"$$FLAGS" != x"`cat GIT-CFLAGS 2>/dev/null`" ; then \
-		echo 1>&2 "    * new build flags"; \
+		$(SILENT_SH_ECHO)echo 1>&2 "    * new build flags"; \
 		echo "$$FLAGS" >GIT-CFLAGS; \
             fi
 
@@ -2469,7 +2472,7 @@ TRACK_LDFLAGS = $(subst ','\'',$(ALL_LDFLAGS))
 GIT-LDFLAGS: FORCE
 	@FLAGS='$(TRACK_LDFLAGS)'; \
 	    if test x"$$FLAGS" != x"`cat GIT-LDFLAGS 2>/dev/null`" ; then \
-		echo 1>&2 "    * new link flags"; \
+		$(SILENT_SH_ECHO)echo 1>&2 "    * new link flags"; \
 		echo "$$FLAGS" >GIT-LDFLAGS; \
             fi
 
diff --git a/git-gui/GIT-VERSION-GEN b/git-gui/GIT-VERSION-GEN
index 6570943..ba17163 100755
--- a/git-gui/GIT-VERSION-GEN
+++ b/git-gui/GIT-VERSION-GEN
@@ -6,6 +6,12 @@ DEF_VER=0.16.GITGUI
 LF='
 '
 
+silent=
+if test "${1:-}" = "#"
+then
+	silent=1
+fi
+
 tree_search ()
 {
 	head=$1
@@ -75,6 +81,9 @@ else
 	VC=unset
 fi
 test "$VN" = "$VC" || {
-	echo >&2 "GITGUI_VERSION = $VN"
+	if test -z "$silent"
+	then
+		echo >&2 "GITGUI_VERSION = $VN"
+	fi
 	echo "GITGUI_VERSION = $VN" >$GVF
 }
-- 
1.7.12.378.gaeb1945.dirty
Junio C Hamano· Sep 10, 2012, 00:35 UTC · re: Pete Wyckoff · lore

Re: [PATCH] Makefile: quiet shell commands when "make --silent"

Pete Wyckoff <pw@padd.com> writes:
> Option "--silent", "--quiet" or "-s" to make prevents
> echoing of commands as they are executed.  However, there
> are some explicit "echo" commands in the Makefile and in
> the two GIT-VERSION-GEN scripts that always echo.
"make -s clean"?

I am not very enthused, especially if the primary motivation is about "check-docs". Such a script must be prepared to filter out cruft from the output of $(MAKE) and to pick out the bits that interests it and that has been the way of life with $(MAKE) way before Git started as a project ;-).

In order to make it more robust, targets like "print-man1" can (and should) arrange their output in such a way that interesting parts are easily findable.

Pete Wyckoff· Sep 10, 2012, 12:16 UTC · re: Junio C Hamano · lore

Re: [PATCH] Makefile: quiet shell commands when "make --silent"

gitster@pobox.com wrote on Sun, 09 Sep 2012 17:35 -0700:
Show 8 quoted lines
> Pete Wyckoff <pw@padd.com> writes:
> 
> > Option "--silent", "--quiet" or "-s" to make prevents
> > echoing of commands as they are executed.  However, there
> > are some explicit "echo" commands in the Makefile and in
> > the two GIT-VERSION-GEN scripts that always echo.
> 
> "make -s clean"?
Fixed here.
Show 5 quoted lines
> I am not very enthused, especially if the primary motivation is
> about "check-docs".  Such a script must be prepared to filter out
> cruft from the output of $(MAKE) and to pick out the bits that
> interests it and that has been the way of life with $(MAKE) way
> before Git started as a project ;-).

My motivation was to quiet output from a script I use to test bisectability. I sent it out because I noticed someone else found the verbosity annoying too.

Agreed that "fixing" check-docs is not important; that's why I didn't bother in this patch.

		-- Pete

← back to recent threads