Makefile中的四个美元符号 [英] Four Dollar signs in Makefile

查看:233
本文介绍了Makefile中的四个美元符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

%.d:%.c

%.d: %.c

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

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

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

     rm -f $@.$$$$

我在C ++程序上尝试过此操作,并获得了文件列表

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

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 (‘$$$$’).

我想知道四个美元符号"$$$$"的实际含义是什么?他们如何18449、18444或18439?

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

感谢和问候!

推荐答案

如果启用了二次扩展",则需要$$$$才能在实际输出中生成单个$. $通常用于扩展变量,调用make函数等.$$启用了辅助扩展的功能还有其他功能,否则会在输出中生成实际的$.

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.

用于在类Unix系统上执行命令行的shell通常将$$解释为扩展为shell进程ID.因此,在未启用辅助扩展的情况下,$$$$会在输出中变成$$,shell会将其扩展为进程ID.

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.

(使用Shell进程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.)

这篇关于Makefile中的四个美元符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆