-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrecurse
executable file
·39 lines (39 loc) · 1.47 KB
/
recurse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
#=============================================================================#
# SCRIPT: recurse #
# PURPOSE: Recursively find dependencies of an executable/library using #
# otool -L #
# AUTHOR: Simon Kissane #
# DATE: 6 December 2015 #
# LICENSE: Public Domain #
#=============================================================================#
[ $# -ne 1 ] && {
echo "usage: $0 EXECUTABLE"
exit 1
}
function SetUnion() {
echo -n $(echo $1 $2 | tr ' ' '\n' | sort -u)
}
function SetSize() {
[ -z "$*" ] && echo 0 || echo $(echo $* | tr ' ' '\n' | wc -l)
}
function SetDiff() {
local rx="$(echo $2 | tr ' ' '\n' | sed -e 's/^/^/;s/$/$/;s/+/\\+/g' |
tr '\n' '|' | sed -e 's/|$//')"
echo $1 | tr ' ' '\n' | egrep -v "$rx"
}
TOCHECK="$1"
CHECKED=""
while true; do
TOCHECK_SIZE=$(SetSize $TOCHECK)
[ $TOCHECK_SIZE -eq 0 ] && break
for tc in $TOCHECK; do
DEPS="$(otool -L $tc | fgrep -v ':' | cut '-d(' -f1)"
DEPSNC="$(SetDiff "$DEPS" "$CHECKED")"
TOCHECK="$TOCHECK $DEPSNC"
CHECKED="$CHECKED $tc"
TOCHECK="$(SetDiff "$TOCHECK" "$tc")"
done
done
echo $CHECKED | tr ' ' '\n' | sort -u
# vim:ts=4:sw=4:et:cc=80: