1 #!/bin/sh 2 3 THISDIR=`dirname "$0"` 4 PKGDIR=`realpath "$THISDIR/../.."` 5 DOCS=`realpath "$THISDIR/.."` 6 7 DOTFILE="$DOCS/depgraph.dot" 8 SVGFILE="$DOCS/depgraph.svg" 9 10 11 12 # Filter interface header files. 13 14 filter_interfaces() 15 { 16 if [ "$WITH_INTERFACES" ] ; then 17 tee 18 else 19 grep -v '_interface.h' 20 fi 21 } 22 23 # Filter library headers. 24 25 filter_libraries() 26 { 27 grep -v '<l4\|<systypes\|<std\|<list>\|<map>\|<mutex>\|<condition_variable>\|<string>\|<set>\|<vector>' 28 } 29 30 # Select basenames in search result filenames. 31 32 select_basenames() 33 { 34 sed 's/[^:]*\/\([^:]*\)/\1/' 35 } 36 37 # Colour nodes by source category. 38 39 colour_sources() 40 { 41 sed '/files/s/$/ [style=filled,fillcolor="#ffdddd"]/' \ 42 | sed '/pipes/s/$/ [style=filled,fillcolor="#ddddff"]/' \ 43 | sed '/mapping/s/$/ [style=filled,fillcolor="#ddffdd"]/' \ 44 | sed '/pages/s/$/ [style=filled,fillcolor="#ddffff"]/' \ 45 | sed '/libmem/s/$/ [style=filled,fillcolor="#dddddd"]/' 46 } 47 48 # Remove this directory as prefix. 49 50 remove_prefix() 51 { 52 QUOTED=`echo "$PKGDIR" | sed 's/\//\\\\\//g'` 53 sed "s/^${QUOTED}\///" 54 } 55 56 57 58 # Main program. 59 60 if [ "$1" = '--with-interfaces' ] ; then 61 WITH_INTERFACES="$1" 62 shift 1 63 else 64 WITH_INTERFACES= 65 fi 66 67 # Directories for processing. 68 69 SOURCES="$PKGDIR/libfsserver $PKGDIR/libmem" 70 71 # Generate prologue. 72 73 cat <<EOF > "$DOTFILE" 74 digraph depgraph { 75 node [fontsize="13.0",fontname="sans-serif"]; 76 edge [fontsize="13.0",fontname="sans-serif"]; 77 78 EOF 79 80 # Generate nodes using source filenames to permit categorisation-based node 81 # colouring. 82 83 find $SOURCES -maxdepth 4 -name '*.cc' \ 84 | filter_interfaces \ 85 | remove_prefix \ 86 | colour_sources \ 87 | select_basenames \ 88 | sed 's/\.cc//' \ 89 | sed 's/^/ /;s/$/;/' \ 90 >> "$DOTFILE" 91 92 # Generate header file relationships. 93 # Find header files. 94 # Obtain include statements. 95 # Remove interface references unless indicated. 96 # Remove various library references. 97 # Obtain basenames for header filenames. 98 # Rewrite include references, producing edges between nodes. 99 100 find $SOURCES -maxdepth 4 -name '*.h' \ 101 | xargs -I{} grep -H include '{}' \ 102 | filter_interfaces \ 103 | filter_libraries \ 104 | select_basenames \ 105 | sed 's/<.*\///g;s/<//g;s/>//g;s/"//g;s/\.h//g;s/:#include / -> /;s/^/ /;s/$/;/' \ 106 >> "$DOTFILE" 107 108 # Generate epilogue. 109 110 cat <<EOF >> "$DOTFILE" 111 } 112 EOF 113 114 # Produce the SVG output. 115 116 dot -Tsvg -o "$SVGFILE" "$DOTFILE" 117 118 # vim: tabstop=4 expandtab shiftwidth=4