|
|
export irfs_libexec_functions=1
|
|
|
|
# find dynamic (share library) dependencies for a binary
|
|
# honors $rootdir and emulates sort of chroot therin
|
|
needed_libs() {
|
|
local x y z library libqueue liblist libdirs
|
|
|
|
# be sure to favor the 64bit locations
|
|
libdirs="$rootdir/lib64 $rootdir/usr/lib64 $rootdir/lib"
|
|
for N in `sed -e"s,^,${rootdir}," ${rootdir}/etc/ld.so.conf | tr '\n' ' '` ; do
|
|
[ -d "$N" ] && libdirs="$libdirs $N"
|
|
done
|
|
|
|
libqueue="$( mktemp -t libqueue-XXXXXX )"
|
|
liblist="$( mktemp -d -t liblist-XXXXXX )"
|
|
|
|
# initialize the queue with $*
|
|
for x ; do
|
|
echo "$rootdir/$x"
|
|
done > "$libqueue"
|
|
|
|
# get the required libraries of each file
|
|
while read y ; do
|
|
${cross_compile}readelf -d "${y}" 2>/dev/null | grep "(NEEDED)" |
|
|
sed -e "s,.*Shared library: \[\(.*\)\],\1," |
|
|
while read library ; do
|
|
[ -e "$liblist/$library" ] && continue
|
|
|
|
# use the first library with this name
|
|
find -L ${libdirs} -maxdepth 1 -name "${library}" 2>/dev/null |
|
|
head -n1 |
|
|
while read z ; do
|
|
# put the libraries found into the queue, because they might
|
|
# require other libraries themselves
|
|
echo "$z" >> "$libqueue"
|
|
echo "$z" | sed -e"s,^${rootdir},,"
|
|
done
|
|
|
|
# list this library as processed
|
|
touch "$liblist/$library"
|
|
done
|
|
done < "$libqueue"
|
|
rm -f "$libqueue" ; rm -rf "$liblist"
|
|
}
|
|
|
|
# add a file ($1) to the contents-list of initramfs
|
|
# optionally you can give a different destination filename
|
|
# in $2
|
|
# the output is a gen_init_cpio compatible list including all
|
|
# dynamic dependencies and the file itself.
|
|
add_with_deps() {
|
|
srcname=$1 ; shift
|
|
dstname=$srcname
|
|
[ -n "$1" ] && dstname=$1
|
|
|
|
echo "file $dstname $rootdir/$srcname 755 0 0"
|
|
needed_libs $srcname | while read lib
|
|
do
|
|
echo "file $lib $rootdir/$lib 755 0 0"
|
|
done
|
|
}
|
|
|
|
export -f needed_libs
|
|
export -f add_with_deps
|