-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib_ldscript
executable file
·41 lines (38 loc) · 1012 Bytes
/
lib_ldscript
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
#!/bin/bash
# Update libs for GNU ld scripts
# Assumes that the binary is the first indicated in whereis
# and the references are part of "GROUP"
# depends on: whereis, sed, file, basename
shortname () {
echo -n $(basename $1 | sed -n 's/^lib\(.*\)[.][aso]/\1/p')' '
}
processArg () {
# remove the -l prefix and define libname
libname=$(echo $1 | sed -n 's/[-]l\(.*\)/lib\1.so/p')
if [ -n "$libname" ]
then
# extract the *first* library in whereis
fullname=$(whereis -b $libname | sed -n 's/[^ :]*[:] \([^ ]*\).*/\1/p')
if [ -e $fullname ]
then
if [ "$(file -b $fullname)"="ASCII text" ]
then
# extract the filenames after GROUP
lst=( $(sed -n 's/^GROUP *[(] *\([^)]*\) *.*/\1/p' $fullname) )
if [ -n "$lst" ]
then
for j in ${lst[@]}; do
echo -n -l$(shortname $j)' '
done
exit
fi
fi
fi
fi
# if fails somewhere then return the original input
echo -n $1' '
}
args=$*
for i in ${args[@]}; do
echo -n $(processArg $i)' '
done