help-make
[Top][All Lists]
Advanced

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

Re: .DELETE_ON_ERROR & error propagation through multi-command


From: Paul Smith
Subject: Re: .DELETE_ON_ERROR & error propagation through multi-command
Date: Tue, 08 Nov 2011 07:40:46 -0500

On Tue, 2011-11-08 at 13:26 +0100, Robert wrote:
> .DELETE_ON_ERROR: $(UPDATE_TARGET) $(EXE_TARGET)

Note that prerequisites of .DELETE_ON_ERROR are ignored.  See the
manual.

> $(UPDATE_TARGET): $(SRC)
>       $(PYTHON) install/mk_update.py -w
> #     cd install; $(PYTHON) mk_update.py -w; cd ..
> 
> The out-commented version with multi-command due to cd's doesn't 
> lead to a deletion of the broken target upon execution error in 
> the py script. While the action version (cd's done inside the 
> script now), will lead to deletion as wanted when error.

This is a shell question, not a make question.

Make runs all the commands in a single logical recipe line in one
invocation of the shell.  It then waits for that shell to exit and
examines the exit code of the shell.  If it's success, the recipe line
succeeded.  If it's not, the recipe line failed.

The exit code of a shell is the exit code of the last command the shell
executed.

In the case of the commented line above, the last command the shell
executes before exiting is the "cd ..", which always succeeds.  So, this
recipe will always succeed and never fail.

With UNIX shells there are lots of ways to manage this.  First you don't
need the "cd .." at all because the working directory is a per-process
feature: changing directories in a sub-shell doesn't impact the parent
shell.  I'm aware that Windows may not behave that way.

Also in general for UNIX shell scripts in recipes you want to separate
all the commands with "&&", not ";", which ensures that if one fails the
command fails immediately with that error.

I'm not strong in Windows scripting so I can't say the best way to solve
your problem.  Presumably you want to preserve the exit code of the
python script, then do the "cd ..", then exit from the recipe line using
the saved exit code.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

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