#!/bin/bash
if test -z "$1"; then
  echo "usage: $0 <libname>"
  exit 1
fi
for file in `find /opt/local/lib /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages -name *.dylib -o  -name *.so ; find /opt/local/bin ; find /opt/local/libexec ; find /opt/local/lib/gimp/2.0/plug-ins | grep -v .py ; find /Applications/MacPorts `; do
  # Skip this match if it's a symbolic link
  if test -f $file -a ! -L $file; then
    # Look for references to the missing library
    otool -L $file | grep --silent $1
    if test "$?" = "0"; then
      port provides `echo $file`
    fi
  fi
# Grab the name of the port and make sure to list each port just once
done | awk -F: ' { print $2 " (" $1 } ' | sed -e "s| is provided.*|\)|" | sort -u
