summaryrefslogtreecommitdiffstats
path: root/kpilot/Documentation/checkPlugin.sh
blob: bc0b840c779d39920f128a004afa40b591c48bc1 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /bin/sh
##
## checkPlugin.sh
##
## Copyright (C) 2002 by Adriaan de Groot
##
## Distributed under the GNU General Public License (GPL) Version 2.
##

##
## Usage: checkPlugin.sh <app-path> <plugin-path> [<extra-lib> ...]
##
## <app-path> :    path to the application that will be loading the
##                 plugin. This is used to get the list of library
##                 dependencies.
## <plugin-path> : path to the plugin (.so) that will be loaded.
## <extra-lib> :   paths to additional libraries to get defined symbols from.
##

USAGE="Usage: checkPlugin.sh <app-path> <plugin-path> [<extra-lib> ...]"

UNDEF_RE="^ *U "
DEF_RE="^[0-9a-fA-F]* [TdWBVDR] "
TMP="/tmp/$$"

APP_PATH="$1"
PLUGIN_PATH="$2"

test -z "$APP_PATH" && echo "$USAGE"
test -z "$APP_PATH" && exit 1
test -f "$APP_PATH" || echo "$USAGE"
test -f "$APP_PATH" || exit 1

test -z "$PLUGIN_PATH" && echo "$USAGE"
test -z "$PLUGIN_PATH" && exit 1
test -f "$PLUGIN_PATH" || echo "$USAGE"
test -f "$PLUGIN_PATH" || exit 1

shift 2

if nm --demangle "$PLUGIN_PATH" > "$TMP-1" ; then
	echo `wc -l < "$TMP-1"` "symbols in $PLUGIN_PATH"
else
	echo "nm failed on $PLUGIN_PATH"
	exit 1
fi

cat "$TMP-1" | grep "$UNDEF_RE" | sed "s/$UNDEF_RE//" | sort > "$TMP-undef"

T=`ldd "$APP_PATH" | grep -v "$APP_PATH" | grep -v "not found" | sed -e 's/.*=> //' -e 's/ (.*) *$//' | sort | uniq`

for LIBF in $T $* ; do
	test -f "$LIBF" || echo "$LIBF: Not found"
	test -f "$LIBF" || exit 1

	if nm --demangle "$LIBF" > "$TMP-2" 2> /dev/null ; then
		nm --demangle --dynamic "$LIBF" >> "$TMP-2" 2> /dev/null
		# echo `wc -l < "$TMP-2"` "symbols defined in $LIBF"
	else
		echo "nm failed on $LIBF"
		exit 1
	fi

	cat "$TMP-2" | grep "$DEF_RE" | sed "s/$DEF_RE//" | sort | uniq > "$TMP-def"
	cat "$TMP-undef" "$TMP-def" | sort | uniq -d > "$TMP-now-defined"
	cat "$TMP-undef" "$TMP-now-defined" | sort | uniq -u > "$TMP-still"

	echo `wc -l < "$TMP-now-defined"` "symbols resolved by $LIBF"
	
	cat "$TMP-still" > "$TMP-undef"
done

echo `wc -l < "$TMP-undef"` "undefined symbols remain"

cat "$TMP-undef"

rm -f "$TMP" "$TMP-1" "$TMP-2" "$TMP-undef" "$TMP-def" "$TMP-now-defined" "$TMP-still"