如何debug makefile文件

本文介绍了一些有用的技巧来帮助开发者调试由Automake生成的复杂Makefile文件。包括使用make命令的不同选项来查看详细输出、避免执行实际操作、调试复杂的规则等。还介绍了使用特殊构造来检查变量值的方法,并推荐了一个名为remake的强大调试工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

27.11 Debugging Make Rules

The rules and dependency trees generated by automake can get rather complex, and leave the developer head-scratching when things don’t work as expected. Besides the debug options provided by the make command (see Options Summary inThe GNU Make Manual), here’s a couple of further hints for debugging makefiles generated by automake effectively:

  • If less verbose output has been enabled in the package with the use of silent rules (see Automake Silent Rules), you can use make V=1 to see the commands being executed.
  • make -n can help show what would be done without actually doing it. Note however, that this will still executecommands prefixed with ‘+’, and, when using GNU make, commands that contain the strings ‘$(MAKE)’ or ‘${MAKE}’ (see Instead of Execution in The GNU Make Manual). Typically, this is helpful to show what recursive rules would do, but it means that, in your own rules, you should not mix such recursion with actions that change any files.8Furthermore, note that GNU make will update prerequisites for the Makefile file itself even with -n (see Remaking Makefiles in The GNU Make Manual).
  • make SHELL="/bin/bash -vx" can help debug complex rules. See The Make Macro SHELL in The Autoconf Manual, for some portability quirks associated with this construct.
  • echo 'print: ; @echo "$(VAR)"' | make -f Makefile -f - print can be handy to examine the expanded value of variables. You may need to use a target other than ‘print’ if that is already used or a file with that name exists.
  • http://bashdb.sourceforge.net/remake/ provides a modified GNU make command called remake that copes with complex GNU make-specific Makefiles and allows to trace execution, examine variables, and call rules interactively, much like a debugger.
here are three command-line options I find most useful for debugging:
--just-print
--print-data-base
--warn-undefined-variables
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值