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 02:13:05 +0000, Christos Zoulas wrote:

> In article <20180526004352.GJ1039%pony.stderr.spb.ru@localhost>,
> Valery Ushakov  <uwe%stderr.spb.ru@localhost> wrote:
> >
> >I'm confused.  Let's change my example to
> >
> >p=XXX
> >FOO=doit $p "$$@"
> >default:
> >        p=ZZZ; foo=${FOO:Q}; echo foo=$$foo
> >
> >
> >It was doing
> >
> >  p=ZZZ; foo=doit\ XXX\ \"\$@\"; echo foo=$foo
> >
> >before, and it does
> >
> >  p=ZZZ; foo=doit\ XXX\ \"\$\$@\"; echo foo=$foo
> >
> >now.
> >
> >So why $p is expanded and $$ (that expands to "$") is not expanded?
> >When does :Q logically happen w.r.t. expandion?
> 
> I see what you mean. The issue here is that the current expansion scheme
> for $$ makes it impossible to pass variables that contain $'s though multiple
> layers of ${MAKE} using :Q. Perhaps the way to fix it is to add a different
> modifier that preserves $$'s.

:Q is defined to quote *shell* meta-characters.  The problem with $$
$$$$ $$$$$$$$ etc is not unique to make but is endemic to all
macro-processors in some form.  At least make does recursive
expansion, so you mostly (only?) run into this with submakes.

As far as I understand you don't really need a new modifier, as
existing :S should do:

    DOLLAR=$$
    ...
        make DOLLAR=${DOLLAR:S/\$/&&/g:Q}

When a variable is expanded, the only remaining '$' characters in it
are from $$ in the original, since you know you are passing this to
another make you use :S to double them again for the nested make.  And
shell-quote the result with :Q

E.g.

# ---8<--- d.mk ---8<---
PID=$$$$
.if !defined(NESTED)
all:
	echo ${PID}
	echo ${PID:Q}
	make -f d.mk NESTED=${PID:S/\$/&&/g:Q}
.else
all:
	echo ${NESTED}
	echo ${NESTED:Q}
.endif
# ---8<---


If you want to hide the gory details you can probably even do
something like

MAKEQUOTE=S/\$$/&&/g:Q
...
	make .... NESTED=${PID:${MAKEQUOTE}}

-uwe


Home | Main Index | Thread Index | Old Index