Subject: How make(1) reacts on failing commands
To: Eric Haszlakiewicz <>
From: Roland Illig <>
List: pkgsrc-changes
Date: 11/17/2005 18:57:31
Eric Haszlakiewicz wrote:
> On Thu, Nov 17, 2005 at 10:07:41AM +0100, Roland Illig wrote:
>>Eric Haszlakiewicz wrote:
>>>	Well, that certainly makes the output look correct, but I don't
>>>understand why you don't see any output without the patch.  The line
>>>that calls check-vulnerable has a semicolon on the end:
>>>       vul=`${MAKE} ${MAKEFLAGS} check-vulnerable`;        \
>>>so the shell should keep processing the rest of the "command" that's been
>>>fed to it, no?
>>When invoked from make(1), the shell is always in "set -e" mode, that is 
>>the first command giving an exitcode != 0 stops the whole program.
> 	eh? I tried this on two of my machines, and on
>>cat Makefile
> foo:
>         echo foo; false; echo bar; set -o
>>make foo
> echo foo; false; echo bar; set -o
> foo
> bar
> Current option settings
> errexit         off
> of them are off also...

make programs terminating after "echo foo":
   - Solaris 9, /usr/xpg4/bin/make
   - bmake-3.1.12 20050603
   - netbsd-20040210
   - IRIX 6.5:1289570120

make programs continuing:
   - GNU make
   - netbsd-20050327
   - netbsd-20041129

However, what they all do the same is to terminate when a complete 
command fails. That is, if the Makefile were:

         echo foo
         echo bar
         set -o

"echo bar" and "set -o" would not be executed (with the default options; 
there's still -k).

> Is this something that has changed recently?  If it really is supposed to
> work how you say it is, how can one ever use make to run a program that
> doesn't return 0?  (e.g. even just a simple rv=`cmp -s a b` would cause
> the script line to stop)

Surround it with "if". See mk/bulk/print{index,depends} for examples. I 
have rewritten them lately to use the "set -e" mode. (printindex, line 
157--158, is a good starting point.)