help-gnu-utils
[Top][All Lists]
Advanced

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

Re: shell for-loop in make


From: Bob Proulx
Subject: Re: shell for-loop in make
Date: Thu, 23 Oct 2014 17:20:20 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Hi Paul!

Paul Jarc wrote:
> Bob Proulx wrote:
> > depend all clean distclean:
> >  rm -f make.log ; \
> >  for d in $(DIRS) ; do \
> >    $(MAKE) -C $$d $@ ; \
> >    if [ $$? -ne 0 ]; then \
> >      echo "make failed with error $$?"; \
> >      exit 1; \
> >    fi; \
> >  done | tee -a make.log
> 
> I was going to make the same suggestion, but in this case "exit" won't
> do the right thing, because now it's buried within the first part of
> the pipeline.  So "make all" will always exit 0 because tee will exit
> 0.

Ah...  And ARGH!  (Sound of my head hitting the keyboard.)  Of course
you are correct!  Thanks for pointing that out.  Silly me.

Frankly I don't like the idea of putting the tee writing to a make.log
file in the rules like that at all.  I have an idea that it is going
to continue to be a source of problems.  This could be avoided by
using a driver script that would make all of the make calls, log as it
wants and handle any errors at that level.

> An ugly way to fix that would be "kill $PPID; exit 1".

That makes me nervous because it depends upon the shell being used
forking processes in an expected way.

Since it seems that creating files in the current directory is okay in
this context I would feel better about a different ugly hack.

 depend all clean distclean:
   rm -f FAILED make.log
   for d in $(DIRS) ; do \
     $(MAKE) -C $$d $@ || touch FAILED; \
   done | tee -a make.log
   test -f FAILED && exit 1

> > I am nervous about the rm -f make.log and then appending to it in this
> > way though.
> 
> That was probably there because tee was being invoked multiple times.
> If it's invoked just once, that shouldn't be necessary.

I have the idea that it truncates the log file.  Otherwise multiple
make runs continue to collect log information over multiple runs.  Of
course if that truncation is done elsewhere then it isn't needed there.

Bob

P.S. The original poster address bounces.  The message came in through
the Stanford news2mail gateway.  I have removed the address from this
reply and expect the poster to read it in their news feed.




reply via email to

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