help-make
[Top][All Lists]
Advanced

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

Re: How to stop building when sub-make returns error


From: Philip Guenther
Subject: Re: How to stop building when sub-make returns error
Date: Tue, 12 Jan 2010 10:07:55 -0800

On Tue, Jan 12, 2010 at 9:21 AM, Paul Smith <address@hidden> wrote:
> On Tue, 2010-01-12 at 11:17 -0500, Harvey Chapman wrote:
>> For more information on pipes and errors, search for "pipefail" in the
>> bash man page. http://linux.die.net/man/1/bash
...
> If you care anything about portability in your makefile, please do NOT
> write your recipes to rely on bash features such as pipefail.  Even if
> you don't care about portability and do write your recipes to use bash
> features, you need to add SHELL=/bin/bash to your makefile so everyone
> will understand that you're requiring it.

For those wondering how to portably  implement "run make, filtering
its stdout and stderr through grep, but returning the exit status of
make", the classical method (as I learned it) is to pass the return
code down an additional pipe, redirected to some other file
descriptor:

two:
        { { $(MAKE) error 2>&1; echo $$? >&3 ; } | grep error >&2 ; }
3>&1 | { read ret; exit $$ret; }

That passes the error status down a pipe on fd 3 'around' the grep and
to a separate pipe where it's picked up by the read and give to the
exit command to set the entire pipe's exit status.  Yeah, it's ugly,
but it works everywhere.  You probably want to hide this from normal
make output using '@', ala:

two:
        @echo "$(MAKE) error 2>&1 | grep error"
        @{ { $(MAKE) error 2>&1; echo $$? >&3 ; } | grep error >&2 ; }
3>&1 | { read ret; exit $$ret; }

...but that's frosting.


Philip Guenther




reply via email to

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