help-make
[Top][All Lists]
Advanced

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

Re: recursive make stop on error


From: Paul D. Smith
Subject: Re: recursive make stop on error
Date: Thu, 27 Apr 2006 15:51:33 -0400

%% "jason roscoe" <address@hidden> writes:

  jr> <snip Makefile>
  jr> SUBDIRS = subdir1 subdir2
  jr> CURRENT_DIR = .

  jr> all:: subdirs

  jr> subdirs::
  jr>   @for flag in ${MAKEFLAGS} ''; do \
  jr>   case "$$flag" in *=*) ;; *[ik]*) set +e;; esac; done; \
  jr>   for i in $(SUBDIRS) ;\
  jr>   do \
  jr>     echo "making" subdirs "in $(CURRENT_DIR)/$$i..."; \
  jr>     (cd $$i &&  $(MAKE) $(MFLAGS)  all); \
  jr>   done

There is a discussion of recursion and a much better way to implement it
than using a loop like this in the GNU make manual.  That discussion
uses some GNU make-specific features, but there are portable
alternatives as well (basically, replace .PHONY with a FORCE target).

  jr> What I want to figure out is whether or not the structure of the
  jr> loop above lends itself to stopping make, say if the make failed
  jr> in subdir1.  If so, what are the appropriate modifications needed
  jr> to cause this to happen?

Make doesn't monitor your shell script and force it to stop whenever
some program returns an error.  Make starts the shell, passes it the
script, waits for it to complete, then looks at the exit code.  If the
exit code is 0 it succeeds and moves to the next target.  If not it is
an error and make exits (unless -k is given).

So you need to ensure your shell script exits immediately when the make
in a subdirectory fails, and not wait until all the rest of the
sub-makes have already run (when, by the way


So, really, unless you want to rewrite your makefile along the lines
described in the GNU make manual, your question is a shell scripting
question and not a make question.

Rewrite your script like this:

 subdirs::
        @set -e; for flag in ${MAKEFLAGS} ''; do \
        case "$$flag" in *=*) ;; *[ik]*) set +e;; esac; done; \
        r=0; \
        for i in $(SUBDIRS) ;\
        do \
          echo "making" subdirs "in $(CURRENT_DIR)/$$i..."; \
          if (cd $$i &&  $(MAKE) $(MFLAGS) all); then \
            :; \
          else \
            r=1; \
            false; \
          fi; \
        done; \
        exit $r

and it will work, basically.  If you have questions about what's going
on let me know.

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