GNU make 引用
引用有什么区别吗?
libmylib.a: ...
$(AR) $(ARFLAGS) $@ $?
# vs
libmylib.a: ...
"$(AR) $(ARFLAGS) $@ $?"
@echo Compiler: $(CXX)
# vs
@echo "Compiler: $(CXX)"
谢谢!
Does quoting makes any difference?
libmylib.a: ...
$(AR) $(ARFLAGS) $@ $?
# vs
libmylib.a: ...
"$(AR) $(ARFLAGS) $@ $?"
@echo Compiler: $(CXX)
# vs
@echo "Compiler: $(CXX)"
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
makefile 规则中的命令只是简单地输入到 shell,因此引用绝对重要。这个规则会起作用:
但这个不会起作用:
第二个不会起作用,因为你可能没有一个名为 ar -r libx.a ao bo 的命令,即使你确实有一个 ar 命令知道如何处理 -r libx.a ao bo 参数列表。
您的第二个示例:
有点不同,因为引号位于 shell 内置
echo
的参数周围,因此这两个规则:通常会产生相同的输出(当然,除非您有一些奇怪的输出)例如,名称中包含“>”的 C++ 编译器命令,在这种情况下,无论是谁命名您的 C++ 编译器,所需的输出都会令人大吃一惊,这甚至超出了 GNU make 的能力)。另一方面,由于引号和空格的相互作用,这两个规则会产生略有不同的输出:
rule3 会执行与rule1 相同的操作,但rule4 会打印一个中间带有一堆空格的字符串。
The commands in makefile rules are simply fed to the shell so quoting absolutely does matter. This rule will work:
but this one won't:
The second won't work because you probably don't have a single command called, say,
ar -r libx.a a.o b.o
even though you do have anar
command that knows what to do with the-r libx.a a.o b.o
argument list.Your second example:
is a bit different because the quotes are around the argument to the shell built-in
echo
so these two rules:would usually produce the same output (unless, of course, you had some bizarre C++ compiler command that had, for example, a ">" in its name and, in this case, the desired output would be a smack upside the head to whoever named your C++ compiler and that's beyond the abilities of even GNU make). On the other hand, these two rules would produce slightly different output due to the interaction of the quotes and the whitespace:
rule3 would do the same thing as rule1 but rule4 would print a string with a bunch of whitespace in the middle.