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\|<fsclient\|<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 '/directories/s/$/ [style=filled,fillcolor="#ffffdd"]/' \ 42 | sed '/files/s/$/ [style=filled,fillcolor="#ffdddd"]/' \ 43 | sed '/pipes/s/$/ [style=filled,fillcolor="#ddddff"]/' \ 44 | sed '/mapping/s/$/ [style=filled,fillcolor="#ddffdd"]/' \ 45 | sed '/pages/s/$/ [style=filled,fillcolor="#ddffff"]/' \ 46 | sed '/libmem/s/$/ [style=filled,fillcolor="#dddddd"]/' 47 } 48 49 # Remove this directory as prefix. 50 51 remove_prefix() 52 { 53 QUOTED=`echo "$PKGDIR" | sed 's/\//\\\\\//g'` 54 sed "s/^${QUOTED}\///" 55 } 56 57 58 59 # Main program. 60 61 if [ "$1" = '--with-interfaces' ] ; then 62 WITH_INTERFACES="$1" 63 shift 1 64 else 65 WITH_INTERFACES= 66 fi 67 68 # Directories for processing. 69 70 SOURCES="$PKGDIR/libfsserver $PKGDIR/libmem" 71 72 # Generate prologue. 73 74 cat <<EOF > "$DOTFILE" 75 digraph depgraph { 76 node [fontsize="13.0",fontname="sans-serif"]; 77 edge [fontsize="13.0",fontname="sans-serif"]; 78 79 EOF 80 81 # Generate nodes using source filenames to permit categorisation-based node 82 # colouring. 83 84 for GROUP in "$PKGDIR/libfsserver/lib/"* "$PKGDIR/libmem/lib/src/" ; do 85 if [ ! -d "$GROUP" ] ; then 86 continue 87 fi 88 89 GROUPNAME=`basename "$GROUP"` 90 91 echo "subgraph $GROUPNAME {" >> "$DOTFILE" 92 93 find "$GROUP" -type f -name '*.cc' \ 94 | filter_interfaces \ 95 | remove_prefix \ 96 | colour_sources \ 97 | select_basenames \ 98 | sed 's/\.cc//' \ 99 | sed 's/^/ /;s/$/;/' \ 100 >> "$DOTFILE" 101 102 echo "}" >> "$DOTFILE" 103 done 104 105 # Generate header file relationships. 106 # Find header files. 107 # Obtain include statements. 108 # Remove interface references unless indicated. 109 # Remove various library references. 110 # Obtain basenames for header filenames. 111 # Rewrite include references, producing edges between nodes. 112 113 find $SOURCES -maxdepth 4 -name '*.h' \ 114 | xargs -I{} grep -H include '{}' \ 115 | filter_interfaces \ 116 | filter_libraries \ 117 | select_basenames \ 118 | sed 's/<.*\///g;s/<//g;s/>//g;s/"//g;s/\.h//g;s/:#include / -> /;s/^/ /;s/$/;/' \ 119 >> "$DOTFILE" 120 121 # Generate epilogue. 122 123 cat <<EOF >> "$DOTFILE" 124 } 125 EOF 126 127 # Produce the SVG output. 128 129 dot -Tsvg -o "$SVGFILE" "$DOTFILE" 130 131 # vim: tabstop=4 expandtab shiftwidth=4