调试Makefile的工具

88

我有一个非常复杂的遗留代码库,其中包含大量变量的复杂makefile。 有时我需要更改它们,但我发现很难弄清楚为什么更改不按照我的预期工作。 我想找到的是一种基本上可以逐步执行“make”过程的工具,我会向它提供一个目录,并且能够在过程的不同点看到不同变量的值。 虽然可能我漏掉了某些东西,但是make的所有调试标志似乎都没有显示我想要的内容。 有人知道如何做到这一点吗?

6个回答

81

您是否一直在查看运行make -nmake -np以及重要命令make -nd的输出结果?

您是否正在使用相对较新的gmake版本?

您是否查看了O'Reilly网站上免费章节Debugging Makefiles,该章节来自他们出色的著作《Managing Projects with GNU Make》(Amazon链接)?


40

我确信你需要的是remake

从主页可以看到:

remake是GNU make实用程序的修补和现代化版本,它增加了改进的错误报告、以易于理解的方式跟踪执行以及调试器。

它具有类似gdb的界面,并且得到了(x)emacs中mdb-mode的支持,这意味着断点、监视等功能。如果您不喜欢(x)emacs,则可以使用DDD


2
如果可以的话,我会加上+100。使用remake('brew install remake'进行安装)时,我需要调试的问题就消失了。不知道问题是什么,但谁在乎呢? :) - ishahak

22

从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.  

6
我不知道有哪个特定的标志可以完全满足你的要求,但是
--print-data-base
听起来可能很有用。

4

0

有一个 GNU make 调试器项目 http://gmd.sf.net 看起来非常有用。gmd 支持的主要功能是断点,这可能比单步执行更有用。要使用它,您需要从 http://gmd.sf.net 下载 gmd 和从 http://gmsl.sf.net 下载 gmsl,在您的 makefile 中执行 'include gmd'。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接