b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 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 | |
| 10 | READELF="${READELF:-readelf}" |
| 11 | OBJCOPY="${OBJCOPY:-objcopy}" |
| 12 | TARGETS=$* |
| 13 | XARGS="${XARGS:-xargs -r}" |
| 14 | |
| 15 | [ -z "$TARGETS" ] && { |
| 16 | echo "$SELF: no directories / files specified" |
| 17 | echo "usage: $SELF [PATH...]" |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | find $TARGETS -type f -a -exec file {} \; | \ |
| 22 | sed -n -e 's/^\(.*\):.*ELF.*\(executable\|shared object\).*,.*/\1/p' | \ |
| 23 | $XARGS -n1 $READELF -d | \ |
| 24 | awk '$2 ~ /NEEDED/ && $NF !~ /interpreter/ && $NF ~ /^\[?lib.*\.so/ { gsub(/[\[\]]/, "", $NF); print $NF }' | \ |
| 25 | sort -u |
| 26 | |
| 27 | tmp=$(mktemp $TMP_DIR/dep.XXXXXXXX) |
| 28 | for kmod in $(find $TARGETS -type f -name \*.ko); do |
| 29 | $OBJCOPY -O binary -j .modinfo $kmod $tmp |
| 30 | sed -e 's,\x00,\n,g' $tmp | \ |
| 31 | sed -ne '/^depends=.\+/ { s/^depends=//; s/,/.ko\n/g; s/$/.ko/p; q }' |
| 32 | done | sort -u |
| 33 | rm -f $tmp |