我想做某事,如:
for i in *
do
if test -d $i
then
cd $i; make clean; make; cd -;
fi;
done
这样可以正常工作,但是如果构建中断,我希望“中断”for
- 循环。
有办法做到这一点吗?也许是某种if
- 语句,可以检查make
的成功吗?
答案 0 :(得分:17)
您可以使用Make本身来实现您的目标:
SUBDIRS := $(wildcard */.)
.PHONY : all $(SUBDIRS)
all : $(SUBDIRS)
$(SUBDIRS) :
$(MAKE) -C $@ clean all
如果任何目标失败,Make会中断执行。
支持任意目标:
SUBDIRS := $(wildcard */.) # e.g. "foo/. bar/."
TARGETS := all clean # whatever else, but must not contain '/'
# foo/.all bar/.all foo/.clean bar/.clean
SUBDIRS_TARGETS := \
$(foreach t,$(TARGETS),$(addsuffix $t,$(SUBDIRS)))
.PHONY : $(TARGETS) $(SUBDIRS_TARGETS)
# static pattern rule, expands into:
# all clean : % : foo/.% bar/.%
$(TARGETS) : % : $(addsuffix %,$(SUBDIRS))
@echo 'Done "$*" target'
# here, for foo/.all:
# $(@D) is foo
# $(@F) is .all, with leading period
# $(@F:.%=%) is just all
$(SUBDIRS_TARGETS) :
$(MAKE) -C $(@D) $(@F:.%=%)
答案 1 :(得分:4)
您可以通过make
变量检查其退出代码来检查$?
是否已成功退出,然后生成break
声明:
...
make
if [ $? -ne 0 ]; then
break
fi