git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 09/13] Makefile: add c-quote helper function
Date: Wed, 05 Feb 2014 11:13:24 -0800	[thread overview]
Message-ID: <xmqqmwi54bl7.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20140205175809.GI15218@sigill.intra.peff.net> (Jeff King's message of "Wed, 5 Feb 2014 12:58:09 -0500")

Jeff King <peff@peff.net> writes:

> We have to c-quote strings coming from Makefile variables
> when we pass them to the compiler via "-D". Now that we can
> use $(call) in our Makefile, we can factor out the quoting
> to make things easier to read. We can also apply it more
> consistently, as there were many spots that should have been
> C-quoting but did not. For example:
>
>   make prefix='foo\bar'
>
> would produce an exec_cmd.o with a broken prefix.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  Makefile | 58 +++++++++++++++++++++++++++++-----------------------------
>  1 file changed, 29 insertions(+), 29 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 868872f..b1c3fb4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1568,6 +1568,17 @@ endif
>  sqi = $(subst ','\'',$1)
>  sq = '$(call sqi,$1)'
>  
> +# usage: $(call cq,CONTENTS)
> +#
> +# Quote the value as appropriate for a C string literal.
> +cq = "$(subst ",\",$(subst \,\\,$1))"
> +
> +# usage: $(call scq,CONTENTS)
> +#
> +# Quote the value as C string inside a shell string. Good for passing strings
> +# on the command line via "-DFOO=$(call # scq,$(FOO))".

"call # scq"???

> +scq = $(call sq,$(call cq,$1))
> +
>  # usage: $(eval $(call make-var,FN,DESC,CONTENTS))
>  #
>  # Create a rule to write $CONTENTS (which should come from a make variable)
> @@ -1617,28 +1628,17 @@ LIB_OBJS += $(COMPAT_OBJS)
>  # Quote for C
>  
>  ifdef DEFAULT_EDITOR
> -DEFAULT_EDITOR_CQ = "$(subst ",\",$(subst \,\\,$(DEFAULT_EDITOR)))"
> -DEFAULT_EDITOR_CQ_SQ = $(subst ','\'',$(DEFAULT_EDITOR_CQ))
> -
> -BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'
> +BASIC_CFLAGS += -DDEFAULT_EDITOR=$(call scq,$(DEFAULT_EDITOR))
>  endif
>  
>  ifdef DEFAULT_PAGER
> -DEFAULT_PAGER_CQ = "$(subst ",\",$(subst \,\\,$(DEFAULT_PAGER)))"
> -DEFAULT_PAGER_CQ_SQ = $(subst ','\'',$(DEFAULT_PAGER_CQ))
> -
> -BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)'
> +BASIC_CFLAGS += -DDEFAULT_PAGER=$(call scq,$(DEFAULT_PAGER))
>  endif
>  
>  ifdef SHELL_PATH
> -SHELL_PATH_CQ = "$(subst ",\",$(subst \,\\,$(SHELL_PATH)))"
> -SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
> -
> -BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
> +BASIC_CFLAGS += -DSHELL_PATH=$(call scq,$(SHELL_PATH))
>  endif
>  
> -GIT_USER_AGENT_CQ = "$(subst ",\",$(subst \,\\,$(GIT_USER_AGENT)))"
> -GIT_USER_AGENT_CQ_SQ = $(subst ','\'',$(GIT_USER_AGENT_CQ))
>  $(eval $(call make-var,USER-AGENT,user agent string,$(GIT_USER_AGENT)))
>  
>  ifdef DEFAULT_HELP_FORMAT
> @@ -1723,9 +1723,9 @@ strip: $(PROGRAMS) git$X
>  
>  git.sp git.s git.o: MAKE/PREFIX
>  git.sp git.s git.o: EXTRA_CPPFLAGS = \
> -	'-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
> -	'-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
> -	'-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
> +	-DGIT_HTML_PATH=$(call scq,$(htmldir_relative)) \
> +	-DGIT_MAN_PATH=$(call scq,$(mandir_relative)) \
> +	-DGIT_INFO_PATH=$(call scq,$(infodir_relative))
>  
>  git$X: git.o MAKE/LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
>  	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
> @@ -1735,14 +1735,14 @@ help.sp help.s help.o: common-cmds.h
>  
>  builtin/help.sp builtin/help.s builtin/help.o: common-cmds.h MAKE/PREFIX
>  builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
> -	'-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
> -	'-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
> -	'-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
> +	-DGIT_HTML_PATH=$(call scq,$(htmldir_relative)) \
> +	-DGIT_MAN_PATH=$(call scq,$(mandir_relative)) \
> +	-DGIT_INFO_PATH=$(call scq,$(infodir_relative))
>  
>  version.sp version.s version.o: GIT-VERSION-FILE MAKE/USER-AGENT
>  version.sp version.s version.o: EXTRA_CPPFLAGS = \
> -	'-DGIT_VERSION="$(GIT_VERSION)"' \
> -	'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
> +	-DGIT_VERSION=$(call scq,$(GIT_VERSION)) \
> +	-DGIT_USER_AGENT=$(call scq,$(GIT_USER_AGENT))
>  
>  $(BUILT_INS): git$X
>  	$(QUIET_BUILT_IN)$(RM) $@ && \
> @@ -2020,25 +2020,25 @@ endif
>  
>  exec_cmd.sp exec_cmd.s exec_cmd.o: MAKE/PREFIX
>  exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
> -	'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
> -	'-DBINDIR="$(bindir_relative_SQ)"' \
> -	'-DPREFIX="$(prefix_SQ)"'
> +	-DGIT_EXEC_PATH=$(call scq,$(gitexecdir)) \
> +	-DBINDIR=$(call scq,$(bindir_relative)) \
> +	-DPREFIX=$(call scq,$(prefix))
>  
>  builtin/init-db.sp builtin/init-db.s builtin/init-db.o: MAKE/PREFIX
>  builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
> -	-DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
> +	-DDEFAULT_GIT_TEMPLATE_DIR=$(call scq,$(template_dir))
>  
>  config.sp config.s config.o: MAKE/PREFIX
>  config.sp config.s config.o: EXTRA_CPPFLAGS = \
> -	-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
> +	-DETC_GITCONFIG=$(call scq,$(ETC_GITCONFIG))
>  
>  attr.sp attr.s attr.o: MAKE/PREFIX
>  attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
> -	-DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
> +	-DETC_GITATTRIBUTES=$(call scq,$(ETC_GITATTRIBUTES))
>  
>  gettext.sp gettext.s gettext.o: MAKE/PREFIX
>  gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
> -	-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
> +	-DGIT_LOCALE_PATH=$(call scq,$(localedir))
>  
>  http-push.sp http.sp http-walker.sp remote-curl.sp: SPARSE_FLAGS += \
>  	-DCURL_DISABLE_TYPECHECK

  reply	other threads:[~2014-02-05 19:13 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05 17:48 [PATCH/RFC 0/13] makefile refactoring Jeff King
2014-02-05 17:49 ` [PATCH 01/13] Makefile: drop USE_GETTEXT_SCHEME from GIT-CFLAGS Jeff King
2014-02-05 17:49 ` [PATCH 02/13] Makefile: fix git-instaweb dependency on gitweb Jeff King
2014-02-05 17:50 ` [PATCH 03/13] Makefile: introduce make-var helper function Jeff King
2014-02-06  8:55   ` Eric Sunshine
2014-02-05 17:50 ` [PATCH 04/13] Makefile: use tempfile/mv strategy for GIT-* Jeff King
2014-02-05 17:50 ` [PATCH 05/13] Makefile: prefer printf to echo " Jeff King
2014-02-05 17:52 ` [PATCH 06/13] Makefile: store GIT-* sentinel files in MAKE/ Jeff King
2014-02-05 19:05   ` Junio C Hamano
2014-02-05 17:53 ` [PATCH 07/13] Makefile: always create files via make-var Jeff King
2014-02-05 17:57 ` [PATCH 08/13] Makefile: introduce sq function for shell-quoting Jeff King
2014-02-05 19:12   ` Junio C Hamano
2014-02-05 17:58 ` [PATCH 09/13] Makefile: add c-quote helper function Jeff King
2014-02-05 19:13   ` Junio C Hamano [this message]
2014-02-05 19:17     ` Jeff King
2014-02-05 17:58 ` [PATCH 10/13] Makefile: drop *_SQ variables Jeff King
2014-02-05 19:14   ` Junio C Hamano
2014-02-05 18:02 ` [PATCH 11/13] Makefile: auto-build C strings from make variables Jeff King
2014-02-05 19:17   ` Junio C Hamano
2014-02-05 19:20     ` Jeff King
2014-02-05 18:05 ` [PATCH 12/13] Makefile: teach scripts to include " Jeff King
2014-02-05 19:26   ` Junio C Hamano
2014-02-05 19:50     ` Jeff King
2014-02-08 21:47   ` Thomas Rast
2014-02-10  1:15     ` Jeff King
2014-02-05 18:08 ` [PATCH 13/13] move LESS/LV pager environment to Makefile Jeff King
2014-02-05 19:23   ` Jeff King
2014-02-05 19:52     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmwi54bl7.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).