gpt4 book ai didi

makefile 独立@符号和目录关键字

转载 作者:行者123 更新时间:2023-12-01 22:16:06 30 4
gpt4 key购买 nike

我想知道是否有人知道我的 makefile 中独立的 @ 符号和“dir”命令在这里(第二行和第三行)的作用:

$(BUILD)/%.o: %.cpp
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $? -o $@

我明白 $@ 是什么,但是 GNU 手册 (https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html) 中并未列出 @ 本身,而且我所有的搜索都与 $@ 相关。

此外,在第三行,我知道 mkdir -p 创建了嵌套目录,但我希望有人可以详细说明 $(dir $@),特别是“dir”部分。

感谢您的宝贵时间。

最佳答案

如果 @ 开始一个配方行,则命令本身不会回显。

$(dir $@) 扩展到目标 $@ 的目录部分。在这种情况下,如果目标是 $(BUILD)/rest/path/to/target.o,则为 $(BUILD)/rest/path/to/

来自 GNU make manual, 5.2 Recipe Echoing :

5.2 Recipe Echoing

Normally 'make' prints each line of the recipe before it is executed. We call this "echoing" because it gives the appearance that you are typing the lines yourself.

When a line starts with '@', the echoing of that line is suppressed. The '@' is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an 'echo' command to indicate progress through the makefile:

 @echo About to make distribution files

来自 same, 8.3 Functions for File Names

8.3 Functions for File Names

Several of the built-in expansion functions relate specifically to taking apart file names or lists of file names.

Each of the following functions performs a specific transformation on a file name. The argument of the function is regarded as a series of file names, separated by whitespace. (Leading and trailing whitespace is ignored.) Each file name in the series is transformed in the same way and the results are concatenated with single spaces between them.

'$(dir NAMES...)' Extracts the directory-part of each file name in NAMES. The directory-part of the file name is everything up through (and including) the last slash in it. If the file name contains no slash, the directory part is the string './'. For example,

      $(dir src/foo.c hacks)

produces the result 'src/ ./'.

关于makefile 独立@符号和目录关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45714649/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com