Okay, here's another little script for checking dependencies........
I decided not to use 'ldd' and used 'objdump' instead.........The reason for this is 'ldd' not only returns direct dependencies, but also returns dependencies of dependencies (quite a mouthful, eh), or "indirect" dependencies............The rationale behind this is you only need to worry about dependencies that are called directly by the executable (and not indirectly through one of it's dependencies)...........A proper search will turn up any missing files.........(plus I use 'objdump' for a bit of error-checking)
Code:
#!/bin/sh
#*******************************************************************************
# Name: finddep
#
# Look for binary dependencies by supplying the name of a file or a directory.
# All output goes to the screen.
#
# Some files may return the error message: "File format not recognized". All
# this means is it is not a binary executable or shared object (lib file). It's
# probably a script or other file type.
#
# TIP: When searching a whole directory, you can limit the output to the screen
# by grep'ing for the word "MISSING", like so:
#
# finddep <directory> | grep 'MISSING'
#
# Now, only missing dependencies will be listed on the screen.
#*******************************************************************************
# Check for command line args:
[ $# -ne 1 ] && echo "
Usage: $0 NAME (where NAME can be a file or directory)
" && return 1
find_dep() {
ldd $1 | grep "`$OBJDUMP | grep 'NEEDED' | cut -d' ' -f9`" \
| sed 's/not\ found/MISSING/' | cut -d ' ' -f1,3 | while read dep
do
echo "$1 --> $dep"
done
}
# If a file is supplied on the command line:
[ -f "$1" ] && {
OBJDUMP="objdump -p $1"
# Use 'objdump' for error-checking:
[ "`$OBJDUMP 2>/dev/null`" ] && {
# Look for dependencies:
[ "`$OBJDUMP | grep 'NEEDED'`" ] && {
echo "FILE --> DEPENDENCY LOCATION"
find_dep "$1"
# Use 'column' for a bit of formatting:
} | column -t && echo || echo -e "$1: NO DEPENDENCIES\n" # Didn't find "NEEDED"
} || {
# Using the error message from 'objdump':
$OBJDUMP 2>&1 | cut -d' ' -f2- && echo
}
}
# Otherwise, if a directory is supplied on the command line;
[ -d "$1" ] && printf "FILE \t --> DEPENDENCY\t LOCATION\n" && {
# Ignore subdirectories when parsing files in a directory:
find "$1" -type f -prune | while read d
do {
OBJDUMP="objdump -p $d"
# Use 'objdump' for error-checking:
[ "`$OBJDUMP 2>/dev/null`" ] && {
# Look for dependencies:
[ "`$OBJDUMP | grep 'NEEDED'`" ] && {
find_dep "$d"
# Use 'column' for a bit of formatting:
} | column -t && echo || echo -e "$d: NO DEPENDENCIES\n" # Didn't find "NEEDED"
} || {
# Using the error message from 'objdump':
$OBJDUMP 2>&1 | cut -d' ' -f2- && echo
}
} done
}
The output is also formatted a bit for easier reading, and when searching in directories, subdirectories will be ignored, This is so you can create a list for a single directory...........If you want a recursive search, just place the script in a 'find' command, such as:
find <path> -type d -exec finddep {} \; | grep 'MISSING'
This will search out any missing dependencies............
I plan on expanding this to create a database of dependencies in /var/log/ for Slackware, one for each package installed, much like the "packages" and "scripts" directories in /var/log.......
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
EDIT: Made changes in the find_dep() function to use 'ldd' instead of 'objdump' for searching dependencies.........