automake-1.16: Debugging Make Rules

 
 26.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
 (⇒(make)Options Summary), 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 (⇒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.  However, this _still executes_ commands prefixed with ‘+’,
      and, when using GNU ‘make’, commands that contain the strings
      ‘$(MAKE)’ or ‘${MAKE}’ (⇒(make)Instead of Execution).
      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.(1)  Furthermore, note
      that GNU ‘make’ will update prerequisites for the ‘Makefile’ file
      itself even with ‘-n’ (⇒(make)Remaking Makefiles).
 
    • ‘make SHELL="/bin/bash -vx"’ can help debug complex rules.  ⇒
      (autoconf)The Make Macro SHELL, 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 tracing execution, examining
      variables, and calling rules interactively, much like a debugger.
 
    ---------- Footnotes ----------
 
    (1) Automake’s ‘dist’ and ‘distcheck’ rules had a bug in this regard
 in that they created directories even with ‘-n’, but this has been fixed
 in Automake 1.11.