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