#!/bin/bash if [ $# -lt 2 ]; then echo "Usage: $0 " exit 1 fi # Color for things that depend on X X11Color=orange # Shape for exectuables ExecShape=box of="$1" shift function deplist { ldd $1 | fgrep -v ' /usr' | fgrep -v ' /lib' | fgrep = | cut -d '=' -f 1 | sed -e "s/\.[0-9]//" -e "s/\.[0-9]//" -e "s/^\s*//" } function fdeplist { ldd $1 | fgrep -v ' /usr' | fgrep -v ' /lib' | fgrep = | cut -d ' ' -f 3 } echo 'digraph "Library Dependencies" {' > $of echo 'size="10,8";' >> $of for file in "$@"; do b=`basename $file .so` echo "$file" >&2 # Check if file depends on X if ldd $file | fgrep libX11 > /dev/null; then echo "$b [color=$X11Color]" >> $of fi # Check if executable rather than lib if file $file | fgrep executable > /dev/null; then echo "$b [shape=$ExecShape]" >> $of fi # Get indirect dependencies indirect="" for dep in `fdeplist $file`; do tmp=`deplist $dep` indirect="$indirect $tmp" done for dep in `deplist $file`; do found=0 for dep2 in $indirect; do if [ $dep2 = $dep ]; then found=1 break fi done if [ $found = 0 ]; then d=`basename $dep .so` echo "$b -> $d;" >> $of fi done done echo "}" >> $of echo "Generate graph with command similar to: dot -Tps $of > $of.ps"