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: Paul Jarc
Subject: Re: shell for-loop in make
Date: Thu, 23 Oct 2014 15:14:02 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Bob Proulx <bob@proulx.com> wrote:
> 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.

That will happen regardless of what order the commands exit.  It's
determinted by the syntactic order.

> 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.  An ugly way to fix that would be "kill $PPID; 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.


paul



reply via email to

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