我有一个非常复杂的遗留代码库,其中包含大量变量的复杂makefile。 有时我需要更改它们,但我发现很难弄清楚为什么更改不按照我的预期工作。 我想找到的是一种基本上可以逐步执行“make”过程的工具,我会向它提供一个目录,并且能够在过程的不同点看到不同变量的值。 虽然可能我漏掉了某些东西,但是make的所有调试标志似乎都没有显示我想要的内容。 有人知道如何做到这一点吗?
您是否一直在查看运行make -n
和make -np
以及重要命令make -nd
的输出结果?
您是否正在使用相对较新的gmake
版本?
您是否查看了O'Reilly网站上免费章节Debugging Makefiles,该章节来自他们出色的著作《Managing Projects with GNU Make》(Amazon链接)?
从make命令行选项的man页中:
-n, --just-print, --dry-run, --recon
Print the commands that would be executed, but do not execute them.
-d Print debugging information in addition to normal processing.
The debugging information says
which files are being considered for remaking,
which file-times are being compared and with what results,
which files actually need to be remade,
which implicit rules are considered and which are applied---
everything interesting about how make decides what to do.
--debug[=FLAGS] Print debugging information in addition to normal processing.
If the FLAGS are omitted, then the behaviour is the same as if -d was specified.
FLAGS may be:
'a' for all debugging output same as using -d,
'b' for basic debugging,
'v' for more verbose basic debugging,
'i' for showing implicit rules,
'j' for details on invocation of commands, and
'm' for debugging while remaking makefiles.
--print-data-base听起来可能很有用。
remake --debugger all可以用于启用所有调试器。
有一个 GNU make 调试器项目 http://gmd.sf.net 看起来非常有用。gmd 支持的主要功能是断点,这可能比单步执行更有用。要使用它,您需要从 http://gmd.sf.net 下载 gmd 和从 http://gmsl.sf.net 下载 gmsl,在您的 makefile 中执行 'include gmd'。