-
Notifications
You must be signed in to change notification settings - Fork 3
/
remove_rpath
executable file
·60 lines (56 loc) · 1.85 KB
/
remove_rpath
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
#!/bin/sh
if [ -z "$RPM_BUILD_ROOT" ]; then
printf '%s\n' "No build root defined" >&2
exit 1
fi
if [ ! -d "$RPM_BUILD_ROOT" ]; then
printf '%s\n' "Invalid build root" >&2
exit 1
fi
find "$RPM_BUILD_ROOT" \
! -path "${RPM_BUILD_ROOT}/usr/lib/debug/*" \
! -path "${RPM_BUILD_ROOT}/usr/doc/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/doc/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/man/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/mime/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/icons/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/pixmaps/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/zoneinfo/*" \
! -path "${RPM_BUILD_ROOT}/usr/share/locale/*" \
! -path "${RPM_BUILD_ROOT}/usr/src/*" \
! -path "${RPM_BUILD_ROOT}/usr/include/*" \
-type f -print0 |
xargs --no-run-if-empty -0 file -N -F ' //magic:' |
grep -e "ELF" |
sed -e 's# //magic:.*##g' |
while read path; do
RPATH=$(chrpath -l "$path" 2>/dev/null| grep -e RUNPATH -e RPATH|sed -e 's#.*RPATH=##g' -e 's#.*RUNPATH=##g')
[ -z "$RPATH" ] && continue
NEWRPATH=
for RDIR in $(echo $RPATH|cut -d: --output-delimiter=" " -f1-); do
case $RDIR in
/lib|/lib32|/libx32|/lib64) printf 'removing %s from rpath\n' $RDIR;;
/usr/lib|/usr/lib32|/usr/libx32|/usr/lib64) printf 'removing %s from rpath\n' $RDIR;;
# often RPM %buildroot is in RPATH, delete it
*/BUILD/*) printf 'removing %s from rpath\n' $RDIR;;
# often for a directory /.libs/ inside %buildroot
*/.libs/*|*/.libs) printf 'removing %s from rpath\n' $RDIR;;
*)
if [ -z "$NEWRPATH" ]; then
NEWRPATH="$RDIR"
else
NEWRPATH="$NEWRPATH:$RDIR"
fi
;;
esac
done
if [ "$NEWRPATH" = "$RPATH" ]; then
continue
elif [ -z "$NEWRPATH" ]; then
chrpath -d "$path"
printf '%s\n' "Removing rpath ($RPATH) from $path"
else
chrpath -r "$NEWRPATH" "$path"
printf '%s\n' "Removed parts of rpath ($RPATH) from $path, new rpath is $NEWRPATH"
fi
done