Propagate error code from recursive nmake on Windows

43 Views Asked by At

I have the following recursive makefile for nmake on Windows:

MODULES = admin char mailnews merintr intro dm chess

all:
    -@for %i in ($(MODULES)) do @if EXIST %i (cd %i && $(MAKE) /$(MAKEFLAGS) && cd ..)

If one of the makes in the subdirectories fails, I want the outer nmake invocation to return an error code. Currently it always returns 0.

I've tried various permutations of setting an error variable if the inner make fails, but I can't get it propagated to the outer level.

1

There are 1 best solutions below

0
Joseph Quinsey On BEST ANSWER

You need to allow nmake to perform the loop itself. The following makefile should work:

MODULES = admin         \
        char            \
        mailnews        \
        merintr         \
        intro           \
        dm              \
        chess           \

all: $(MODULES)

clean:
    @$(MAKE) -$(MAKEFLAGS) $(MODULES) TARGET=$@

$(MODULES): FORCE
    @if exist $@\ cd $@ && $(MAKE) -$(MAKEFLAGS) $(TARGET)

FORCE: