-
Notifications
You must be signed in to change notification settings - Fork 490
/
roboschool_compile_and_graft.sh
executable file
·99 lines (87 loc) · 2.65 KB
/
roboschool_compile_and_graft.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -e
function graft_libs {
local libfile=$1
local libdir=$(dirname $libfile)
if [ $(uname) == 'Darwin' ]; then
local relink="osx_relink"
local origin="@loader_path"
local deps=$(otool -L $libfile | awk 'FNR>2 {print $1}')
fi
if [ $(uname) == 'Linux' ]; then
local relink="linux_relink"
local library_lister="ldd"
local origin="\$ORIGIN"
local deps=$(ldd $libfile | awk '{print $3}')
fi
local patterns=${@:3}
graft_dir=$2
mkdir -p $graft_dir
for dep in $deps; do
# echo $dep
for deppattern in $patterns; do
if [[ "$dep" =~ $deppattern ]]; then
new_depname=${dep##*/}
new_deppath="$graft_dir/$new_depname"
rel_path=$(realpath --relative-to="$libdir" $new_deppath)
new_dep="$origin/$rel_path"
echo "$libfile depends on $dep, relinking to $new_deppath ($new_dep)"
$relink $dep $new_dep $libfile
if [ ! -f $new_deppath ]; then
echo "$new_deppath not found, copying and calling self"
cp $dep $new_deppath
chmod 777 $new_deppath
graft_libs $new_deppath $graft_dir $patterns
else
echo "grafted library $new_deppath already exists"
fi
fi
done
done
}
function osx_relink {
install_name_tool -change $1 $2 $3
}
function linux_relink {
# local depname=${2#*/}
local dep_dir=${2%/*}
patchelf --set-rpath $dep_dir $3
}
cd $(dirname "$0")
cd roboschool/cpp-household
# make clean
make -j4
cd ..
graft_libs cpp_household.so .libs \
^/.+/libboost_python.+ \
^/.+Qt.+ \
^/.+/libassimp.+ \
^/.+/libLinearMath.+ \
^/.+/libBullet.+ \
^/.+/libPhysicsClientC_API.+ \
^/.+/libjpeg.+ \
^/.+/libpng.+ \
^/.+/libicu.+ \
^/.+/libpcre.+ \
^/.+/libdouble-conversion.+ \
^/.+/libminizip.+
if [ $(uname) == 'Darwin' ]; then
# HACK - this should auto-detect plugins dir
cp -r /usr/local/Cellar/qt/5.10.1/plugins .qt_plugins
lib_pattern="*.dylib"
fi
if [ $(uname) == 'Linux' ]; then
cp -r /usr/lib/x86_64-linux-gnu/qt5/plugins .qt_plugins
lib_pattern="*.so*"
fi
for lib in $(find .qt_plugins -name "$lib_pattern"); do
graft_libs $lib .libs ^/.+Qt.+ \
^/.+/libjpeg.+ \
^/.+/libpng.+ \
^/.+/libicu.+ \
^/.+/libpcre.+ \
^/.+/libdouble-conversion.+ \
^/.+/libminizip.+ \
^/.+/libxcb.+ \
^/.+/libxkb.+
done