過日のスクリプトを少々修正 / 注意

実働部分を改めました。 動作が速くなれば助かります。

#! /bin/sh

usage()
{
	cat <<EOF
Usage: `basename $0` [OPTION] [PORTNAME]
Option:
	[-v|--verbose] : show results of \`ldd -a\`
Portname:
	It should be a full name.  If you give a portion,
	this script gives some suggestion.
EOF
	exit $1
}

if test $# -eq 0; then
	usage 1 1>&2
fi

verbose=false

while test $# -gt 1; do
	case "$1" in
	-v|--verbose)
		verbose=true
		;;
	esac
	shift
done
dir=$1

contfile=/var/db/pkg/${dir}/+CONTENTS
if [ ! -e ${contfile} ]; then
	candidate=`(cd /var/db/pkg/; ls -d ${dir}*)`
	if [ "" != "${candidate}" ]; then
		echo "Which port?: " ${candidate}
	fi
	exit
fi

base=`head ${contfile} | grep @cwd | sed 's,@cwd ,,'`
for item_file in `grep -v @ ${contfile}`
	do if [ "" != "`file ${base}/${item_file} | grep ELF`" ]; then
		if ${verbose}; then
			blame=`ldd -a ${base}/${item_file} | grep -E "^/usr/|not found" \
				| grep -B1 "not found"`
			if [ "" != "${blame}" ]; then
				printf "########## %s\n%s\n" "${item_file}" "${blame}"
			fi
		else
			blame=`ldd ${base}/${item_file} | grep "not found" | sort | uniq`
			if [ "" != "${blame}" ]; then
				echo ${item_file}:${blame}
			fi
		fi
	fi; done

潜む危険

ライブラリの依存問題は回避できていない可能性があります。 旧いライブラリと新しいライブラリに両方対応するために条件コンパイルを行なっているソフトウェアだと、 この回避方法では旧いライブラリの function を呼び出そうとして失敗する危険があるはずです。 使用時に問題が起こったらビルドしなおすつもりです。