gen-dependencies.sh 969 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  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\).*,.* stripped/\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. egrep -a '^depends=' | \
  28. sed -e 's,^depends=,,' -e 's/,/\n/g' | \
  29. awk '{ print $1 ".ko" }'
  30. done | sort -u
  31. rm -f $tmp