#!/bin/ksh Usage() { myname=${0##*/} print -u2 " Usage: $myname [-h] [-f file] [directory] Find all ELF files in the given directory or optional file list and create a list of libraries used in those files. -f file .. file with a list of files (one at a line) to scan directory .. directory to scan for ELF files " } FLIST="" while getopts "f:h" option ; do case "$option" in "h") Usage; exit 1;; "f") if [ ! -f "$OPTARG" ]; then print -u2 "Unable to read $OPTARG - ignored" else FLIST="$OPTARG" fi ;; esac done X=$((OPTIND-1)) shift $X if [ -z "$1" -a -z "$FLIST" ]; then Usage exit 1 fi # we use a temporary file, since number of files might be > 1024 and thus # bigger than the maximum size of an shell array _TMP=/tmp/x.$$ if [ -n "$FLIST" ]; then cat "$FLIST" >$_TMP else echo >$_TMP fi if [ -n "$1" ]; then if [ ! -e "$1" ]; then print -u2 "$1 does not exist" exit 2 fi find "$1" -type f -print >$_TMP fi echo "REQUIRED LIBRARIES:" echo "-------------------" if [ ! -s $_TMP ]; then echo "none" rm -f $_TMP exit 0 fi cat $_TMP | while read f; do TYPE=$(file $f | cut -f2 -d: | awk '{ print $1 }' ) if [ "$TYPE" = "ELF" ]; then LIBS=$(elfdump -d $f | egrep '(NEEDED)' | awk '{ print $4 }') print "$LIBS" fi done | sort | uniq rm -f $_TMP