automake: Debugging Make Rules

1 
1 27.11 Debugging Make Rules
1 ==========================
1 
1 The rules and dependency trees generated by ‘automake’ can get rather
1 complex, and leave the developer head-scratching when things don’t work
1 as expected.  Besides the debug options provided by the ‘make’ command
1 (⇒(make)Options Summary), here’s a couple of further hints for
1 debugging makefiles generated by ‘automake’ effectively:
1 
1    • If less verbose output has been enabled in the package with the use
1      of silent rules (⇒Automake Silent Rules), you can use ‘make
1      V=1’ to see the commands being executed.
1    • ‘make -n’ can help show what would be done without actually doing
1      it.  Note however, that this will _still execute_ commands prefixed
1      with ‘+’, and, when using GNU ‘make’, commands that contain the
11      strings ‘$(MAKE)’ or ‘${MAKE}’ (⇒(make)Instead of
      Execution).  Typically, this is helpful to show what recursive
1      rules would do, but it means that, in your own rules, you should
1      not mix such recursion with actions that change any files.(1)
1      Furthermore, note that GNU ‘make’ will update prerequisites for the
11      ‘Makefile’ file itself even with ‘-n’ (⇒(make)Remaking
      Makefiles).
11    • ‘make SHELL="/bin/bash -vx"’ can help debug complex rules.  ⇒
      (autoconf)The Make Macro SHELL, for some portability quirks
1      associated with this construct.
1    • ‘echo 'print: ; @echo "$(VAR)"' | make -f Makefile -f - print’ can
1      be handy to examine the expanded value of variables.  You may need
1      to use a target other than ‘print’ if that is already used or a
1      file with that name exists.
1    • <http://bashdb.sourceforge.net/remake/> provides a modified GNU
1      ‘make’ command called ‘remake’ that copes with complex GNU
1      ‘make’-specific Makefiles and allows to trace execution, examine
1      variables, and call rules interactively, much like a debugger.
1 
1    ---------- Footnotes ----------
1 
1    (1) Automake’s ‘dist’ and ‘distcheck’ rules had a bug in this regard
1 in that they created directories even with ‘-n’, but this has been fixed
1 in Automake 1.11.
1