GNU make:当 for loop make 中发生错误时如何停止和退出



我使用"for"循环来制作子目录,但是当在子目录中make时发生一些错误时,它会继续制作下一个目录,当子目录中发生错误时我可以停止"make"吗?

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'

当然,只需在 shell 脚本中添加一些内容来检查:

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

(注意始终使用 $(MAKE) 递归调用子makes,从不make)。

不过,这不是一个好方法,因为虽然当子制作失败时它会立即退出,但它不服从制作-k选项继续前进。

最新更新