help-make
[Top][All Lists]
Advanced

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

RE: please clarify the manual on foreach function?


From: Paul Smith
Subject: RE: please clarify the manual on foreach function?
Date: Fri, 18 Feb 2011 18:42:23 -0500

On Fri, 2011-02-18 at 15:17 -0800, Mark Galeck (CW) wrote:
> Without being too clever, here's an SSCCE:
> 
> define VAR
> $(foreach item,foo bar,$(shell echo $(item)>>foobar.txt))
> endef
> 
> foobar:
>       $(VAR)
> 
> I guess what you are saying is, the (first pass of) make is serial.
> And in the manual it says, that make waits for the end of the shell
> function to collect the output of the shell.  

All of make is serial, including the first pass, and yes make will never
run multiple $(shell ...) functions at the same time.

I should point out that the evaluation of $(VAR) here does not happen
until make decides to start the "foobar" target.  This loop will never
have any output, so it will basically simply be an empty command; the
entire processing of this recipe is a side-effect of the evaluation.

This is, to be sure, pretty bizarre.  It's like using this for your
compile rules:

        %.o : %.c
                $(shell $(CC) -o $@ -c $<)

why would you do that?  In your case it's even weirder because you have
to run one shell per file instead of one shell total.  Is there a reason
you can't get rid of the $(shell ...) and just have:

        foobar:
                for v in foo bar; do echo $$v >> foobar.txt; done

??

> So that would mean, the above example should behave as expected.  

Yes.

> The reason why I was asking, is I see in one of my users, a rather
> bizarre effects, which would be consistent with the above shell
> invocations executed "in parallel" and/or not "in order".  So I think
> I should look for another explanation?

Yes, you need to look for another explanation.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]