help-make
[Top][All Lists]
Advanced

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

RE: make is setting exit code to 0 when gcc command fails


From: Cook, Malcolm
Subject: RE: make is setting exit code to 0 when gcc command fails
Date: Tue, 10 Feb 2015 21:36:51 +0000

>
 >On Mon Feb  9 12:35:36 2015, address@hidden (Paul Smith) wrote:
 >> On Mon, 2015-02-09 at 16:19 +0000, David Aldrich wrote:
 >> > If I deliberately introduce a syntax error into one of my C files,
 >> > make calls gcc to build the file, as expected, and an error is
 >> > reported as text in bash.  However, the exit code (checked using echo
 >> > $?) returns 0.  If I run the gcc command from the bash command line,
 >> > the exit code is 1.
 >> >
 >> > Why might make return 0 instead of 1 in the case of this compiler
 >> > error?
 >
 >Guess: you're checking it like this:
 >
 >%.o: %.c
 >      $(CC) -c -o $@ $<
 >      @echo $?
 >
 >That won't work: each line will use a separate shell invocation, unless
 >
 >.ONESHELL:
 >
 >is specified.

Indeed!  +1

And in addition, to get the recipe to terminate on the first error, add the 
following target.  

.POSIX:

This may not be what you want to do in general for your other recipes - you 
have to decide - but it works in this case.  I find the combination of 
.ONESHELL: and .POSIX: (and .SHELL=/bin/bash) is EXACTLY what I want in ALL my 
recipes.

 >
 >--
 >Reinier Post
 >
 >_______________________________________________
 >Help-make mailing list
 >address@hidden
 >https://lists.gnu.org/mailman/listinfo/help-make



reply via email to

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