blob: 4beff74bb0221aa2b5b545b66d2417777cfe5e36 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/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#
8SELF=${0##*/}
9
10READELF="${READELF:-readelf}"
11OBJCOPY="${OBJCOPY:-objcopy}"
12TARGETS=$*
13XARGS="${XARGS:-xargs -r}"
14
15[ -z "$TARGETS" ] && {
16 echo "$SELF: no directories / files specified"
17 echo "usage: $SELF [PATH...]"
18 exit 1
19}
20
21find $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
27tmp=$(mktemp $TMP_DIR/dep.XXXXXXXX)
28for 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 }'
32done | sort -u
33rm -f $tmp