help-make
[Top][All Lists]
Advanced

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

Re: Breaking out of a foreach loop


From: Noel Yap
Subject: Re: Breaking out of a foreach loop
Date: Sat, 28 Feb 2004 09:14:44 -0500

IMHO, $(firstword) is the clean approach but I'd do something like:

        $(foreach f,$(FILES),$(firstword $(wildcard $(addsuffix 
/$(f),$(DIRS)))))

I think emulating a loop using recursion could be much slower.

HTH,
Noel

"Bhatt, Milan C" wrote:
> 
> I want to be able to loop through a set of optional prerequisites and
> search for these files through a list of directories.
> 
> This would seem like the perfect usage model for VPATH, but since the
> files are optional, I can't statically set them as prereqs in the
> Makefile.
> 
> I was thinking something like this:
> 
> $(foreach file,$(FILES),
>     $(foreach dir,$(DIRS),
>         $(if $(wildcard $(dir)/$(file)), $(dir)/$(file);
> <break_to_next_file>)))
> 
> I'd like to have the break function so that in case the optional file is
> located in more than one directory, it would only return the first one.
> I suppose I could use the $(firstword) functionality or something like
> it to filter out the duplicate files, but I'm trying to find a clean
> one-pass approach first.
> 
> Hope this makes sense...
> 
> Thanks!
> Milan
> 
> -----Original Message-----
> From: Noel Yap [mailto:address@hidden
> Sent: Friday, February 27, 2004 3:07 PM
> To: Bhatt, Milan C
> Cc: address@hidden
> Subject: Re: Breaking out of a foreach loop
> 
> Think "functional programming language" rather than "procedural
> programming language".
> 
> What exactly do you want to do?  Maybe there's another way to do it.
> 
> Noel
> 
> > "Bhatt, Milan C" wrote:
> >
> > Hi Guys,
> >
> > I just had a quick question on whether there was any way to break out
> of a foreach loop when a certain condition has been reached.
> >
> > I'd like to do the following:
> >
> > $(foreach dir, $(DIRS), \
> >         $(if <condition>,   <statement>; \
> >                                        <break_out_of_loop>) )
> >
> > I wasn't able to find anything in the documentation that provided this
> kind of functionality.
> >
> > Thanks,
> > Milan
> >
> >
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> -------------
> > _______________________________________________
> > Help-make mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/help-make
> 
> --
> NOTICE: If received in error, please destroy and notify sender.  Sender
> does not waive confidentiality or privilege, and use is prohibited.

-- 
NOTICE: If received in error, please destroy and notify sender.  Sender does 
not waive confidentiality or privilege, and use is prohibited.




reply via email to

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