PigeonLueng
PigeonLueng

Reputation: 73

gnu make: how to stop and exit when errors occur in for loop make

I use 'for' loop to make subdirectories,but when some errors occur when make in subdirectory,it continues to make the next directory,can i stop when errors occur 'make' in subdirectory?

all :
    for i in $(SUBDIRS); do make -C $$i dll; done;
                ||
make[1]: *** [bd_snmp.o] error 1
make[1]: Leaving directory `/home/ping/work/svnsocserv/src/bd_snmp'
make[1]: Entering directory `/home/ping/work/svnsocserv/src/bd_snmp_proxy'

Upvotes: 3

Views: 7286

Answers (1)

MadScientist
MadScientist

Reputation: 100866

Sure, just add something to your shell script that checks:

all:
        for i in $(SUBDIRS); do $(MAKE) -C $$i dll || exit 1; done

(note ALWAYS use $(MAKE) to recursively invoke sub-makes, never make).

This is not a great method though, because while it does exit immediately when a sub-make fails it doesn't obey the make -k option to keep going.

Upvotes: 8

Related Questions