From 0d7ff95d72c16b7d0d23c778d7e5426e736dcc9d Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 22 Mar 2008 09:44:12 +0200 Subject: [PATCH] build: Quote redirections when echoing commands. Without this, "make --directory=doc V=1 keymap-defaults.txt" would not display the command it runs, because the command is LC_ALL=C LANGUAGE=en /home/Kalle/src/elinks-0.12/doc/tools/keys2doc /home/Kalle/src/elinks-0.12/src/config/kbdbind.c keymap-defaults.txt > keymap-defaults.txt and the build system would run echo LC_ALL=C LANGUAGE=en /home/Kalle/src/elinks-0.12/doc/tools/keys2doc /home/Kalle/src/elinks-0.12/src/config/kbdbind.c keymap-defaults.txt > keymap-defaults.txt && LC_ALL=C LANGUAGE=en /home/Kalle/src/elinks-0.12/doc/tools/keys2doc /home/Kalle/src/elinks-0.12/src/config/kbdbind.c keymap-defaults.txt > keymap-defaults.txt so, the initial echo was redirected to keymap-defaults.txt too, and then overwritten with the intended output. Now, the build system instead runs echo 'LC_ALL=C LANGUAGE=en /home/Kalle/src/elinks-0.12/doc/tools/keys2doc /home/Kalle/src/elinks-0.12/src/config/kbdbind.c keymap-defaults.txt > keymap-defaults.txt' && LC_ALL=C LANGUAGE=en /home/Kalle/src/elinks-0.12/doc/tools/keys2doc /home/Kalle/src/elinks-0.12/src/config/kbdbind.c keymap-defaults.txt > keymap-defaults.txt which echoes the redirection instead of executing it. This change also makes the output correctly preserve quotes in some other rules. --- Makefile.lib | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index 96c85185..03bb7d8c 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -23,22 +23,33 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ # If we are verbose, we will show the "real" cmds instead of # their quiet versions (which are used in the non-verbose mode). # Inspired by the Linux kernel build system. +# +# If real cmds are to be shown, then quoteverbose quotes each as +# a shell word, so that it can be accurately displayed with echo. +# If the quiet versions are to be shown, then they should already +# be sufficiently quoted, so quoteverbose does nothing. ifdef V quiet = mquiet = masq_ + quoteverbose = '$(subst ','\'',$(1))' + #'# This line fixes syntax highlighting in Emacs' makefile-mode. Q = else quiet = quiet_ mquiet = quiet_ + quoteverbose = $(1) Q = @ endif # Show the command (quiet or non-quiet version based on the assignment # just above) and then execute it. -ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1)) -cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1)) -mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1)) -ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1)) +# +# Because $(cmd_$(1)) and related variables may contain references to $(2), +# they must be expanded right here; that cannot be delegated to quoteverbose. +ncmd = $(if $($(quiet)cmd_$(1)),echo $(call quoteverbose,$($(quiet)cmd_$(1))) &&) $(cmd_$(1)) +cmd = @$(if $($(quiet)cmd_$(1)),echo $(call quoteverbose,$($(quiet)cmd_$(1))) &&) $(cmd_$(1)) +mcmd = @$(if $($(mquiet)cmd_$(1)),echo $(call quoteverbose,$($(mquiet)cmd_$(1))) &&) $(cmd_$(1)) +ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $(call quoteverbose,$($(mquiet)cmd_$(1))) &&) $(cmd_$(1)) quiet_cmd_compile = ' [$(CC_COLOR)CC$(END_COLOR)] $(RELPATH)$@' masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2)