简体   繁体   English

理解 Makefile 规则

[英]Understanding Makefile rule

I have been debugging a linking error for specific target (android), for all other targets, build is successful.我一直在调试特定目标(android)的链接错误,对于所有其他目标,构建成功。

Error is something like错误是这样的

Test.cpp:29:57: fatal error: linux/ethtool.h: No such file or directory compilation terminated.
make: *** [../../../makefiles/rules.makefile:1012: android-arm-r/Test.o] Error 1

and build command is:和构建命令是:

make DEBUG=no TARGET=android

I checked this rules.makefile's 1012 line:我检查了这个 rules.makefile 的 1012 行:

$(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp $(OBJDIR)/%.d 
     @$(cpp_PRECOMPILE) 
     $(cpp_COMMAND) $< 
     @$(cpp_POSTCOMPILE)

Now, as typical make rule pattern, I can understand that,现在,作为典型的 make 规则模式,我可以理解,

  • TARGET is $(OBJDIR)/%.$(OBJ_SUFFIX)目标是$(OBJDIR)/%.$(OBJ_SUFFIX)

  • PREREQUISITES are %.cpp $(OBJDIR)/%.d (Source files, which would be mostly Test.cpp, being the only cpp file in that dir) %.cpp $(OBJDIR)/%.d条件是%.cpp $(OBJDIR)/%.d (源文件,主要是 Test.cpp,是该目录中唯一的 cpp 文件)

  • RECIPE is食谱是

     @$(cpp_PRECOMPILE) $(cpp_COMMAND) $< @$(cpp_POSTCOMPILE)

Here, looking at other files, I could see,在这里,查看其他文件,我可以看到,

cpp_PRECOMPILE is :
cpp_COMMAND is gcc -x c++
cpp_PRECOMPILE is :

So that makes the RECIPE, somewhat like:所以这使得食谱,有点像:

     @: 
     /opt/android-arm-r9/bin/arm-linux-androideabi- gcc -x c++ $< 
     @:

Now, I am not able to understand:现在,我无法理解:

  1. What is @$ for? @$有什么用?

  2. $< is automatic variable holding prerequisite name. $<是保存先决条件名称的自动变量。 But overall what action this recipe is trying to do?但总的来说,这个食谱试图做什么?

  3. When no TARGET is given (default is linux)当没有给出TARGET (默认为 linux)

     make CPU=x86_64 DEBUG=no

    works perfectly.完美地工作。

    But when TARGET=android , it fails.但是当TARGET=android ,它失败了。

     make CPU=x86_64 DEBUG=no TARGET=android

"@" simply silence the current line. "@" 只是让当前行静音。

The "-x" option determines the language, thus $(gcc -x c++) $< compiles the file (prerequisite) as C++ file. “-x”选项确定语言,因此$(gcc -x c++) $<将文件(先决条件)编译为 C++ 文件。

  1. What is @$ for? @$ 有什么用?

@$ is not a unit. @$不是一个单位。 The @ is a prefix that suppresses the command's output from being forwarded to make 's output. @是一个前缀,它禁止将命令的输出转发到make的输出。 The $ is the beginning of a variable reference ( $(cpp_PRECOMPILE) ) which expands to a command to run. $是变量引用( $(cpp_PRECOMPILE) )的开头,它扩展为要运行的命令。

  1. $< is automatic variable holding prerequisite name. $< 是保存先决条件名称的自动变量。 But overall what action this recipe is trying to do?但总的来说,这个食谱试图做什么?

More specifically, $< expands to the name of the first prerequisite.更具体地说, $<扩展为第一个先决条件的名称。 This matters in your case, since the rule designates multiple prerequisites.这对您来说很重要,因为规则指定了多个先决条件。

The variable names appearing in the recipe give a pretty clear indication of what the recipe is supposed to do:配方中出现的变量名称非常清楚地表明配方应该做什么:

  1. $(cpp_PRECOMPILE) -- some kind of step preparing for compilation. $(cpp_PRECOMPILE) -- 某种准备编译的步骤。 That might be anything or nothing;那可能是什么,也可能什么都不是; it presumably depends on values of other variables, and maybe on other factors as well.它大概取决于其他变量的值,也可能取决于其他因素。

  2. $(cpp_COMMAND) $< -- compile the source file named by the first prerequisite. $(cpp_COMMAND) $< -- 编译第一个先决条件命名的源文件。 Presumably with a C++ compiler.大概是用 C++ 编译器。

  3. $(cpp_POSTCOMPILE) -- some kind of post-processing, cleanup, or followup step to be performed after compilation. $(cpp_POSTCOMPILE) -- 编译后要执行的某种后处理、清理或后续步骤。 As with the pre-compile step, that could be anything or nothing, with the details depending on other parts of the makefile.与预编译步骤一样,这可以是任何东西,也可以什么都不是,细节取决于 makefile 的其他部分。

  1. When no TARGET is given (default is linux)当没有给出 TARGET 时(默认为 linux)

     make CPU=x86_64 DEBUG=no

    works perfectly.完美地工作。

    But when target=android, it fails.但是当 target=android 时,它失败了。

     make CPU=x86_64 DEBUG=no TARGET=android

TARGET (and DEBUG and CPU ) are details specific to your particular makefile, not features of make generally. TARGET (以及DEBUGCPU )是特定于您的特定 makefile 的详细信息,而不是一般的make功能。 We can't speak to the specifics of their effects.我们无法谈论它们的具体影响。 However, these error messages ...但是,这些错误消息...

 Test.cpp:29:57: fatal error: linux/ethtool.h: No such file or directory compilation terminated. make: *** [../../../makefiles/rules.makefile:1012: android-arm-r/Test.o] Error 1

... present a reasonably clear picture of what the immediate problem is: file Test.cpp , as it is being compiled, attempts to #include a C header file linux/ethtool.h , which file is not found in the cross environment supporting your cross build. ... 对当前的问题有一个相当清晰的描述:文件Test.cpp ,因为它正在被编译,试图#include一个 C 头文件linux/ethtool.h ,该文件在支持的跨环境中找不到你的交叉构建。 That the error does not manifest when you perform a different kind of build is not particularly relevant.当您执行不同类型的构建时,错误没有出现并不是特别相关。

You should review the build requirements documentation for the project.您应该查看项目的构建需求文档。 It may specify particular required packages, which, for a cross build such as you are trying to perform, would probably need to be installed in the cross environment.它可能会指定特定的必需包,对于像您尝试执行的交叉构建,可能需要在交叉环境中安装这些包。 Possibly kernel headers.可能是内核头文件。 You may also want to seek assistance from the maintainers of the project.您可能还想寻求项目维护者的帮助。

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

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