#!/bin/bash
# rebuild-gcj-db

# Rebuild all the standard databases.
for base in /usr/lib*; do
   dbLocation=`/usr/bin/gcj-dbtool -p $base`
   libdir=$base/gcj
   if ! test -d $libdir; then
      # No shared libraries here.
      continue
   fi
   dirname $dbLocation | xargs mkdir -p
   /usr/bin/gcj-dbtool -n $dbLocation 64
   find $libdir -follow -name '*.db' | {
      while read dbfile; do
         sofile="${dbfile%.db}.so"
         if [ -e "$sofile" ] && [ 01 -ne 0$(ldd "$sofile" | sed -ne 's,^.*libgcj_bc.so.\([^ ]\).*$,\1,p') ]; then
             continue
         fi
         echo -ne "${dbfile}\x00"
      done; } |
      xargs -0 /usr/bin/gcj-dbtool -m $dbLocation $dbLocation
done
