tech-toolchain archive

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

Re: make: conditionals inside muti-line commands



On Mon, Jul 13, 2015 at 09:26:37PM +0200, Edgar Fu? wrote:
 > EF> Is there another way to achieve what I want without opening the target 
 > EF> multiple times?
 > 
 > CZ> foobar:
 > CZ> 	( \
 > CZ> 	${foo:Dfalse:Utrue} || echo foo=${foo}; \
 > CZ> 	${bar:Dfalse:Utrue} || echo bar=${bar}; \
 > CZ> 	) > ${.TARGET}

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

should work too. Or

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}

 > Just because I'm curious:
 > EF> Is this a bug?

Which part? The reason you can't mix conditionals with a single shell
blob continued with \ is that such blobs are single lines and
conditionals go on their own lines. This might be construed as
undesirable, but it isn't readily changed.

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

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index