tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: make :Q breakage



On Sat, May 26, 2018 at 14:32:07 -0400, Christos Zoulas wrote:

> On May 26,  8:32pm, uwe%stderr.spb.ru@localhost (Valery Ushakov) wrote:
> -- Subject: Re: make :Q breakage
> 
> | > When you want to pass e.g. variable reference to be interpreted by the
> | > submake?  I.e.
> | > 
> | > # FOO and BAR are defined in the submake, you can select which one you
> | > # want to use
> | > #DEFVAR=$${FOO}
> | > DEFVAR=$${BAR}
> | > 
> | > 	make -f other.mk VAR=${DEFVAR:Q}
> | > 
> | > Which is like setting VAR=${BAR} in the submake.  You want :Q for the
> | > shell, but you do mean to pass single $ here that you need to express
> | > with $$ in the caller.
> | > 
> | > Actually, the variable can be a shell variable too and not necessarily
> | > quoted to pass to a submake.  The use case your change broke with
> | > pkgsrc tools is exactly that for shell's $@
> | 
> | It can also be literal input to something with a dollar in it, e.g.
> | 
> | EDCMD=	3,$$d
> | all:
> | 	seq 5 > seq.txt
> | 	(echo ${EDCMD:Q}; echo wq ) | ed seq.txt
> | 	cat seq.txt
> | 
> | where you want shell-quoting but not make-quoting.
> | 
> | To reiterate - there are two distinct operations here.  One is quoting
> | of meta-characters interpreted by shell, the other is quoting the
> | meta-characters interpreted by make.  In the latter case the character
> | is just '$' and to "quote" it, you need to change it to $$, which you
> | can do with :S.  Since it's only one character, the :S expression is
> | not that unwieldy, so may be we don't necessarily want to introduce a
> | brand new modifier just for that. Even if we do, it's still
> | conceptually a separate operation from :Q
> | 
> | OTOH, since we will almost always want to apply shell-quoting after
> | make-quoting anyway, it might be convenient to introduce a version of
> | :Q that first applies make-quoting, so that you can write ${VAR:QM}
> | instead of ${VAR:S/\$/&&/g:Q} or ${VAR:${MAKEQUOTE}}.  If you need
> | just the make-quoting you can still use :S
> 
> Ok, I will use :Qm, so that it is not confused with :M and follow the
> current convention, but I will note that the manual page says now:
> 
>     :Q   Quotes every shell meta-character in the variable, so that it can be
> 	 passed safely through recursive invocations of make.
> 
> so the original intention was to pass safely variables to sub-makes
> (I would know since I wrote it) and I should have realized that '$'
> needs to be doubled too. But that is water under the bridge now.

pkgsrc uses :Q a lot for plain shell.  Actually, if you want to be
really safe you probably want to use :Q on ~everything because even
your MAKE may be C:/Program Files/PkgSrc/make.exe :) And from a quick
look pkgsrc indeed does.


> So the man page will say when I change it:
> 
>     :Q   Quotes every shell meta-character in the variable, so that it can be
> 	 passed safely to the shell.
> 
>     :Qm   Quotes every shell meta-character in the variable and `$', so that
> 	 it can be passed safely through recursive invocations of make.

The wording for :Qm is not the best.  Because it doubles instances of
dollar (at least conceptually) first (i.e. make-quote), and *then*
quotes both dollar characters with backslash for shell.  Might be
worth mentioning that it has the same effect as :S...:Q

-uwe


Home | Main Index | Thread Index | Old Index