[英]How is a for loop implemented in a Makefile recipe
盡管下面的腳本旨在在子目錄級別1中查找一個makefile並使其遞歸進行,但我無法通過它找到任何成功。
for file in `find $(pwd)/ -maxdepth 2 -mindepth 2 -type f -name 'Makefile'`; do\
make --directory=$(dirname $file);\
done
這可能是什么問題?
在此配方中,您不打算通過make
擴展$(pwd)
, $(dirname ...)
和$file
,但是它們是這樣的,因為您沒有逃脫$
。 (嚴格來說,您不希望通過make
擴展$file
的$f
)。 重新寫成:
for file in `find $$(pwd)/ -maxdepth 2 -mindepth 2 -type f -name 'Makefile'`; do\
make --directory=$$(dirname $$file);\
done
后來
有沒有更好,更簡單的方法來制作項目的子模塊?
是。 規范的方式將是:
# Identify the sub-directories some way, not necessarily like this:
SUBDIRS := $(dir $(shell find $$(pwd)/ -maxdepth 2 -mindepth 2 -type f -name 'Makefile'))
.PHONY: $(SUBDIRS)
all: $(SUBDIRS)
# Maybe some recipe...
$(SUBDIRS):
$(MAKE) -C $@
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.