bug-make
[Top][All Lists]
Advanced

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

Re: handling of errors during recursion


From: Paul D. Smith
Subject: Re: handling of errors during recursion
Date: Tue, 26 Jun 2001 17:04:34 -0400

%% Michael Espe <address@hidden> writes:

  me> The issue I am dealing with is an error in a sub-make causes that
  me> make file to terminate, but the main makefile just goes to the
  me> next sub-make and keeps on going.

  me> I could reproduce this with a few simple makefiles.  Other version
  me> of make which had been used before would pass the error to the
  me> parent makefile which would also then terminate, and so on.  There
  me> are option to turn this behavior off, so I would expect the normal
  me> behavior would be to fail.

The option to which you're referring deals with continuing after errors
that make sees.  That's not the problem here.

  me> The documentation does not seem to specifically spell this out,
  me> either way.

  me> What is the specified behavior, and is this a known issue? 

I think the documentation is pretty clear: if any of the command scripts
that GNU make runs exits with an error, it will stop.

The problem is, your sub-makes are failing but then you're not exiting
the script with an error, so make doesn't see it.

Your rule is:

SUBMAKE = t1.mk t2.mk

  all:
        @for sub in ${SUBMAKE} ; \
        do  \
        (${MAKE} -f $$sub) \
        done

Note that nowhere here do you test the result of the sub-make to see if
it failed; you simply continue with the next sub-make.

The result of this command script, since you don't specifically exit
with any value, will be the result of the final command that was
invoked.  So, if the last sub-make fails, the script will exit with a
failure code and make will see it.  If any other sub-make fails, make
will not see it so it won't know something bad happened, and it won't
stop.

The reason other makes have different behavior is that they invoke
subshells with the -e option (see your sh(1) man page).  This causes the
shell to exit with an error as soon as any command the shell runs exits.
You can get this behavior in GNU make by adding "set -e" to such
commands, like:

  all:
        @set -e; \
        for sub in ${SUBMAKE} ; \
        do  \
        (${MAKE} -f $$sub) \
        done

The reason GNU make doesn't do this is that the POSIX.2 definition of
make specifically states how make will invoke sub-shells, and it doesn't
provide for the use of the -e flag.  I also think not using -e by
default is superior behavior.


However, the best way to handle this is to not use a loop like this to
do subdirectory builds.  Needing the -e flag is only part of the reason.
Also consider that if you ever wanted to use any kind of parallel build,
this can break that since it's considered one rule by make, so you won't
get any of the directories built in parallel.

The Right Way to do submakes in GNU make is like this:

  all: $(SUBMAKE)

  .PHONY: $(SUBMAKE)
  $(SUBMAKE):
        ${MAKE} -f $@

Actually, if "SUBMAKE" is normally a list of subdirectories you would
say "-C $@" instead, but whatever.

Now you get full parallel capabilities.  And, if you have dependencies
between two directories or whatever, just declare them normally:

  prog_dir : lib1_dir lib2_dir lib3_dir

etc.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "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]