This repository has been archived by the owner on Apr 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfix-alice-binary-gfortran.sh
executable file
·221 lines (176 loc) · 4.62 KB
/
fix-alice-binary-gfortran.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
#
# fix-alice-binary-gfortran.sh -- by Dario Berzano <[email protected]>
#
# Fixes the wrong path to libgfortran.3.dylib inside binaries and libraries from
# the precompiled version[1] of the ALICE framework for Mac OS X.
#
# [1] http://alimonitor.cern.ch/packages/
#
# The only requisite is to run this script from inside the directory containing
# the scripts used to set environment variables, i.e. env_aliroot.sh and
# env_root.sh
#
#
# Global variables
#
# "Wrong" library paths (from Fink) hardcoded into binaries
export WRONG=(
"/sw/lib/gcc4.5/lib/libstdc++.6.dylib"
"/sw/lib/gcc4.5/lib/libgfortran.3.dylib"
"/sw/lib/gcc4.5/lib/libgcc_s.1.dylib"
"/sw/lib/libcrypto.0.9.8.dylib"
"/sw/lib/libjpeg.62.dylib"
"/sw/lib/libssl.0.9.8.dylib"
"/sw/lib/python2.6/config/libpython2.6.dylib"
)
# "Right" paths, to be searched automatically
export RIGHT=()
# Base search directories for the libraries, in order
export BASE=()
# Result of function LocateLib
export LOCATELIB_RES=""
#
# Functions
#
# The fix function
function FixPaths() {
local PREFIX="$1"
local DRY=0
local D F FN T
# Dry run?
[ "$2" == "--dry" ] && DRY=1
# Assemble command on a temporary file
T=$(mktemp /tmp/chlib.XXXXX)
echo -n "install_name_tool" > $T
CNT=0
for P in "${WRONG[@]}"; do
echo -n " -change \"$P\" \"${RIGHT[$CNT]}\"" >> $T
let CNT++
done
echo " \"\$1\"" >> $T
# We look inside bin and lib directories
find "$PREFIX" -type d -and \( -name lib -or -name bin \) | \
while read D
do
# We look for so/dylib files or files without extension (not symlinks)
find "$D" -type f -and \
\( -name '*.so' -or -name '*.dylib' -or -not -name '*.*' \) | \
while read F
do
# Limit search to all paths containing /sw (Fink)
otool -L "$F" | grep "/sw" > /dev/null 2>&1
if [ $? == 0 ]; then
# Wrong full path of a library found
FN=$(basename "$F")
echo -n "[....] $FN"
if [ "$DRY" == 0 ]; then
chmod +w "$F" > /dev/null 2>&1 && \
source $T "$F"
if [ $? == 0 ]; then
echo -e "\r[ \033[32mOK\033[m ] $FN"
else
echo -e "\r[\033[31mFAIL\033[m] $FN"
fi
else
# Dry run
echo -e "\r[\033[35mNOOP\033[m] $FN"
fi
fi
done
done
rm -f $T
}
# Find right library named "$1" under "$2"
function LocateLib() {
local NAME="$1"
local BASE="$2"
LOCATELIB_RES=""
local T=$(mktemp /tmp/locate_gfortran.XXXXX)
echo -en "\r[....] Searching for $NAME under $BASE"
# Try with mdfind first
mdfind -name "$NAME" -onlyin "$BASE" > "$T" 2> /dev/null
if [ ! -s "$T" ]; then
# Nothing was found with mdfind... try with find instead
find "$BASE" -name "$NAME" > "$T" 2> /dev/null
fi
if [ ! -s "$T" ]; then
# Nothing was found neither with mdfind, nor with find... failure
echo -e "\r[\033[31mFAIL\033[m]"
rm -f $T
return 1
else
# Found: take the first result
LOCATELIB_RES=$(head -n1 $T)
echo -e "\r[\033[32m OK \033[m] $NAME has been found as $LOCATELIB_RES"
fi
rm -f $T
return 0
}
# The main function
function Main() {
local DRY P CNT THISNAME THISBASE
local NERR=0
# Parse parameters
while [ $# -gt 0 ]; do
case "$1" in
--dry)
DRY=1
;;
--base-dir)
THISNAME="$2"
THISBASE="$3"
CNT=0
for P in "${WRONG[@]}"; do
if [ "$(basename "$P")" == "$THISNAME" ]; then
BASE[$CNT]="$THISBASE"
fi
let CNT++
done
shift 2
;;
*)
echo "Unrecognized switch: $1"
let NERR++
;;
esac
shift
done
# Are there any errors?
if [ $NERR -gt 0 ]; then
echo "Aborting."
exit 1
fi
if [ "`uname`" != "Darwin" ]; then
echo ""
echo "This script is meant to be run only on Macs"
echo ""
elif [ -f env_aliroot.sh ] && [ -f env_root.sh ]; then
# Search for each library path in order, abort on error
CNT=0
for P in "${WRONG[@]}"; do
THISBASE="${BASE[$CNT]}"
if [ "$THISBASE" == "" ]; then
LocateLib $(basename "$P") "/usr/lib" || \
LocateLib $(basename "$P") "/" || return 1
else
LocateLib $(basename "$P") "$THISBASE" || return 1
fi
RIGHT[$CNT]="$LOCATELIB_RES"
let CNT++
done
# Fix paths (if not dry run)
[ "$DRY" == 1 ] && FixPaths "$PWD" --dry || FixPaths "$PWD"
else
echo ""
echo "This script must be run from within the directory containing:"
echo ""
echo " * env_aliroot.sh"
echo " * env_root.sh"
echo ""
fi
}
#
# Entry point
#
Main "$@"