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 pathalice-install.sh
executable file
·2327 lines (1867 loc) · 69.3 KB
/
alice-install.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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# alice-install.sh -- by Dario Berzano <[email protected]>
#
# Installs all the ALICE software on Ubuntu/Mac hopefully with the least
# possible human intervention.
#
#
# Variables
#
export NCORES=0
export BUILD_MODE='' # clang, gcc, custom-gcc
export SUPPORTED_BUILD_MODES=''
export CUSTOM_GCC_PATH='/opt/gcc'
export BUILDOPT_LDFLAGS=''
export BUILDOPT_CPATH=''
export ALIEN_INSTALL_TYPE=''
export FASTJET_PATCH_HEADERS=0
export DOWNLOAD_MODE=''
export SYSTEM_ALIEN_LIBS=
export MIN_ROOT_VER_NUM=''
export MIN_ROOT_VER_STR='all'
export LC_ALL=C
export DebugSwallow=0
export DebugDetectOs=0
export BuildType='normal'
export DontUpdateEnv=0
#
# Functions
#
# Sources environment variables
function SourceEnvVars() {
local R UpdateFlag
if [[ ! -r "$ALI_EnvScript" ]] ; then
return 100
fi
if [[ "$1" == '-u' ]] ; then
# Force the update now
UpdateFlag='-u'
else
# By default, stop auto updating. We don't want the script to accidentally
# self-update while installing!
UpdateFlag='-k'
fi
source "$ALI_EnvScript" -n "$ALI_nAliTuple" $UpdateFlag
R=$?
[[ $NCORES -gt 0 ]] && MJ=$NCORES
return $R
}
# Returns date in current timezone in a compact format
function DateTime() {
date +%Y%m%d-%H%M%S
}
# Prints the time given in seconds in hours, minutes, seconds
function NiceTime() {
local SS HH MM STR
SS="$1"
let "HH=SS / 3600"
let "SS=SS % 3600"
[ $HH -gt 0 ] && STR=" ${HH}h"
let "MM=SS / 60"
let "SS=SS % 60"
[ $MM -gt 0 ] && STR="${STR} ${MM}m"
[ $SS -gt 0 ] && STR="${STR} ${SS}s"
[ "$STR" == "" ] && STR="0s"
echo $STR
#printf "%02dh %02dm %02ds" $HH $MM $SS
}
# Prints the command name when it is started.
# - $1: command description
function SwallowStart() {
local MSG OP
OP="$1"
shift
MSG='*** ['"$(DateTime)"'] BEGIN OP='"$OP"' CWD='"$PWD"' CMD='"$@"' ***'
echo -e "\n\n$MSG" >> "$OUT"
echo -e "\n\n$MSG" >> "$ERR"
if [[ $DebugSwallow == 1 ]] ; then
echo
echo -e "\033[35m CWD:>\033[34m $PWD\033[m"
for ((i=1 ; i<=$# ; i++)) ; do
if [[ $i == 1 ]] ; then
echo -e "\033[35m CMD:>\033[34m ${!i}\033[m"
else
echo -e "\033[35m $(printf '% 3u' $((i-1))):>\033[34m ${!i}\033[m"
fi
done
fi
echo -en "[....] $OP..."
}
# Prints command's progress with percentage and time.
# - $1: command description
# - $2: current percentage
# - $3: start timestamp (seconds)
function SwallowStep() {
local TS_START OP MSG PCT PCT_FMT MODE
if [ "$1" == '--pattern' ] || [ "$1" == '--percentage' ] ; then
MODE="$1"
shift
fi
OP="$1"
PCT=$2
TS_START=${3}
let TS_DELTA=$(date +%s)-TS_START
# Prints progress
echo -ne '\r \r'
if [ "$MODE" == '--pattern' ] ; then
#local PROG_PATTERN=( '. ' '.. ' '... ' '....' ' ...' ' ..' ' .' ' ' )
local PROG_PATTERN=( \
'o...' 'O...' 'o...' \
'.o..' '.O..' '.o..' \
'..o.' '..O.' '..o.' \
'...o' '...O' '...o' \
'..o.' '..O.' '..o.' \
'.o..' '.O..' '.o..' \
)
local PROG_IDX=$(( $PCT % ${#PROG_PATTERN[@]} ))
echo -ne "[\033[34m${PROG_PATTERN[$PROG_IDX]}\033[m] $OP \033[36m$(NiceTime $TS_DELTA)\033[m"
else
PCT_FMT=$( printf "%3d%%" $PCT )
echo -ne "[\033[34m$PCT_FMT\033[m] $OP \033[36m$(NiceTime $TS_DELTA)\033[m"
fi
}
# Prints the command with its exit status (OK or FAILED) and time taken.
# - $1: command description
# - $2: the exit code of command
# - $3: start timestamp (seconds) (optional)
# - $4: end timestamp (seconds) (optional)
# - $@: the command (from $5 on)
function SwallowEnd() {
local TS_END TS_START OP MSG RET
OP="$1"
FATAL=$2
RET=$3
TS_START=${4-0} # defaults to 0
TS_END=${5-0}
# After this line, $@ will contain the command
shift 5
let TS_DELTA=TS_END-TS_START
# Prints success (green OK) or fail (red FAIL). In case FATAL=0
# prints a warning (yellow SKIP) instead of an error
echo -ne '\r'
if [ $RET == 0 ]; then
echo -ne '[ \033[32mOK\033[m ]'
elif [ $FATAL == 0 ]; then
echo -ne '[\033[33mSKIP\033[m]'
else
echo -ne '[\033[31mFAIL\033[m]'
fi
echo -ne " ${OP}"
# Prints time only if greater than 1 second
if [ $TS_DELTA -gt 1 ]; then
echo -e " \033[36m$(NiceTime $TS_DELTA)\033[m"
else
echo " "
fi
# On the log files (out, err)
MSG='*** ['"$(DateTime)"'] END OP='"$OP"' CWD='"$PWD"' ERR='"$RET"' CMD='"$@"' ***'
echo -e "$MSG" >> "$OUT"
echo -e "$MSG" >> "$ERR"
return $RET
}
# Sends everything to a logfile
function Swallow() {
local MSG ERRMSG RET TSSTART TSEND DELTAT FATAL OP
# Options given?
FATAL=0
ERRMSG=''
OKMSG=''
while [[ "${1:0:1}" == '-' ]] ; do
case "$1" in
-f|--fatal)
FATAL=1
;;
--error-msg)
ERRMSG="$2"
shift
;;
--success-msg)
OKMSG="$2"
shift
;;
esac
shift
done
OP="$1"
shift
SwallowStart "$OP" "$@"
TSSTART=$(date +%s)
"$@" >> "$OUT" 2>> "$ERR"
RET=$?
TSEND=$(date +%s)
SwallowEnd "$OP" $FATAL $RET $TSSTART $TSEND "$@"
if [[ $RET != 0 && $FATAL == 1 ]]; then
if [[ "$ERRMSG" != '' ]] ; then
# Produce a custom error message instead of log output
echo
echo -e "\033[31m${ERRMSG}\033[m"
echo
else
LastLogLines -e "$OP"
fi
exit 1
elif [[ $RET == 0 && "$OKMSG" != '' ]]; then
echo
echo -e "\033[32m${OKMSG}\033[m"
echo
fi
return $RET
}
# Prints the last lines of both log files
function LastLogLines() {
local LASTLINES=20
local ISERROR=0
if [ "$1" == "-e" ]; then
echo ""
echo -e "\033[41m\033[1;37mOperation \"$2\" ended with errors\033[m"
fi
echo ""
echo -e "\033[33m=== Last $LASTLINES lines of stdout -- $SWALLOW_LOG.out ===\033[m"
tail -n$LASTLINES "$SWALLOW_LOG".out
echo ""
echo -e "\033[33m=== Last $LASTLINES lines of stderr -- $SWALLOW_LOG.err ===\033[m"
tail -n$LASTLINES "$SWALLOW_LOG".err
echo ""
echo -e "\033[31m=== Possible errors ===\033[m"
cat "$SWALLOW_LOG".err | grep -B 2 'error:' --color
echo ""
[ "$1" == "-e" ] && ShowBugReportInfo
}
# Echoes a colored banner
function Banner() {
echo ""
echo -e '\033[33m'"$1"'\033[m'
}
# Prepares information for bug report
function PrepareBugReport() {
# Source environment variables (non-fatal)
SourceEnvVars >> $OUT 2>&1
# Some environment variables
(
echo "=== BUILD ENVIRONMENT ==="
echo "PATH=$PATH"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
echo "PYTHONPATH=$PYTHONPATH"
echo "uname -a: `uname -a`"
if [[ -r /etc/lsb-release ]] ; then
echo "*** /etc/lsb-release ***"
cat /etc/lsb-release
fi
if [[ -r /etc/redhat-release ]] ; then
echo "*** /etc/redhat-release ***"
cat /etc/redhat-release
fi
echo "=== ROOT COMPILATION FLAGS ==="
local rootconf=( --f77 --cc --cxx --ld --features --cflags --auxcflags --ldflags )
for rc in "${rootconf[@]}" ; do
echo "root-config ${rc}: `root-config ${rc} 2> /dev/null`"
done
echo "=== VERSIONS OF EXTERNAL TOOLS ==="
local progs=( 'gcc -v' 'g++ -v' 'ld -v' 'gfortran -v' \
'clang -v' 'clang++ -v' \
'make -v' 'cmake --version' \
'libtool -V' 'autoconf --version' 'automake --version' \
'git --version' 'brew -v' 'port version' 'fink --version' )
for pa in "${progs[@]}" ; do
pr=${pa%% *}
echo "*** ${pr} ***"
w=$( which $pr 2> /dev/null )
if [[ $? == 0 ]] ; then
echo "Location: ${w}"
${pa} 2>&1
else
echo '<not found>'
fi
done
echo "=== ALICE SOFTWARE VERSIONS ==="
echo "ROOT: $ROOT_VER"
echo "Geant3: $G3_VER"
echo "AliRoot Core: $ALICE_VER"
echo "AliPhysics: $ALICEPHYSICS_VER"
echo "FastJet: $FASTJET_VER"
echo "FJ Contrib: $FJCONTRIB_VER"
echo "=== DISK SPACE ==="
df
echo "=== MOUNTED VOLUMES ==="
mount
) >> $OUT 2>&1
}
# Shows a message reminding user to send the log files when asking for support
function ShowBugReportInfo() {
echo ""
echo -e "\033[41m\033[1;37mWhen asking for support, please send an email attaching the following file(s):\033[m"
echo ""
[ -s "$ERR" ] && echo " $ERR"
[ -s "$OUT" ] && echo " $OUT"
echo ""
echo -e "\033[41m\033[1;37mNote:\033[m should you be concerned about private information contained"
echo " in the logs, you can edit them before sending."
echo ""
}
# Module to fetch and compile ROOT
function ModuleRoot() {
local ForceCleanSlate="$1"
Banner 'Installing ROOT...'
Swallow -f 'Sourcing envvars' SourceEnvVars
Swallow 'Checking that we are not using an external ROOT' [ "$ROOT_VER" != EXTERNAL ] || return
Swallow --fatal \
--error-msg "ROOT $ROOT_VER is not supported on your platform: use at least $MIN_ROOT_VER_STR." \
"Ensuring ROOT $ROOT_VER is OK for your platform" \
[ $( ConvertVersionStringToNumber "$ROOT_VER" ) -ge $MIN_ROOT_VER_NUM ]
# ROOT variables: only ${ALICE_PREFIX} and ${ROOTSYS} needed
local RootGit="${ALICE_PREFIX}/root/git"
local RootBase=$( dirname "${ROOTSYS}" )
local RootInst="$ROOTSYS"
local RootSrc="${RootBase}/src"
local RootTmp="${RootBase}/build"
local RootGitUrl='https://github.com/alisw/root'
local RootGitRemote='aliceroot'
Swallow -f 'Creating ROOT directory' mkdir -p "$RootBase"
if [[ "$DOWNLOAD_MODE" == '' || "$DOWNLOAD_MODE" == 'only' ]] ; then
#
# Downloading ROOT from Git
#
Swallow -f 'Creating ROOT Git local directory' mkdir -p "$RootGit"
Swallow -f 'Moving into ROOT Git local directory' cd "$RootGit"
if [[ ! -e "$RootGit/.git" ]] ; then
SwallowProgress -f --pattern 'Cloning ROOT Git repository (might take some time)' \
git clone "$RootGitUrl" .
fi
# Setting a public and private remote
Swallow -f 'Setting ROOT ALICE remote URL' \
GitForceSetRemote "$RootGitRemote" "$RootGitUrl" "$RootGitUrl"
SwallowProgress -f 'Synchronizing Git clone' \
GitSync "$RootGitRemote"
# Updating from the former installation schema (no inst and build dir)
if [[ -e "${RootBase}/LICENSE" ]] ; then
Swallow -f 'Clean up directory from the old installation schema' rm -rf "${RootBase}"
fi
# Shallow copy with git-new-workdir
if [[ ! -d "${RootSrc}/.git" ]] ; then
rmdir "$RootSrc" > /dev/null 2>&1
SwallowProgress -f --pattern \
"Creating a local clone for version ${ROOT_VER}" \
GitNewWorkdir "$RootGit" "$RootSrc" "$RootGitRemote" "$ROOT_VER"
fi
Swallow -f "Moving to local clone for version ${ROOT_VER}" cd "$RootSrc"
Swallow -f "Checking out ROOT version ${ROOT_VER}" \
GitCheckoutTrack "$ROOT_VER" "$RootGitRemote"
if [[ $ForceCleanSlate == 1 ]] ; then
Swallow -f "Forcing hard reset to remote ${ROOT_VER}" \
GitResetHard "$RootGitRemote" "$ROOT_VER"
Swallow -f 'Forcing cleanup of working directory' git clean -f -d
elif [[ "$(git rev-parse --abbrev-ref HEAD)" != 'HEAD' ]] ; then
# update only if on a branch: errors are fatal
SwallowProgress -f --pattern "Updating ROOT branch ${ROOT_VER}" git pull --rebase
fi
fi # end download
if [[ "$DOWNLOAD_MODE" == '' || "$DOWNLOAD_MODE" == 'no' ]] ; then
#
# Build ROOT
#
# Build type. Note that ROOT, if configured with ./configure (and not CMake), does not allow us
# to be flexible with respect to build options. We will need to override them when running make
# by passing the additional OPT= variable. The following options match the build options for
# AliRoot Core and AliPhysics for consistency
case $BuildType in
debug)
BuildCfgFlags='--build=debug'
BuildMakeFlags='-O0 -g'
;;
normal)
BuildCfgFlags='--build=debug'
BuildMakeFlags='-O2 -g'
;;
optimized)
BuildCfgFlags=''
BuildMakeFlags='-O3'
;;
esac
# Configuration options (including installation prefixes)
local ConfigOpts="--with-pythia6-uscore=SINGLE \
--with-alien-incdir=${GSHELL_ROOT}/include \
--with-alien-libdir=${GSHELL_ROOT}/lib \
--with-monalisa-incdir="${GSHELL_ROOT}/include" \
--with-monalisa-libdir="${GSHELL_ROOT}/lib" \
--with-xrootd=${GSHELL_ROOT} \
--enable-builtin-ftgl \
--enable-minuit2 \
--enable-roofit \
--enable-soversion \
--disable-bonjour \
--disable-rfio \
--disable-castor \
--enable-builtin-freetype $BuildCfgFlags \
--prefix=${RootInst} \
--incdir=${RootInst}/include \
--libdir=${RootInst}/lib \
--datadir=${RootInst} \
--etcdir=${RootInst}/etc"
# Are --disable-fink and --enable-cocoa available (OS X only)?
if [[ "`uname`" == 'Darwin' ]] ; then
if [[ `./configure --help 2>/dev/null|grep -c finkdir` == 1 ]] ; then
ConfigOpts="$ConfigOpts --disable-fink"
fi
if [[ `./configure --help 2>/dev/null|grep -c cocoa` == 1 ]] ; then
ConfigOpts="$ConfigOpts --enable-cocoa"
fi
fi
case "$BUILD_MODE" in
gcc)
ConfigOpts="--with-f77=$( which gfortran ) \
--with-cc=$( which gcc ) \
--with-cxx=$( which g++ ) \
--with-ld=$( which g++ ) $ConfigOpts"
;;
clang)
ConfigOpts="--with-clang \
--with-f77=$( which gfortran ) \
--with-cc=$( which clang ) \
--with-cxx=$( which clang++ ) \
--with-ld=$( which clang++ ) $ConfigOpts"
;;
custom-gcc)
ConfigOpts="--with-f77=$CUSTOM_GCC_PATH/bin/gfortran \
--with-cc=$CUSTOM_GCC_PATH/bin/gcc \
--with-cxx=$CUSTOM_GCC_PATH/bin/g++ \
--with-ld=$CUSTOM_GCC_PATH/bin/g++ $ConfigOpts"
;;
esac
# Enable C++11 if possible
function TestCxx11() {
TCXX11=$(mktemp /tmp/test_cxx11_XXXXX)
mv $TCXX11 $TCXX11.cxx
cat > $TCXX11.cxx <<\EOF
// Use Clang (any version) or GCC v4.8.2
#if defined __clang__ || \
((__GNUC__ << 32)+(__GNUC_MINOR__ << 16)+(__GNUC_PATCHLEVEL__) >= (4 << 32)+(8 << 16)+(2))
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
for(auto i : arr) {
cout << arr[i] <<endl;
}
return 0;
}
#else
#error "C++11 is not supported by your compiler."
#endif
EOF
case "$BUILD_MODE" in
clang) GXX=clang++ ;;
gcc) GXX=g++ ;;
custom-gcc) GXX="$CUSTOM_GCC_PATH/bin/g++" ;;
*) GXX=false ;;
esac
"$GXX" -std=c++11 -o $TCXX11.out $TCXX11.cxx
RV=$?
rm -f $TCXX11*
unset GXX TCXX11
return $RV
}
Swallow 'Testing C++11 support' TestCxx11 && ConfigOpts="$ConfigOpts --enable-cxx11"
# Building out-of-source with configure (no CMake)
Swallow -f 'Creating build directory' mkdir -p "$RootTmp"
Swallow -f 'Moving into build directory' cd "$RootTmp"
SwallowProgress -f --pattern 'Configuring ROOT' "${RootSrc}/configure" $ConfigOpts
# Before building ROOT, make sure we have some required features enabled
Swallow --fatal --error-msg \
'ROOT was configured with no OpenGL support: check you have the OpenGL libraries installed.' \
'Ensuring ROOT will be built with OpenGL support' \
RootConfiguredWithFeature opengl
Swallow --fatal --error-msg \
'ROOT did not find AliEn: make sure it is installed before compiling ROOT.' \
'Ensuring ROOT will be built with AliEn support' \
RootConfiguredWithFeature alien
local AppendLDFLAGS AppendCPATH
[[ "$BUILDOPT_LDFLAGS" != '' ]] && AppendLDFLAGS="LDFLAGS=$BUILDOPT_LDFLAGS"
[[ "$BUILDOPT_CPATH" != '' ]] && AppendCPATH="CPATH=$BUILDOPT_CPATH"
export CCACHE_BASEDIR="$RootBase"
SwallowProgress -f --pattern 'Building ROOT' \
make -j$MJ $AppendLDFLAGS $AppendCPATH OPT="$BuildMakeFlags"
Swallow -f 'Cleaning ROOT installation directory' rm -rf "${RootInst}"
SwallowProgress -f --pattern 'Installing ROOT' make -j$MJ install
unset CCACHE_BASEDIR
fi # end build
}
# Module to fetch and compile Geant3
function ModuleGeant3() {
local ForceCleanSlate="$1"
Banner 'Installing Geant3...'
Swallow -f 'Sourcing envvars' SourceEnvVars
Swallow 'Checking if Geant3 support has been requested' [ "$G3_VER" != '' ] || return
Swallow 'Checking that we are not using an external Geant3' [ "$G3_VER" != EXTERNAL ] || return
# Geant3 variables: only ${ALICE_PREFIX} and ${G3_VER} needed
local Geant3Git="${ALICE_PREFIX}/geant3/git"
local Geant3Base="${ALICE_PREFIX}/geant3/${G3_SUBDIR}"
local Geant3Inst="${Geant3Base}/inst"
local Geant3Src="${Geant3Base}/src"
local Geant3Tmp="${Geant3Base}/build"
if [[ "$DOWNLOAD_MODE" == '' || "$DOWNLOAD_MODE" == 'only' ]] ; then
#
# Git clone of Geant3
#
Swallow -f "Creating Geant3 Git clone directory" mkdir -p "$Geant3Git"
Swallow -f "Moving to the Geant3 Git clone directory" cd "$Geant3Git"
if [[ ! -d "${Geant3Git}/.git" ]] ; then
SwallowProgress -f --pattern 'Cloning Geant3 Git repository' \
git clone http://root.cern.ch/git/geant3.git .
fi
SwallowProgress -f 'Synchronizing Git clone' \
GitSync origin
# Updating from the former installation schema (no inst and build dir)
if [[ -e "${Geant3Base}/README" ]] ; then
Swallow -f 'Clean up directory from the old installation schema' rm -rf "${Geant3Base}"
fi
# Shallow copy with git-new-workdir
if [[ ! -d "${Geant3Src}/.git" ]] ; then
rmdir "$Geant3Src" > /dev/null 2>&1
SwallowProgress -f --pattern \
"Creating a local clone for version ${G3_VER}" \
git-new-workdir "$Geant3Git" "$Geant3Src" "$G3_VER"
fi
Swallow -f "Moving to local clone for version ${G3_VER}" cd "$Geant3Src"
Swallow -f "Checking out Geant3 version ${G3_VER}" git checkout "$G3_VER"
if [[ $ForceCleanSlate == 1 ]] ; then
Swallow -f "Forcing hard reset to remote ${G3_VER}" GitResetHard origin "$G3_VER"
Swallow -f 'Forcing cleanup of working directory' git clean -f -d
elif [[ "$(git rev-parse --abbrev-ref HEAD)" != 'HEAD' ]] ; then
# update only if on a branch: errors are fatal
SwallowProgress -f --pattern "Updating Geant3 branch ${G3_VER}" git pull --rebase
fi
fi # end download
if [ "$DOWNLOAD_MODE" == '' ] || [ "$DOWNLOAD_MODE" == 'no' ] ; then
#
# Build Geant3
#
Swallow -f "Moving to the local Git clone for Geant3 version $G3_VER" cd "$Geant3Src"
export CCACHE_BASEDIR="$Geant3Base"
if [[ -e Makefile ]] ; then
# Prior to version ~v2-0: no CMake, only make
Swallow -f 'Preparing build directory' rsync -ca --exclude '**/.git' "$Geant3Src"/ "$Geant3Tmp"/
Swallow -f 'Move to the temporary build directory' cd "$Geant3Tmp"
SwallowProgress -f --pattern 'Building Geant3' make -j$MJ
# Fake installation
Swallow -f 'Cleaning up installation path' rm -rf "$Geant3Inst"
Swallow -f 'Creating installation directory' mkdir -p "${Geant3Inst}/include/TGeant3/"
Swallow -f 'Installing header files' \
cp "${Geant3Tmp}/TGeant3/"*.h "${Geant3Inst}/include/TGeant3/"
Swallow -f 'Installing libraries' \
rsync -a "${Geant3Tmp}/lib/tgt_$(root-config --arch)/" "${Geant3Inst}/lib/"
else
# From ~v2-0: CMake
Swallow -f 'Creating build directory' mkdir -p "$Geant3Tmp"
Swallow -f 'Moving to the temporary build directory' cd "$Geant3Tmp"
# Note: ROOTSYS can be also passed as -DROOT_DIR, but ROOT paths must be set in the env :-(
SwallowProgress -f --pattern 'Bootstrapping Geant3' \
cmake "$Geant3Src" -DCMAKE_INSTALL_PREFIX="$Geant3Inst"
SwallowProgress -f --percentage "Building Geant3 ${G3_VER}" make -j$MJ
Swallow -f 'Removing previous installation directory' rm -rf "$Geant3Inst"
SwallowProgress -f --percentage "Installing Geant3 ${G3_VER}" make -j$MJ install
fi
unset CCACHE_BASEDIR
fi
}
# Module to fetch and compile FastJet
function ModuleFastJet() {
local MinFastJetVerStr='v3.0.6'
local MinFastJetVerNum=$( ConvertVersionStringToNumber "$MinFastJetVerStr" )
# FastJet versions will be downloaded from tarballs on the official website
local FASTJET_URL_PATTERN='http://fastjet.fr/repo/fastjet-%s.tar.gz'
local FASTJET_TARBALL='source.tar.gz'
# FastJet contrib
local FJCONTRIB_URL_PATTERN='http://fastjet.hepforge.org/contrib/downloads/fjcontrib-%s.tar.gz'
local FJCONTRIB_TARBALL='contrib.tar.gz'
Banner 'Installing FastJet...'
Swallow -f 'Sourcing envvars' SourceEnvVars
Swallow 'Checking if FastJet support has been requested' [ "$FASTJET_VER" != '' ] || return
Swallow --fatal \
--error-msg "FastJet $FASTJET_VER is not supported: use at least $MinFastJetVerStr." \
"Ensuring FastJet $FASTJET_VER is supported" \
[ $( ConvertVersionStringToNumber "$FASTJET_VER" ) -ge $MinFastJetVerNum ]
Swallow --fatal \
--error-msg 'FastJet contrib is mandatory when installing FastJet.' \
'Ensuring FastJet contrib is enabled' \
[ "$FJCONTRIB_VER" != '' ]
# FastJet variables: from $FASTJET (no build directory)
local FastJetBase="$( dirname "$FASTJET" )"
local FastJetInst="$FASTJET"
local FastJetSrc="${FastJetBase}/src"
Swallow -f 'Creating FastJet directory' mkdir -p "$FastJetSrc"
if [[ -d "${FastJetBase}/bin" || -d "${FastJetBase}/lib" || -d "${FastJetBase}/include" ]] ; then
Swallow -f 'Removing FastJet from old installation schema' \
rm -rf "$FastJetBase"/{bin,lib,include}
fi
if [[ "$DOWNLOAD_MODE" == '' || "$DOWNLOAD_MODE" == 'only' ]] ; then
#
# Download, unpack and patch FastJet tarball
#
Swallow -f 'Moving into FastJet source directory' cd "$FastJetSrc"
if [[ ! -e "$FASTJET_TARBALL" ]] ; then
SwallowProgress -f --percentage "Downloading FastJet v$FASTJET_VER" \
Dl $( printf "$FASTJET_URL_PATTERN" "$FASTJET_VER" ) "$FASTJET_TARBALL"
fi
if [[ ! -f fastjet-"$FASTJET_VER"/configure ]] ; then
Swallow -f 'Removing old FastJet source directory' rm -rf fastjet-"$FJCONTRIB_VER"
SwallowProgress -f --pattern 'Unpacking FastJet tarball' \
tar xzvvf "$FASTJET_TARBALL"
fi
if [[ $FJCONTRIB_VER != '' ]] ; then
# Optional FastJet contrib
if [[ ! -e "$FJCONTRIB_TARBALL" ]] ; then
SwallowProgress -f --percentage "Downloading FastJet contrib v$FJCONTRIB_VER" \
Dl $( printf "$FJCONTRIB_URL_PATTERN" "$FJCONTRIB_VER" ) "$FJCONTRIB_TARBALL"
fi
if [[ ! -f fjcontrib-"$FJCONTRIB_VER"/configure ]] ; then
Swallow -f 'Removing old FastJet contrib source directory' rm -rf fjcontrib-"$FJCONTRIB_VER"
SwallowProgress -f --pattern 'Unpacking FastJet contrib tarball' \
tar xzvvf "$FJCONTRIB_TARBALL"
fi
fi
if [[ $FASTJET_PATCH_HEADERS == 1 ]]; then
# Patching FastJet headers: libc++ fixup
function FastJetPatchLibcpp() {
find . -name '*.h' -or -name '*.hh' | \
while read F; do
echo '#include <cstdlib>' > "$F.0" && \
cat "$F" | grep -v '#include <cstdlib>' >> "$F.0" && \
\mv -f "$F.0" "$F" || return 1
done
}
Swallow -f 'Patching FastJet headers: libc++ workaround' FastJetPatchLibcpp
unset FastJetPatchLibcpp
fi
fi
if [[ "$DOWNLOAD_MODE" == '' || "$DOWNLOAD_MODE" == 'no' ]] ; then
#
# Build FastJet
#
Swallow -f 'Moving into FastJet build directory' cd "${FastJetSrc}/fastjet-$FASTJET_VER"
case "$BUILD_MODE" in
gcc)
export CXX=$( which g++ )
;;
clang)
export CXX=$( which clang++ )
;;
custom-gcc)
export CXX=$CUSTOM_GCC_PATH/bin/g++
;;
esac
# Build type: optimization level and debug symbols
case $BuildType in
debug)
FastJetOptDbgFlags='-O0 -g'
;;
normal)
FastJetOptDbgFlags='-O2 -g'
;;
optimized)
FastJetOptDbgFlags='-O3'
;;
esac
export CCACHE_BASEDIR="$FastJetBase"
# Exporting this variable is relevant to FastJet's configure, while FJ contrib's Makefile picks
# it directly from the environment
export CXXFLAGS="${BUILDOPT_LDFLAGS} ${FastJetOptDbgFlags} -lgmp -lCGAL"
SwallowProgress -f --pattern 'Configuring FastJet' \
./configure --enable-cgal --prefix="$FastJetInst"
SwallowProgress -f --pattern 'Building FastJet' make -j$MJ
Swallow -f 'Removing old FastJet installation' rm -rf "$FastJetInst"
SwallowProgress -f --pattern 'Installing FastJet' make -j$MJ install
if [[ "$FJCONTRIB_VER" != '' ]] ; then
#
# Build FastJet contrib (optional)
#
Swallow -f 'Sourcing envvars' SourceEnvVars
Swallow -f 'Moving into FastJet contrib build directory' \
cd "${FastJetSrc}/fjcontrib-$FJCONTRIB_VER"
SwallowProgress -f --pattern 'Configuring FastJet contrib' \
./configure CXX="$CXX" CXXFLAGS="$CXXFLAGS"
SwallowProgress --pattern 'Building FastJet contrib' make -j$MJ
SwallowProgress -f --pattern 'Building FastJet contrib shared library' \
make -j$MJ fragile-shared
# No need to clean up old installation: already done for FastJet base package
SwallowProgress --pattern 'Installing FastJet contrib' make install
SwallowProgress -f --pattern 'Installing FastJet contrib shared library' \
make fragile-shared-install
fi
unset CXXFLAGS CXX CCACHE_BASEDIR
fi
}
# Function to force-set a remote in a Git repository
# $1: remote name
# $2: URL
# $3 (optional): push URL (in this case, $2 is the fetch URL)
# Returns nonzero on error
function GitForceSetRemote() (
gitFetchUrl="$2"
if [[ $3 != '' ]] ; then
gitPushUrl="$3"
else
gitPushUrl="$gitFetchUrl"
fi
git remote set-url "$1" "$gitFetchUrl" || git remote add "$1" "$gitFetchUrl"
git remote set-url --push "$1" "$gitPushUrl" || git remote add --push "$1" "$gitPushUrl"
)
# Function to checkout a local branch, if it exists. If it does not, create a
# new one and track the corresponding one from the remote
# $1: branch name
# $2: remote name
# Returns nonzero on error
function GitCheckoutTrack() (
local branch="$1"
local remote="$2"
git checkout "$branch" || git checkout -b "$branch" --track "${remote}/${branch}"
)
# Works around a problem with the original git-new-workdir which is unable to
# deal properly with multiple remotes
# $1: Git reference directory
# $2: destination source
# $3: remote name
# $4: branch to checkout
function GitNewWorkdir() (
local ref="$1"
local src="$2"
local remote="$3"
local branch="$4"
git-new-workdir "$ref" "$src" "$branch"
GitCheckoutTrack "$branch" "$remote"
)
# Synchronizes the local Git clone with the remote copy.
# $1: remote name
# Returns nonzero on error
function GitSync() (
local remote="$1"
git remote update "$remote" --prune && \
git fetch "$remote" && \
git fetch "$remote" --tags
)
# Force-reset to either a remote head or tag.
# $1: remote name
# $2: version name
# Returns nonzero on error
function GitResetHard() (
local remote="$1"
local vers="$2"
git reset --hard "${remote}/${vers}" || git reset --hard "${vers}"
)
# Module to fetch, update and compile AliRoot
function ModuleAliRoot() {
local GenerateDoc="$1"
local ForceCleanSlate="$2"
local Pedantic="$3"
local CMakeCxxFlags
Banner 'Installing AliRoot Core...'
Swallow -f 'Sourcing envvars' SourceEnvVars
Swallow 'Checking that we are not using an external AliRoot Core' \
[ "$ALICE_VER" != EXTERNAL ] || return
# AliRoot variables: only ${ALICE_ROOT} needed
# - ${ALICE_ROOT}: installation directory
# - ${ALICE_ROOT}/../build: build directory
# - ${ALICE_ROOT}/../src: source directory
local AliRootBase=$( dirname "${ALICE_ROOT}" )
local AliRootInst="$ALICE_ROOT"
local AliRootSrc="${AliRootBase}/src"
local AliRootTmp="${AliRootBase}/build"
# AliRoot remote name
local AliRootGitRemote='alicern'
# AliRoot Git private and public URLs
local AliRootGitUrlPub='http://git.cern.ch/pub/AliRoot'
local AliRootGitUrlPriv='https://git.cern.ch/reps/AliRoot'
if [[ ! -d "$AliRootTmp" ]]; then
Swallow -f "Creating AliRoot build directory" mkdir -p "$AliRootTmp"
fi
if [[ "$DOWNLOAD_MODE" == '' || "$DOWNLOAD_MODE" == 'only' ]] ; then
#
# Download AliRoot from Git
#
# The directory AliRootGit contains the only Git clone pointing by default
# to the remote Git reposiory of ALICE. All other Git clones point to this
# directory instead
local AliRootGit="${AliRootBase}/../git"
Swallow -f 'Creating AliRoot Git local directory' mkdir -p "$AliRootGit"
Swallow -f 'Moving into AliRoot Git local directory' cd "$AliRootGit"
if [[ ! -e "$AliRootGit/.git" ]] ; then
SwallowProgress -f --pattern \
'Cloning AliRoot Git repository (might take some time)' \
git clone "$AliRootGitUrlPub" .
fi
AliRootGit=$(cd "$AliRootGit";pwd)
# Setting a public and private remote
Swallow -f 'Setting ALICE Git pull/push URLs' \
GitForceSetRemote "$AliRootGitRemote" "$AliRootGitUrlPub" "$AliRootGitUrlPriv"
SwallowProgress -f 'Synchronizing Git clone' \
GitSync "$AliRootGitRemote"
# Source is ${AliRootSrc} his will be a Git directory on its own that shares
# the object database, but with its own index. This is possible via the
# git-new-workdir[1] script
# [1] http://nuclearsquid.com/writings/git-new-workdir/