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