-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathrel-rpaths.sh
executable file
·72 lines (55 loc) · 1.95 KB
/
rel-rpaths.sh
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
#!/bin/sh
# Script to set RPATHs to be relative in shared binaries
# Copyright (C) 2012, 2013 Synopsys Inc.
# Copyright (C) 2014 Embecosm Limited.
# Contributor Simon Cook <[email protected]>
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# This should be run in the INSTALL directory, so there should be a bin
# subdirectory.
# Usage:
# ./rel-paths.sh <installdir>
# Exits with 0 on success, 1 otherwise.
install_dir=$1
if ! cd ${install_dir}
then
echo "ERROR: rel-rpaths.sh: Can't cd to install directory ${install_dir}"
exit 1
fi
if ! [ -d bin ]; then
echo "\`$INSTALLDIR' is not a toolchain installation directory."
exit 1
fi
# We need patchelf for this to install
if ! which patchelf > /dev/null 2>&1
then
echo "ERROR: rel-rpaths.sh: patchelf not found."
exit 1
fi
# Get list of executables
files=`find -type f -exec file {} \; | grep 'ELF ??-bit .* executable' | \
sed -e 's/:.*$//'`
for f in ${files}
do
# Do we have a RPATH to do?
rpath=$(readelf -d "${f}" | grep 'Library rpath')
if [ $? -gt 0 ]; then
continue
fi
echo "Making RPATH relative for $f"
# Build a relative directory
reldir=${f:2}
reldir=$(echo ${reldir//[^\/]})
reldir=$(echo ${reldir//\//\/..})
rpath=`echo "${rpath}" | \
sed "s#.*\[${install_dir}\(.*\)\]#\$ORIGIN${reldir}\1#"`
patchelf --set-rpath "${RPATH}" ${f}
done