[英]How to set a Makefile target depend on pattern prerequisites?
我在makefile中有一系列模式依賴項,最后它們應該放在一個文件中,例如: *.x
- > *.y
- > onefile.z
所以我制作了這樣的文件:
$ touch a.x b.x
和規則:
%.y: %.x some-other-script
touch $@
onefile.z: %.y second-other-script
touch $@
此規則不起作用:
$ make onefile.z
make: *** No rule to make target '%.y', needed by 'onefile.z'. Stop.
使用通配符:
%.y: %.x some-other-script
touch $@
z: $(wildcard *.y) second-other-script
touch $@
這也不起作用:它看到沒有*.y
文件並繼續制作onefile.z
跳過第一條規則。
$ make onefile.z
touch onefile.z
$ ls
a.x b.x onefile.z Makefile
我可能可以將兩個規則合並為一個,但在實際應用程序中,有更多的步驟,有些是通過HTTP發出請求並花費很多時間,實際上不應該沒有理由重復。
有沒有辦法做出這樣的依賴?
onefile.z: %.y second-other-script
是常規規則,而不是模式規則或靜態模式規則,因此%
字面解釋。 即使它是一個模式規則,如何推斷該詞應該匹配什么?
$(wildcard *.y)
告訴make查找匹配*.y
所有文件,但當然還沒有,所以它返回一個空字符串。
如果我正確理解你的問題,以下內容應該有效:
xfiles := $(wildcard *.x)
yfiles := $(xfiles:.x=.y)
%.y: %.x some-other-script
touch $@
onefile.z: $(yfiles) second-other-script
touch $@
請參閱Gnu Make文檔
$(wildcard ...)
$(foo:from=to)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.