mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

  1. export irfs_libexec_functions=1
  2. # find dynamic (share library) dependencies for a binary
  3. # honors $rootdir and emulates sort of chroot therin
  4. needed_libs() {
  5. local x y z library libqueue liblist libdirs
  6. # be sure to favor the 64bit locations
  7. libdirs="$rootdir/lib64 $rootdir/usr/lib64 $rootdir/lib"
  8. for N in `sed -e"s,^,${rootdir}," ${rootdir}/etc/ld.so.conf | tr '\n' ' '` ; do
  9. [ -d "$N" ] && libdirs="$libdirs $N"
  10. done
  11. libqueue="$( mktemp -t libqueue-XXXXXX )"
  12. liblist="$( mktemp -d -t liblist-XXXXXX )"
  13. # initialize the queue with $*
  14. for x ; do
  15. echo "$rootdir/$x"
  16. done > "$libqueue"
  17. # get the required libraries of each file
  18. while read y ; do
  19. ${cross_compile}readelf -d "${y}" 2>/dev/null | grep "(NEEDED)" |
  20. sed -e "s,.*Shared library: \[\(.*\)\],\1," |
  21. while read library ; do
  22. [ -e "$liblist/$library" ] && continue
  23. # use the first library with this name
  24. find -L ${libdirs} -maxdepth 1 -name "${library}" 2>/dev/null |
  25. head -n1 |
  26. while read z ; do
  27. # put the libraries found into the queue, because they might
  28. # require other libraries themselves
  29. echo "$z" >> "$libqueue"
  30. echo "$z" | sed -e"s,^${rootdir},,"
  31. done
  32. # list this library as processed
  33. touch "$liblist/$library"
  34. done
  35. done < "$libqueue"
  36. rm -f "$libqueue" ; rm -rf "$liblist"
  37. }
  38. # add a file ($1) to the contents-list of initramfs
  39. # optionally you can give a different destination filename
  40. # in $2
  41. # the output is a gen_init_cpio compatible list including all
  42. # dynamic dependencies and the file itself.
  43. add_with_deps() {
  44. srcname=$1 ; shift
  45. dstname=$srcname
  46. [ -n "$1" ] && dstname=$1
  47. echo "file $dstname $rootdir/$srcname 755 0 0"
  48. needed_libs $srcname | while read lib
  49. do
  50. echo "file $lib $rootdir/$lib 755 0 0"
  51. done
  52. }
  53. export -f needed_libs
  54. export -f add_with_deps