简体   繁体   English

这个 makefile 规则中的大括号是做什么用的?

[英]What are the braces in this makefile rule for?

I am reading a makefile for a Qt-created project that has the following:我正在阅读 Qt 创建的项目的 makefile,该项目具有以下内容:

{backend}.cpp{release\}.obj::
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
    $<  
<<

(above code is using \\t for recipe and is as written in makefile) (上面的代码使用 \\t 作为配方,并且是在 makefile 中编写的)

Both the rule and the recipe confuse me.规则和食谱都让我感到困惑。

I'll start with {backend} in the rule.我将从规则中的{backend}开始。 Obviously the same confusion for {release} as well.显然{release}也有同样的困惑。 I assume this is a reference to a particular sub-directory named backend .我假设这是对名为backend的特定子目录的引用。 I guess that ..\\backend\\release\\bar.obj would be found as a legitimate target?我猜..\\backend\\release\\bar.obj会被发现为合法目标? But what part of make says this is legitimate syntax and what exactly happens here?但是make 的哪一部分说这是合法的语法,这里到底发生了什么?

FWIW: This is in a section commented as: ##### implicit rules . FWIW:这是在注释为: ##### implicit rules Version: GNU Make 4.2.1 Built for x86_64-unknown-cygwin版本: GNU Make 4.2.1 Built for x86_64-unknown-cygwin

Bonus points:奖励积分:

Explain the use of @<< and << in the recipe... ( Yes, I'm lacking in bash shell finesse... ).解释@<<<<在配方中的使用......(是的,我缺乏 bash shell 技巧...... )。 Is this referencing the first prerequisite with $< and silently redirecting it?这是用$<引用第一个先决条件并静默重定向它吗? Why isn't it $$< ?为什么不是$$<

Thanks.谢谢。

That is an NMAKE batch-mode rule这是 NMAKE 批处理模式规则

https://docs.microsoft.com/en-us/cpp/build/batch-mode-rules?view=vs-2017 https://docs.microsoft.com/en-us/cpp/build/batch-mode-rules?view=vs-2017

The equivalent GNU Make rule would be something like等效的 GNU Make 规则类似于

backend/%.obj: release/%.cpp:

With the difference that, as the name suggests, these rules will invoke their recipes only once for all valid targets and expect the rule to create all of the targets in a single pass with the $< macro.不同之处在于,顾名思义,这些规则只会为所有有效目标调用一次他们的配方,并期望规则使用$<宏在一次传递中创建所有目标。

The << syntax is NMAKE's inline file feature <<语法是 NMAKE 的内联文件功能

https://docs.microsoft.com/en-us/cpp/build/inline-files-in-a-makefile?view=vs-2017 https://docs.microsoft.com/en-us/cpp/build/inline-files-in-a-makefile?view=vs-2017

This expands and captures everything between the angle brackets and saves it to a file, in this case a temporary file as no filename is specified after the brackets.这将扩展并捕获尖括号之间的所有内容并将其保存到一个文件中,在这种情况下是一个临时文件,因为在括号后没有指定文件名。 The file is then passed to the compiler as a response file on the first line of the recipe through the @ option.然后该文件通过@选项作为配方第一行的响应文件传递给编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM