如何跟踪 Makefile 行号以进行故障排除?

jww*_*jww 5 makefile gnu-make

这与如何跟踪 Makefile 目标进行故障排除有关?我正在使用旧的 PowerMac G5。它之所以存在,是因为我用它来测试较旧的编译器和大端、PowerPC。

我试图确定 makefile 中的哪一行导致了unexpected EOF while looking for matching ``'. 我们的makefile 不使用反引号(我们添加它们是为了测试这个问题);对于具有 1000 行的 makefile 来说,尝试/错误和猜测的速度太慢。

当我运行 make with 时--debug,它无法打印行号:

$ make --debug=a
GNU Make 3.82
Built for powerpc-apple-darwin9.8.0
...

Reading makefiles...
Reading makefile `GNUmakefile'...
bash: -c: line 0: unexpected EOF while looking for matching ``'
bash: -c: line 1: syntax error: unexpected end of file
bash: -c: line 0: unexpected EOF while looking for matching ``'
bash: -c: line 1: syntax error: unexpected end of file
bash: -c: line 0: unexpected EOF while looking for matching ``'
bash: -c: line 1: syntax error: unexpected end of file
bash: -c: line 0: unexpected EOF while looking for matching ``'
bash: -c: line 1: syntax error: unexpected end of file
Updating makefiles...
...
Run Code Online (Sandbox Code Playgroud)

make --help似乎没有讨论它:

$ make --help 2>&1 | grep -i line
$
Run Code Online (Sandbox Code Playgroud)

我的第一个问题是,如何告诉 GNU make 打印行号?

我的第二个问题是,一个自 make 以来就存在的程序在调试支持方面怎么会如此蹩脚?

Bas*_*tch 1

您可以尝试make --trace(至少使用GNU make 4),或考虑使用remake(能够调试的变体make),如remake -x.

对于调试复杂的Makefile-s,使用remake非常方便

您可以考虑使用其他构建自动化工具,例如ninja

如果您使用GNU make,您最好将其升级到较新的版本(并在配置时启用Guile扩展)。

Linux:找到 ./makefile_dir -mtime -10,查看哪个文件更改了:foo.c,然后 grep -n foo.c Makefile 并查看 Makefile 中的行号