tech-toolchain archive

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

Re: make: conditionals inside muti-line commands



> Or
> foobar:
> 	{ \
> 	${foo:Dprintf "foo=${foo}\n"}; \
> 	${bar:Dprintf "foo=${bar}\n"}; \
> 	} > ${.TARGET}
Sort of. The problem is that
	{ } > foobar
is invalid shell syntax (meaning my original version wouldn't have worked 
anyway even if make would have digested it).
But:

foobar:
	{\
		${foo:U\::Dprintf "foo=%s\n" "${foo}"}; \
		${bar:U\::Dprintf "bar=%s\n" "${bar}"}; \
	} >${.TARGET}

does the trick.
Of course you have to be careful of quoting colons in case you want something 
like "foo: %s\n" in the output. That's the advantage of Christos' approach: 
you don't have to care about that.

> foobar:
> 	printf "${foo:Dfoo=${foo}\n}${bar:Dbar=${bar}\n}" > ${.TARGET}
> 
> or, depending on your quoting requirements, something like
> 
> foobar:
> 	printf "{$foo:D%s\n:U%.0s}{$bar:D%s\n:U%.0s}" \
> 		'foo=${foo}' 'bar:${bar}' > ${.TARGET}
Yes, but not if I actually want printf to format something (which I omitted 
in the example because I thought it didn't matter).

EF> Is this a bug?
DH> Which part? The reason you can't mix conditionals with a single shell
DH> blob continued with \ is that such blobs are single lines and
DH> conditionals go on their own lines. This might be construed as
DH> undesirable, but it isn't readily changed.
I would have expected it either to work or the make conditionals showing 
up verbatim in the shell script.
What I got was warings about open conditionals meaning make mus have 
partially parsed them.

DH> The reason you can't put this construction on multiple lines of the
DH> recipe is that there's no guarantee of how many shells are run for
DH> recipes, and in fact it varies with the mode make's in. And,
DH> traditionally it's one shell per line.
That's clear to me.


Home | Main Index | Thread Index | Old Index