我用类似的代码
https://stackoverflow.com/a/17845120/1375972
TOPTARGETS := zip test clean
SUBDIRS := $(wildcard */.)
$(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)
它在每个子目录上运行(从TOPTARGETS)传递的make命令,这就是我想要的。
但是我想有个目标
deploy
它只有在设置了环境变量时才具有相同的行为。以下是我尝试过的:
deploy:
ifdef GITLAB_CI
@echo "GITLAB_CI variable is defined, running deploy on all subdirectories"
$(MAKE) -C $(SUBDIRS) $(MAKECMDGOALS)
else
@echo "snip"
endif
注意
$(MAKE)
线条与
$(SUBDIRS)
一个,就一个
$@
替换为
直接。
$(细分卢比)
部署中的行为不符合预期。当我跑的时候
make deploy
在包含两个子目录的目录中:
> make deploy
GITLAB_CI variable is defined, running deploy on all subdirectories
/Library/Developer/CommandLineTools/usr/bin/make -C subdir1/. subdir2/. deploy
make[1]: *** No rule to make target `subdir2/.'. Stop.
make: *** [deploy] Error 2
相比
make clean
(我的一个朋友)
TOPTARGETS
):
> make clean
/Library/Developer/CommandLineTools/usr/bin/make -C subdir1/. clean
/Library/Developer/CommandLineTools/usr/bin/make -C subdir2/. clean
所以当
头号目标
使用时
$@
好像展开了
$(细分卢比)
$@
替换为
. 有没有办法让我自己也有这种行为
部署
线路?或者我需要写我自己的循环
$(细分卢比)
在目标里面?