make:在先决条件中使用目标特定变量
我正在尝试编写一个 Makefile,其中使用目标特定变量的先决条件
version=
target1: override version=1
target1: package
target2: override version=2
target2: package
package: dir=package-${version}\
package: source
source: src/${version}.c
当我运行 make 时,版本变量位于目标包中,源为空。
我做错了什么?
I'm trying to write a Makefile where prerequisites using target specific variables
version=
target1: override version=1
target1: package
target2: override version=2
target2: package
package: dir=package-${version}\
package: source
source: src/${version}.c
When i run make the version variable is in target package and source empty.
What I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用二次扩展:
UPD。
这个答案是错误的,由于类似问题的答案中解释的原因,建议的代码将不起作用。
TL;DR:特定于目标的变量根据 make 当前构建的目标发挥作用 [1]。反过来,第二次扩展发生在读入阶段结束时 [2],在构建任何内容之前。
感谢 @koniiiik 的指出。
Use Secondary Expansion:
UPD.
This answer is wrong, the suggested code won't work because of the reasons explained in the answer to a similar question.
TL;DR: Target-specific variables take their effect based on the target that make is currently building [1]. Second expansion, in turn, takes place right at the end of the read-in phase [2], before building anything.
Thanks to @koniiiik for pointing out.