Makefile 中的四个美元符号

发布于 2024-08-02 05:47:00 字数 664 浏览 5 评论 0原文

我正在阅读GNU Make的文档。这是一个例子

%.d:%.c

<前><代码> @set -e; rm -f $@; \ $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$> $@; \ rm -f $@.$$$$

我在 C++ 程序上尝试了这个,并得到了文件列表

init3d.d init3d.d.18449 input.d input.d.18444 main.d main.d.18439

这是我发现但不明白的内容 ​​文档

如果您启用了二次扩展,并且希望在先决条件列表中包含文字美元符号,则实际上必须编写四个美元符号 ('$$$$')。

我想知道四个美元符号“$$$$”实际上是什么意思?他们如何18449、18444或18439?

感谢致敬!

I am reading the document of GNU Make. Here is an example

%.d: %.c

    @set -e; rm -f $@; \

     $(CC) -M $(CPPFLAGS) 
lt; > $@.$$; \

     sed ’s,\($*\)\.o[ :]*,\1.o $@ : ,g’ < $@.$$ > $@; \

     rm -f $@.$$

I tried this on a C++ program, and got the list of files

init3d.d init3d.d.18449 input.d input.d.18444 main.d main.d.18439

Here is what I found but don't understand in the same document

If you have enabled secondary expansion and you want a literal dollar sign in the prerequisites list, you must actually write four dollar signs (‘$$$$’).

I wonder what the four dollar signs "$$$$" mean actually? How do they 18449, 18444 or 18439?

Thanks and regards!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暗藏城府 2024-08-09 05:47:00

如果启用“二次扩展”,则需要 $$$$ 才能在实际输出中生成单个 $$ 通常用于扩展变量、调用 make 函数等。启用二次扩展的 $$ 会执行其他操作,但除此之外它会生成实际的 $输出中的代码>。

make 用于在类 Unix 系统上执行命令行的 shell 通常将 $$ 解释为扩展为 shell 进程 ID。因此,如果不启用二次扩展,$$$$ 将在输出中变成 $$,shell 将其扩展为进程 ID。

(使用 shell 进程 ID 作为后缀是尝试保证临时文件的文件名唯一性的一种简单方法。)

If make "secondary expansion" is enabled, $$$$ is required in order to generate a single $ in the actual output. $ is normally used to expand variables, call make functions, etc. $$ with secondary expansion enabled does something else, but otherwise it generates an actual $ in the output.

The shell that make uses to execute command-lines on Unix-like systems normally interprets $$ as expand to shell process ID. So, without secondary expansion enabled, $$$$ will turn into $$ in the output, which the shell will expand to the process ID.

(Using the shell process ID as a suffix is a simple way of trying to guarantee uniqueness of file name for a temporary file.)

只怪假的太真实 2024-08-09 05:47:00

$$ 将转换为 $,但在 Makefile 规则(它们是 shell 表达式)中,您还必须使用转义生成的 $ a \ 或在表达式周围使用单引号 '

下面是一个演示它的示例:

DOLLAR:=$
dollar:
    echo '$'  >  $@
    echo "\$" >> $@
    echo '$(DOLLAR)'  >> $@
    echo "\$(DOLLAR)" >> $@
    cat dollar

$$ will be converted to $, but in Makefile rules (which are shell expressions) you'll have to also escape the resulting $ using a \ or by using single quotes ' around your expression.

Here is an example that demonstrates it:

DOLLAR:=$
dollar:
    echo '$'  >  $@
    echo "\$" >> $@
    echo '$(DOLLAR)'  >> $@
    echo "\$(DOLLAR)" >> $@
    cat dollar
ま柒月 2024-08-09 05:47:00

18449、18444 或 18439 看起来像进程 ID,所以可能是进程 ID?

18449, 18444 or 18439 look like process ids so maybe a process ID?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文