Wiki:visualise_makefile
zuletzt geändert vor 4 Jahre zuletzt geändert am 13.11.2008 23:16:39

Makefile-Abhängigkeiten visualisieren

Ich (Alexander Kriegisch) habe lange nichts mehr gemacht für Freetz, aber heute möchte ich der Allgemeinheit mal wieder ein kleines Werkzeug zur Verfügung stellen, das nicht nur für Freetz nützlich ist, sondern allgemein mehr Transparenz in Makefiles (getestet mit GNU Make) bringt: das Skript tools/visualise_make. In Verbindung mit dem Perl-Helferskript tools/visualise_make.pl, welches wiederum aufbaut auf dem (unbedingt zuvor samt Abhängigkeiten zu installierenden) Perl-Modul Makefile::GraphViz, können Makefile-Abhängigkeiten graphisch dargestellt werden. GNU Make nennt das einen Abhängigkeits-Graphen (engl. "dependency graph"). Einige Beispiele befinden sich in den Dateianhängen.

Wenn man das Hauptskript mit

tools/visualise_make -? | more

aufruft, erhält man eine ausführliche Hilfe:

visualise_make - create PNG image visualising a Make target's dependency graph

Usage: visualise_make [options] target [log-target]
  -?          print this usage help
  -a [lfica]  perform specified actions (default: lfi)
     l        create log via "make -p"
     f        filter log as a preparation for visualisation
     i        create dependency graph image for specified target
     c        clean up: delete log and filtered file before exiting
     a        all: equal to "lfic"
  -l <file>   log file name (default: visualise_make.log); contains complete
              output of: LC_ALL=C make -j1 -pns log-target
  -f <file>   filtered log file name (default: visualise_make.flt); contains only the
              main makefile's targets (no sub-makefile contents in case of 
              recursive make calls) without variables, implicit rules,
              actions, comments etc., i.e. just the data needed for the
              dependency graph
  -i <file>   alternative image file name (default: <target>.png, but dots,
              spaces and slashes in target names will be replaced by
              underscores, condensing consecutive underscores to one, i.e.
              target "../src/foo_/bar/zot.h" becomes image file name
              "_src_foo_bar_zot_h.png")
  target      target to be visualised, resulting in <target>.png (mandatory)
  log-target  target for log file creation (optional); default: none, i.e.
              makefile's default target (usually "all"); specify only if you
              wish to create the log-file from a target other than the
              default one.

Examples:
  visualise_make my_target
      create + filter log file, possibly overwriting existing *.log, *.flt
      files; then create my_target.png containing visual representation of
      my_target's dependency graph; do not delete *.log, *.flt so they can be
      re-used with another target
  visualise_make -a i my_other_target
      create my_other_target.png, re-using existing visualise_make.flt
  visualise_make -a fi -l my_dir/saved_make.log -i graph-03.png my_3rd_target
      filter existing make log into visualise_make.flt, then create
      graph-03.png for specified target
  visualise_make -a a -l make.log -f make.flt my_target big_target
      create + filter log file, using custom file names make.log, make.flt,
      but do not use default make target for log file creation, but big_target;
      then create visual representation of my_target's dependency graph;
      finally, clean up make.log, make.flt
  visualise_make -a c
      delete visualise_make.log and visualise_make.flt, do nothing else
  visualise_make -?
      print usage help

Hints for creating custom log files:
  - You may create your own make logs via "make -p".
  - If so, take care to use "-j1" so as to get a clean log file with
    sequential entries. Multi-threaded make may create garbled output.
    If your makefile contains -j2 or greater, change it there temporarily,
    because the command line switch might not override the makefile setting.
  - If you just want to simulate a make run in order to create a log file,
    but do not want to actually build files, use "make -n" (dry-run).
    Combined with log output generation this would be "make -pn".
  - This tool can only filter English make logs, so please use
    "LC_ALL=C make ..." so as to avoid locale-specific output.
  - This tool only works well for top-level makefiles, so if you have a
    build system using recursive make calls, just modify the desired
    sub-build's "make" call so as to create a log file of its own,
    subsequently filtering it by
        visualise_make -a fi -l custom_make.log my_target
    The reason it does not work for recursive make is that target names can
    repeat themselves (e.g. often-used standard targets like all, install,
    clean, menuconfig, distclean). To avoid problems, the filter action
    always eliminates sub-make output when creating *.flt from *.log.

Auch ein Blick in die Skripten selbst kann nicht schaden.

Anhänge