-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathinstall
More file actions
executable file
·336 lines (281 loc) · 8.95 KB
/
install
File metadata and controls
executable file
·336 lines (281 loc) · 8.95 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
version=1.0.0
logFile=$PWD/install.log
echo "" > $logFile
# Help display function
function print_help ()
{
echo ""
echo "Syntax: ./install"
echo " [--no-prereqs]"
echo " [--rebuild]"
echo " [--debug]"
echo " [--jobs=N]"
echo " [--help]"
echo ""
echo "Where:"
echo " --no-prereqs prevents Korali from automatically installing prerequisites."
echo " --rebuild Cleans and rebuilds/installs Korali for development purposes."
echo " --debug builds a non-optimized Korali for debugging purposes."
echo " --jobs=N Specifies N jobs to use when building Korali."
echo " --help Displays this help message."
}
# Logging and printing function.
function logEcho ()
{
echo "$1"
echo "$1" >> $logFile
}
# Logging function.
function log ()
{
echo "$1" >> $logFile
}
# Exit with error message.
function exitWithError ()
{
>&2 echo "[Korali] Installation Error: Check $logFile for more information."
exit -1
}
INSTALLREQS=1
NJOBS=4
OPTFLAGS="-O3 -DJSON_NOEXCEPTION"
for i in "$@"
do
case $i in
--no-prereqs)
INSTALLREQS=0
shift
;;
--debug)
OPTFLAGS="-O0"
shift
;;
--jobs=*)
NJOBS="${i#*=}"
shift
;;
--rebuild)
logEcho "[Korali] Cleaning Korali for new build..."
pip uninstall -y korali >> $logFile 2>&1
make -C source clean >> $logFile 2>&1
shift
;;
--help)
print_help
exit 0
shift
;;
*)
print_help
echo ""
echo "[Korali] Error: Unknown option $i."
exit 1
;;
esac
done
######## Start Configuration ######
logEcho "[Korali] Installing Korali v$version..."
logEcho "[Korali] Determining Configuration..."
log "[Korali] Using $NJOBS jobs."
log "[Korali] Checking for architecture..."
arch="$(uname -s)"
# Linux Architecture is default
SHAREDLIB_FLAG="-shared"
if [ "$arch" == "Linux" ]; then
log "[Korali] Linux System Detected."
fi
# If using MacOs, change flags
if [ "$arch" == "Darwin" ]; then
log "[Korali] MacOS (Darwin) System Detected."
SHAREDLIB_FLAG="-dynamiclib"
fi
######## Checking Compiler ########
logEcho "[Korali] Checking Pre-requisites..."
log "Checking for C++ Compiler..."
$CXX --version > /dev/null 2>&1
DETECTED_CXX=$?
c++ --version > /dev/null 2>&1
DETECTED_CPLUSPLUS=$?
g++ --version > /dev/null 2>&1
DETECTED_GXX=$?
clang++ --version > /dev/null 2>&1
DETECTED_CLANG=$?
icpc --version > /dev/null 2>&1
DETECTED_ICPC=$?
CC --help > /dev/null 2>&1
DETECTED_CRAY=$?
USE_CXX=""
if [ $DETECTED_CPLUSPLUS -eq 0 ]; then USE_CXX=c++; fi;
if [ $DETECTED_GXX -eq 0 ]; then USE_CXX=g++; fi;
if [ $DETECTED_ICPC -eq 0 ]; then USE_CXX=icpc; fi;
if [ $DETECTED_CRAY -eq 0 ]; then USE_CXX=CC; fi;
if [ $DETECTED_CLANG -eq 0 ]; then USE_CXX=clang++; fi;
if [ $DETECTED_CXX -eq 0 ]; then USE_CXX=$CXX; fi;
######## Checking support for GNU Scientific Library ########
log "[Korali] Looking for existing GNU Scientific Library (GSL)..."
gslprefix=$PWD/build
gslcfgFile=$gslprefix/bin/gsl-config
if [ ! -f "$gslcfgFile" ]; then
gslcfgFile=gsl-config
fi
log "[Korali] Running \"$gslcfgFile --version\"..."
gslver=`$gslcfgFile --version`
mingslver=2.5
if [ $? -eq 0 ]
then
log "[Korali] Found GSL version $gslver."
cmpver=`printf "${gslver}\n${mingslver}" | sort -V | head -n 1`
if [[ "$cmpver" != "$mingslver" ]]; then
if [ $INSTALLREQS -eq 0 ]; then
logEcho "[Korali] Error: GSL Version found (${gslver}) is smaller than required (${mingslver})."
logEcho "[Korali] Solution: Run \"./install\"."
exitWithError
fi
logEcho "[Korali] Downloading GNU Scientific Library... "
mkdir -p build
CURDIR=$PWD
rm -f gsl-2.5.tar.gz
wget 'ftp://ftp.gnu.org/gnu/gsl/gsl-2.5.tar.gz'
tar -xzvf gsl-2.5.tar.gz >> $logFile 2>&1
echo "[Korali] Configuring GNU Scientific Library... "
cd gsl-2.5
logEcho "[Korali] Running ./configure --prefix=$gslprefix ..."
./configure --prefix=$gslprefix >> $logFile 2>&1
logEcho "[Korali] Compiling GNU Scientific Library... "
make -j$NJOBS >> $logFile 2>&1
logEcho "[Korali] Installing GNU Scientific Library... "
make install >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho -e "[Korali] Error: Failed GNU Scientific Library installation."
exitWithError
fi
cd ..
rm -rf gsl-2.5 gsl-2.5.tar.gz >> $logFile 2>&1
logEcho "[Korali] Finished installing GNU Scientific Library. "
gslcfgFile=$gslprefix/bin/gsl-config
fi
fi
######## Checking support for MPI ########
MPIFLAGS=""
log "[Korali] Checking for MPI support..."
log "[Korali] Running \"\$MPICXX --help\"..."
$MPICXX --help > /dev/null 2>&1
if [ ! $? -eq 0 ]
then
logEcho "[Korali] Installing Korali without support for MPI."
USE_MPI=0
else
log "[Korali] Found $MPICXX for MPI compiler/wrapper."
log "[Korali] Use 'export MPICXX=(path)' to use a different MPI wrapper."
USE_CXX=$MPICXX
MPIFLAGS="-D_KORALI_USE_MPI"
fi
######## Checking support for Python3 ########
log "[Korali] Checking for Python3 support using \"python3 --version\"."
pyver=`python3 --version`
if [ $? -eq 0 ]; then
log "[Korali] Checking for python3-config."
python3-config --help >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error: python3-config not found."
logEcho "[Korali] Solution: Please make sure the python3-dev package is correctly installed."
exitWithError
fi
else
logEcho "[Korali] Error: Python3 not found."
logEcho "[Korali] Solution: Please make sure the python3-config command is accesible in the PATH environment variable."
exitWithError
fi
log "[Korali] Python3 version $pyver found."
######## Checking support for pip3 ########
log "[Korali] Checking for pip3 support using \"pip3 --version\"..."
pip3 --version >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error: pip3 not found."
logEcho "[Korali] Solution: Make sure python and pip3 are correctly installed in your system."
exitWithError
fi
######## Checking support for Pybind11 ########
log "[Korali] Checking for Pybind11 support using \"python3 -m pybind11 -h\"..."
python3 -m pybind11 -h >> $logFile 2>&1
if [ $? -ne 0 ]; then
if [ $INSTALLREQS -eq 0 ]; then
logEcho "[Korali] Error: pybind11 not found, trying to install it automatically."
logEcho "[Korali] Solution: Run \"./install\"."
exitWithError
fi
logEcho "[Korali] pybind11 not found, trying to install it automatically."
pip3 install --user pybind11 >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error trying to install pybind11."
exitWithError
fi
fi
######## Determining Library Flags ########
echo "[Korali] Creating configuration files..."
GSLPREFIX=`$gslcfgFile --prefix`
GSLCFLAGS=`$gslcfgFile --cflags`
GSLLIBS=`$gslcfgFile --libs`
PYBIND11INCLUDES=`python3 -m pybind11 --includes`
PYBIND11LIBS=`python3-config --ldflags`
CXXARCH="-std=c++14"
which $USE_CXX | grep "cray" >> $logFile 2>&1
if [ $? -eq 0 ]; then
logEcho "[Korali] Assuming Cray System."
CC -craype-verbose 2>&1 | grep "driver.CC" >> $logFile 2>&1
if [ $? -eq 0 ]; then
logEcho "[Korali] Detected Cray compiler."
CXXARCH="-hstd=c++14"
PYBIND11LIBS=`echo $PYBIND11LIBS | sed 's/-Xlinker//g' | sed 's/-export-dynamic//g'`
fi
fi
######## Checking selected compiler #######
if [[ "$USE_CXX" == "" ]]
then
logEcho "[Korali] Error: Did not found any valid C++ or MPI C++ compiler."
logEcho "[Korali] Solution: Please define a valid C++ compiler in \$CXX or \$MPICXX."
exitWithError
fi
######## Creating Compilation Config File ########
log "[Korali] Creating Compilation Config File..."
echo CXX=$USE_CXX > source/Makefile.conf
echo CXXARCH=$CXXARCH >> source/Makefile.conf
echo SHAREDLIB_FLAG=$SHAREDLIB_FLAG >> source/Makefile.conf
echo MPIFLAGS=$MPIFLAGS >> source/Makefile.conf
echo OPTFLAGS=$OPTFLAGS >> source/Makefile.conf
echo MACHINEARCH=$arch >> source/Makefile.conf
echo GSLPREFIX=$GSLPREFIX >> source/Makefile.conf
echo GSLCFLAGS=$GSLCFLAGS >> source/Makefile.conf
echo GSLLIBS=$GSLLIBS >> source/Makefile.conf
echo PYBIND11INCLUDES=$PYBIND11INCLUDES >> source/Makefile.conf
echo PYBIND11LIBS=$PYBIND11LIBS >> source/Makefile.conf
######## Compiling Korali C++ Engine #########
logEcho "[Korali] Building Korali Source..."
make -C source build >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error building Korali."
exitWithError
fi
logEcho "[Korali] Compiling Korali..."
make -j$NJOBS -C source all >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error compiling Korali."
exitWithError
fi
######## Installing Korali using pip3 ########
logEcho "[Korali] Installing Korali..."
cp source/libkorali.so . >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error obtaining libkorali.so"
exitWithError
fi
pip3 install . --user --upgrade >> $logFile 2>&1
if [ $? -ne 0 ]; then
logEcho "[Korali] Error installing Korali's Python module."
exitWithError
fi
rm -f libkorali.so >> $logFile 2>&1
echo "------------------------------------------------------------------"
echo "[Korali] Finished installation successfully."
echo "------------------------------------------------------------------"