为什么 Makefile 中 */%/x 不匹配 a/b/x?
在 Makefile 代码中解释...
PATH = a/b/x
$(patsubst a/%/x,%,$(PATH)) # => b
$(patsubst */%/x,%,$(PATH)) # => a/b/x
似乎这两个都应该产生相同的结果,b
,因为 *
应该匹配任何内容。为什么情况并非如此?如何编写一个表达式来捕获带有任何前缀的中心术语,而不仅仅是“a”?
Explained in Makefile code…
PATH = a/b/x
$(patsubst a/%/x,%,$(PATH)) # => b
$(patsubst */%/x,%,$(PATH)) # => a/b/x
It seems like both of these should produce the same result, b
, as the *
should match anything. Why is this not the case? How do I write one expression to capture the center term with any prefix, not just 'a'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Make 根本没有很好的处理通配符的能力。您的
$(patsubst */%/x,%,$(PATH))
不起作用,因为您的$(PATH)< 中没有
*
/代码>。但你可以通过这个组合获得你想要的效果:Make simply doesn't have very good ability to handle wildcards. Your
$(patsubst */%/x,%,$(PATH))
doesn't work because there is no*
in your$(PATH)
. But you can get the effect you want with this kludge: