gen-dependencies.sh 927 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2012 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. SELF=${0##*/}
  9. READELF="${READELF:-readelf}"
  10. OBJCOPY="${OBJCOPY:-objcopy}"
  11. TARGETS=$*
  12. XARGS="${XARGS:-xargs -r}"
  13. [ -z "$TARGETS" ] && {
  14. echo "$SELF: no directories / files specified"
  15. echo "usage: $SELF [PATH...]"
  16. exit 1
  17. }
  18. find $TARGETS -type f -a -exec file {} \; | \
  19. sed -n -e 's/^\(.*\):.*ELF.*\(executable\|shared object\).*,.*/\1/p' | \
  20. $XARGS -n1 $READELF -d | \
  21. awk '$2 ~ /NEEDED/ && $NF !~ /interpreter/ && $NF ~ /^\[?lib.*\.so/ { gsub(/[\[\]]/, "", $NF); print $NF }' | \
  22. sort -u
  23. tmp=$(mktemp $TMP_DIR/dep.XXXXXXXX)
  24. for kmod in $(find $TARGETS -type f -name \*.ko); do
  25. $OBJCOPY -O binary -j .modinfo $kmod $tmp
  26. sed -e 's,\x00,\n,g' $tmp | \
  27. sed -ne '/^depends=.\+/ { s/^depends=//; s/,/.ko\n/g; s/$/.ko/p; q }'
  28. done | sort -u
  29. rm -f $tmp