记录调用的 make 命令

发布于 2024-08-24 12:53:39 字数 129 浏览 3 评论 0原文

有没有办法记录命令、make 调用来编译程序?我知道参数 -n-p,但它们要么不解析 if 条件,而只是将其打印出来。或者,当 Makefile 中调用“make”本身时,它们不起作用。

Is there a way to log the commands, make invokes to compile a program? I know of the parameters -n and -p, but they either don't resolve if-conditions but just print them out. Or they don't work, when there are calls to 'make' itself in the Makefile.

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

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

发布评论

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

评论(5

ζ澈沫 2024-08-31 12:53:39

make SHELL="sh -x -e"

将导致 shell(make 调用来评估 shell 构造)打印有关其正在执行的操作的信息,让您了解如何评估 shell 命令中的任何条件。

-e 对于确保正确检测 Makefile 目标中的错误并返回非零进程退出代码是必要的。

This

make SHELL="sh -x -e"

will cause the shell (which make invokes to evaluate shell constructs) to print information about what it's doing, letting you see how any conditionals in shell commands are being evaluated.

The -e is necessary to ensure that errors in a Makefile target will be properly detected and a non-zero process exit code will be returned.

浅沫记忆 2024-08-31 12:53:39

您可以尝试使用 strace 记录 execve 调用

strace -f -e execve make ...

You could try to log execve calls with strace

strace -f -e execve make ...
泪痕残 2024-08-31 12:53:39

Make 将其执行的每个命令写入控制台,因此

make 2>&1 | tee build.log

将创建一个名为 build.log 的日志文件作为副作用,其中包含写入屏幕的相同内容。 (man tee 了解更多详细信息。)

2>&1 将标准输出和错误合并到一个流中。如果不包含它,常规输出将进入日志文件,但错误只会进入控制台。 (make 仅在命令返回错误代码时写入 stderr。)

如果您想完全抑制输出以记录到文件,则更简单:

make 2>&1 > build.log

因为这些只是捕获控制台输出,所以它们只工作可以使用递归make

Make writes each command it executes to the console, so

make 2>&1 | tee build.log

will create a log file named build.log as a side effect which contains the same stuff written to the screen. (man tee for more details.)

2>&1 combines standard output and errors into one stream. If you didn't include that, regular output would go into the log file but errors would only go to the console. (make only writes to stderr when a command returns an error code.)

If you want to suppress output entirely in favor of logging to a file, it's even simpler:

make 2>&1 > build.log

Because these just capture console output they work just fine with recursive make.

不爱素颜 2024-08-31 12:53:39

您可能会在 SparkBuild 生成的带注释的构建日志中找到所需内容。这包括构建中执行的每个规则的命令,无论是否使用“@”来阻止 make 打印命令行。

不过,您对 if 条件的评论有点令人困惑:您是在谈论 shell 构造还是 make 构造?如果您指的是 shell 构造,我认为除了像其他人描述的那样使用 strace 之外,没有任何方法可以让您准确地得到您想要的东西。如果您指的是 make 构造,那么您看到的输出就是已解析条件表达式的结果。

You might find what you're looking for in the annotated build logs produced by SparkBuild. That includes the commands of every rule executed in the build, whether or not "@" was used to prevent make from printing the command-line.

Your comment about if-conditions is a bit confusing though: are you talking about shell constructs, or make constructs? If you mean shell constructs, I don't think there's any way for you to get exactly what you're after except by using strace as others described. If you mean make constructs, then the output you see is the result of the resolved conditional expression.

我不咬妳我踢妳 2024-08-31 12:53:39

您是否尝试过使用 -d 参数(调试)?

请注意,您可以使用 --debug 来控制信息量。例如,--debug=a(与-d相同),或--debug=b仅显示基本信息...

Have you tried with the -d parameter (debug)?

Note that you can control the amount of infos with --debug instead. For instance, --debug=a (same as -d), or --debug=b to show only basic infos...

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