簡體   English   中英

如何在Makefile配方中實現for循環

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM