help-make
[Top][All Lists]
Advanced

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

Re: Breaking from a for loop?


From: Philip Guenther
Subject: Re: Breaking from a for loop?
Date: Mon, 23 Nov 2009 19:39:44 -0800

On Mon, Nov 23, 2009 at 8:43 AM, David Aldrich <address@hidden> wrote:
...
> .PHONY : makedynamiclibs
> makedynamiclibs :
>       address@hidden d in $(DYNAMIC_LIBS); do $(MAKE) --quiet --directory=$$d 
> $(MAKECMDGOALS); done
>
> This works fine but, when a library makefile exits with a failure code,
> the for loop continues with the next makefile. This means that this
> top level makefile can exit with status 0 even if a lower level makefile
> exits with status 1 or 2.
>
> How can I cause the for loop to break, and this makefile to exit with a
> failure status, if a lower level makefile fails, please?

Answer #1: it's just a /bin/sh 'for' loop; the shell's 'break'
built-in works there:

$ for i in 1 2 3 4; do echo $i; [ $i = 3 ] && break ; done
1
2
3
$

So:
        @for d in $(DYNAMIC_LIBS); do $(MAKE) --quiet --directory=$$d
$(MAKECMDGOALS) || break ; done


Answer #2: instead of looping at the shell level, perhaps you should
be looping at the make level, with a separate target for each
directory.  With that, make's parallel mode (-j) can recurse into the
directory concurrently instead of doing the first, then the second,
then third...  (I don't have a good example of how to do this on hand
and don't have time to dig one out the archives; sorry)


Philip Guenther




reply via email to

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