# HG changeset patch # User Paul Boddie # Date 1618521351 -7200 # Node ID 42f3edfaeb7ba2ad77c69029abae8c2d3099ff54 # Parent b6dab1e89e3c6b1bcd42bee06c4ec669a60e94ea Added a header dependency graph generation tool. diff -r b6dab1e89e3c -r 42f3edfaeb7b docs/tools/depgraph --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/tools/depgraph Thu Apr 15 23:15:51 2021 +0200 @@ -0,0 +1,73 @@ +#!/bin/sh + +THISDIR=`dirname "$0"` +PKGDIR=`realpath "$THISDIR/../.."` +DOCS=`realpath "$THISDIR/.."` + +DOTFILE="$DOCS/depgraph.dot" +SVGFILE="$DOCS/depgraph.svg" + + + +# Filter interface header files. + +filter_interfaces() +{ + if [ "$WITH_INTERFACES" ] ; then + tee + else + grep -v '_interface.h' + fi +} + + + +# Main program. + +if [ "$1" = '--with-interfaces' ] ; then + WITH_INTERFACES="$1" + shift 1 +else + WITH_INTERFACES= +fi + +# Directories for processing. + +SOURCES="$PKGDIR/libfsserver $PKGDIR/libmem" + +# Generate prologue. + +cat < "$DOTFILE" +digraph depgraph { + node [fontsize="13.0",fontname="sans-serif"]; + edge [fontsize="13.0",fontname="sans-serif"]; + +EOF + +# Generate header file relationships. +# Find header files. +# Obtain include statements. +# Remove interface references unless indicated. +# Remove various library references. +# Obtain basenames for header filenames. +# Rewrite include references, producing edges between nodes. + + find $SOURCES -maxdepth 4 -name '*.h' \ +| xargs -I{} grep -H include '{}' \ +| filter_interfaces \ +| grep -v '\|\|\|' \ +| sed 's/[^:]*\/\([^:]*\)/\1/' \ +| sed 's/<.*\///g;s///g;s/"//g;s/\.h//g;s/:#include / -> /;s/^/ /;s/$/;/' \ +>> "$DOTFILE" + +# Generate epilogue. + +cat <> "$DOTFILE" +} +EOF + +# Produce the SVG output. + +dot -Tsvg -o "$SVGFILE" "$DOTFILE" + +# vim: tabstop=4 expandtab shiftwidth=4