Makefile变量扩展
以下是一个人为的示例 Makefile,说明了我遇到的问题。
release: TYPE := release
FILE = main.cpp
OBJDIR = dist/$(TYPE)
OBJS = $(patsubst %.cpp,$(OBJDIR)/%.o,$(FILE))
release: $(OBJS)
@echo "just created: " $(OBJS)
%.o:
@echo "create $@"
当我运行“make release”时,输出是:
create dist//main.o
just created: dist/release/main.o
如何确保发布目标的 $(OBJS) 依赖项扩展到 dist/release/main.o 而不是 dist//main.o 。另外它扩展到 dist//main.o 的原因是什么?
The following is a contrived example Makefile illustrating a problem that I'm having.
release: TYPE := release
FILE = main.cpp
OBJDIR = dist/$(TYPE)
OBJS = $(patsubst %.cpp,$(OBJDIR)/%.o,$(FILE))
release: $(OBJS)
@echo "just created: " $(OBJS)
%.o:
@echo "create $@"
When I run 'make release' the output is:
create dist//main.o
just created: dist/release/main.o
How can I ensure that the $(OBJS) dependency of release target is expanded to dist/release/main.o and not dist//main.o . Also what is the reason for it expanding to dist//main.o?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它扩展到
dist//main.o
的原因是TYPE
是特定于目标的变量。这种变量的值仅在目标配方的上下文中可用(以及在其他特定于目标的分配中。这意味着该规则的先决条件中
TYPE
的值为空。The reason for it expanding to
dist//main.o
is thatTYPE
is a target-specific variable. The value of this kind of variable is only available within the context of a target's recipe (and in other target-specific assignments.This means the value of
TYPE
is empty in the prerequisites for that rule.