[Top][All Lists]

[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 12:44:37 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

ElChino wrote:
>    $(MAKE) -C $$d $@ | tee -a make.log ; \

> But the 'exit' isn't called when $(MAKE) fails on a target.
> Anybody see the problem?

If tee exits last then it will set the $? exit code.  I didn't try it
but I think that is your problem.  I didn't try it so I could be wrong.

Having | tee -a log everywhere is inconvenient and causes these types
of problems.  Don't do it on every command.  Instead tee the entire
list of commands to the log.  You can create a list with { ... ;} so
you can always { ... ;} | tee -a log and the output from the entire
list will go into the log.  But shell constructs such as for ... done
and while ... done can also be redirected.  Try this:

DIRS = dir1 \
          dir2      # etc. a long list of dirs.

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

Additionally that pwd save and cd restore was useless in the example
you showed.  I don't know if that was cut down from something that
previously needed it.  But you didn't need it there.  I removed them.

I am nervous about the rm -f make.log and then appending to it in this
way though.  I worry about parallel make -j2 race conditions.  I think
it might have one process writing the file and another one removing it
later and output to be lost.  I would ask about that on the mailing list.  The help-make list is where all of
the real make experts hang out for just those types of questions.

Hope that helps,

reply via email to

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