[英]GNU Make fails to enter subdirectories from a loop
我有一個包含多個子目錄的項目,主要的Makefile需要能夠構建/清理一些子目錄-子目錄的確切名稱通過變量傳遞(示例中為DIRS):
DIRS = dir1 dir2 # Usually passed from the command line
.PHONY: all clean $(DIRS)
all: $(DIRS)
# ... do stuff in this direcotry ...
$(DIRS):
$(MAKE) -C $(@)
clean:
# ... Clean this directory ...
$(foreach d,$(DIRS),cd $(d) && $(MAKE) clean; )
由於我已經使用目錄名稱作為構建目標,因此我想使用循環來清理每個子目錄。 但是我收到以下錯誤:
$ make clean
# ... Clean this directory ...
cd dir1 && make clean; cd dir2 && make clean;
make[1]: Entering directory `/home/ex/clean_try/dir1'
rm -fr *.o
make[1]: Leaving directory `/home/ex/clean_try/dir1'
/bin/sh: 1: cd: can't cd to dir2
make: *** [clean] Error 2
好像它已經離開了dir1,為什么它不能從主目錄輸入dir2?
cd dir2
是剛剛完成cd dir1
---的上下文,而dir2不是dir1的子目錄,對嗎? :-)
嘗試: make -C $d clean
高溫超導
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.