forked from zoglauer/megalib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·643 lines (548 loc) · 18.2 KB
/
configure
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
#!/bin/bash
# This file is part of MEGAlib.
# Copyright (C) by Andreas Zoglauer.
#
# Please see the MEGAlib software license and documentation for more informations.
# Part 1:
# Helper functions
confhelp() {
echo ""
echo "Configuration script for MEGAlib"
echo ""
echo "Usage: ./configure [options]";
echo ""
echo ""
echo "Options:"
echo "--architecture=[linux, macosx]"
echo " Default is autodetected via uname -a, thus there should be no need to give this option!"
echo " "
echo "--optimization=[off/no, normal/on/yes, strong/hard (requires gcc 4.2 or higher)]"
echo " Default is normal."
echo " "
echo "--debug=[off/no, on/yes, strong/hard]"
echo " Default is on."
echo " Strong enables the address sanitizer on Linux with gcc to detect memory access errors."
echo " "
echo "--compiler=[gcc, clang, icc]"
echo " This currently only works on Linux. Default is gcc. On a Mac always the default compiler is used."
echo " "
echo "--updates=[off/no, on/yes]"
echo " Check periodically for updates. Default is off."
echo " Even if set to on, update checks will only be performed, if the user has write access to the MEGAlib installation."
echo " "
echo "--help or -h"
echo " Show this help."
echo " "
echo ""
echo "Examples:"
echo " ./configure --optimization=normal --debug=off"
echo " It is possible to reduce the command line to the bare minimum which is still unique, e.g. "
echo " ./configure -o=y -d=n"
echo " "
}
# Part 2:
# A first sanity check
if [ "$SHELL" != "/bin/bash" ]; then
echo " "
echo "Info: This is a bash script. Thus you need to use bash for it and not: ${SHELL}"
echo " "
fi
# Part 3:
# Upgrade the input options:
# Store command line
CMD=""
while [[ $# -gt 0 ]] ; do
CMD="${CMD} $1"
shift
done
# Check for help
for C in ${CMD}; do
if [[ ${C} == *-h* ]]; then
echo ""
confhelp
exit 0
fi
done
echo ""
echo ""
echo ""
echo "Configuring MEGAlib for compilation on your system"
echo "=================================================="
echo ""
echo " "
echo "(1) Verifying chosen configuration options:"
echo " "
# Remove the old configuration store
rm -f config/configure_lastgoodoptions
# Default options:
OS=`uname -s`
OPT="normal"
DEBUG="on"
COMP="gcc"
UPDATES="off"
# Overwrite default options with user options:
for C in ${CMD}; do
if [[ ${C} == *-a*=* ]]; then
OS=`echo ${C} | awk -F"=" '{ print $2 }'`
elif [[ ${C} == *-o*=* ]]; then
OPT=`echo ${C} | awk -F"=" '{ print $2 }'`
elif [[ ${C} == *-d*=* ]]; then
DEBUG=`echo ${C} | awk -F"=" '{ print $2 }'`
elif [[ ${C} == *-u*=* ]]; then
UPDATES=`echo ${C} | awk -F"=" '{ print $2 }'`
elif [[ ${C} == *-c*=* ]]; then
COMP=`echo ${C} | awk -F"=" '{ print $2 }'`
elif [[ ${C} == --linux ]]; then
OS="linux"
elif [[ ${C} == --macosx ]]; then
OS="darwin"
elif [[ ${C} == --debug ]]; then
DEBUG="on"
elif [[ ${C} == --optimize* ]]; then
OPT="on"
elif [[ ${C} == *-h* ]]; then
echo ""
confhelp
exit 0
else
echo ""
echo "ERROR: Unknown command line option: ${C}"
echo " See \"./configure --help\" for a list of options"
exit 1
fi
done
# Everything to lower case:
OS=`echo ${OS} | tr '[:upper:]' '[:lower:]'`
OPT=`echo ${OPT} | tr '[:upper:]' '[:lower:]'`
DEBUG=`echo ${DEBUG} | tr '[:upper:]' '[:lower:]'`
COMP=`echo ${COMP} | tr '[:upper:]' '[:lower:]'`
UPDATES=`echo ${UPDATES} | tr '[:upper:]' '[:lower:]'`
# provide feed back and perform error checks:
if [[ ${OS} == l* ]]; then
OS="linux"
echo " * Using operating system architecture Linux"
elif ( [[ ${OS} == d* ]] || [[ ${OS} == m* ]] ); then
OS="darwin"
echo " * Using operating system architecture Darwin (Mac OS X)"
else
echo " "
echo "ERROR: Unknown operating system architecture: ${OS}"
confhelp
exit 1
fi
if ( [[ ${OPT} == of* ]] || [[ ${OPT} == no ]] ); then
OPT="off"
echo " * Using no code optimization"
elif ( [[ ${OPT} == nor* ]] || [[ ${OPT} == on ]] || [[ ${OPT} == y* ]] ); then
OPT="normal"
echo " * Using normal code optimization"
elif ( [[ ${OPT} == s* ]] || [[ ${OPT} == h* ]] ); then
OPT="strong"
echo " * Using strong code optimization"
else
echo " "
echo "ERROR: Unknown code optimization: ${OPT}"
confhelp
exit 1
fi
if ( [[ ${DEBUG} == of* ]] || [[ ${DEBUG} == no ]] ); then
DEBUG="off"
echo " * Using no debugging code"
elif ( [[ ${DEBUG} == on ]] || [[ ${DEBUG} == y* ]] || [[ ${DEBUG} == nor* ]] ); then
DEBUG="normal"
echo " * Using debugging code"
elif ( [[ ${DEBUG} == st* ]] || [[ ${DEBUG} == h* ]] ); then
DEBUG="strong"
echo " * Using more debug flags"
else
echo " "
echo "ERROR: Unknown debugging code selection: ${DEBUG}"
confhelp
exit 1
fi
if ( [[ ${COMP} == g* ]] ); then
COMP="gcc"
command -v g++ >/dev/null 2>&1 || { echo " "; echo "Error: gnu gcc is not installed!"; exit 1; }
echo " * Using gnu compiler"
elif ( [[ ${COMP} == c* ]] ); then
COMP="clang"
command -v clang++ >/dev/null 2>&1 || { echo " "; echo "Error: clang is not installed!"; exit 1; }
echo " * Using clang compiler"
elif ( [[ ${COMP} == i* ]] ); then
COMP="icc"
command -v icc >/dev/null 2>&1 || { echo " "; echo "Error: icc is not installed!"; exit 1; }
echo " * Using icc compiler"
else
echo " "
echo "ERROR: Unknown compiler option: ${COMP}"
confhelp
exit 1
fi
if ( [[ ${UPDATES} == of* ]] || [[ ${UPDATES} == n* ]] ); then
UPDATES="off"
echo " * Don't check for updates"
elif ( [[ ${UPDATES} == on ]] || [[ ${UPDATES} == y* ]] ); then
UPDATES="on"
echo " * Check for updates if the user has write access to the MEGAlib installation"
else
echo " "
echo "ERROR: Unknown option for updates: ${UPDATES}"
confhelp
exit 1
fi
# Part 4:
# Check if all programs are available
# Start configuration
echo ""
echo ""
echo "(2) Testing paths and programs:"
# Check for path to MEGAlib
echo ""
echo "(a) MEGAlib"
echo ""
if ( `test -d $MEGALIB` && [ "$MEGALIB" != "" ] ); then
echo "Found MEGAlib: $MEGALIB";
else
echo "MEGAlib installation directory not found!";
echo ""
echo "--> Please add the path to MEGAlib to your resource file (e.g. .bashrc or .tcshrc)";
echo " Example for .bashrc: export MEGALIB=$HOME/MEGAlib";
echo " Example for .tcshrc: setenv MEGALIB ${HOME}/MEGAlib";
echo "--> If you are trying to run this script with sudo, your existing environment variables might not be transferred";
echo " Instead of \"sudo ./configure ...\", try \"sudo bash\" and then configure."
echo ""
exit 1
fi
# Check for ROOT
echo ""
echo "(b) ROOT"
echo ""
bash ${MEGALIB}/config/configure_checkpath exe root
FoundROOTExe=$?;
if [ $FoundROOTExe -eq 0 ]; then
echo "ROOT program not found or not executable!"
echo ""
echo "--> If ROOT is not installed, then install it first!"
echo "--> If ROOT is installed, make sure that your PATH variable contains a folder which contains root,"
echo " that you have read access to the ROOT directory, and that ROOT is executable"
echo "--> If ROOT is installed, the PATH is set, and you run this script via sudo, then you have to make"
echo " sure you have set the PATH globally and not just for the user as the PATH variable might not be"
echo " transferred via sudo"
echo " Thus instead of \"sudo -E ./configure ...\", try \"sudo bash\" and then configure."
echo ""
exit 0;
fi
bash ${MEGALIB}/config/configure_checkpath lib libCore
FoundROOTLibs=$?;
if [ $FoundROOTLibs -eq 0 ]; then
echo "ROOT libraries not found or not readable/accessable (test case: the \"Core\" library)!"
echo ""
echo "--> If ROOT is not installed, then install it first!"
echo "--> If ROOT is installed, make sure your LD_LIBRARY_PATH variable contains a folder "
echo " which contains the root libraries (on Mac it's the DYLD_LIBRARY_PATH) and"
echo " that you have read access to the libraries"
echo ""
exit 0;
fi
echo "Found ROOT: $(which root)";
bash ${MEGALIB}/config/configure_rootversiontest -s;
RootVersionOK=$?;
if [ $RootVersionOK -eq 1 ]; then
exit 1
fi
# Check for Geant4
echo ""
echo "(c) GEANT4"
echo ""
Geant4Found=1;
Geant4DawnFileFound=1;
Geant4OpenGLFound=1;
bash ${MEGALIB}/config/configure_checkpath lib libG4event
FoundGeant4Libs=$?;
if [ $FoundGeant4Libs -eq 0 ]; then
echo "Geant4 libraries not found (test case: the \"G4event\" library)!"
echo ""
echo "Geant4 is not required for all parts of MEGAlib:"
echo "--> This is only a problem if you want to do simulations with Cosima, "
echo " you can use the rest of MEGAlib without it."
echo " If you reinstall GEANT4 later, please rerun configure and recompile"
echo ""
echo "But if you want to do simulations:"
echo "--> If Geant4 is not installed, then install it first!"
echo "--> If Geant4 is installed, make sure your LD_LIBRARY_PATH variable contains a folder,"
echo " which contains the Geant4 libraries (on Mac it's the DYLD_LIBRARY_PATH) and "
echo " make sure you have read access to the libraries!"
Geant4Found=1
else
GEANT4CONFIG=`type -P geant4-config`
if ([ "${GEANT4CONFIG}" != "" ]); then
echo "Found Geant4: $(geant4-config --prefix)";
else
echo "Found Geant4: ${G4INSTALL} on ${G4SYSTEM}";
fi
Geant4Found=0;
bash ${MEGALIB}/config/configure_geant4versiontest -s;
Geant4VersionOK=$?;
if [ $Geant4VersionOK -eq 1 ]; then
Geant4Found=1;
fi
Geant4OpenGLFound=1
if [ "${G4VIS_USE_OPENGLX}" == "1" ]; then
echo "Found Geant4 visualization: OPENGLX";
Geant4OpenGLFound=0;
fi;
fi
# Check for path to cfitsio library
echo ""
echo "(d) cfitsio library (optional)"
echo ""
FitsIOFound=1
if [[ ${LHEASOFT} != "" ]] && ( [[ -f ${LHEASOFT}/lib/libcfitsio.a ]] || [[ -f ${LHEASOFT}/lib/libcfitsio.so ]] ); then
echo "Found cfitsio library in ${LHEASOFT}/lib";
FitsIOFound=0
else
locate libcfitsio &> /dev/null
if [[ "$?" == "0" ]]; then
echo "Found exiting cfitsio in a system path";
FitsIOFound=0
fi
fi
if [ ${FitsIOFound} == 1 ]; then
echo "cfitsio not found"
echo ""
echo "-> cfitsio is only required if you want to read / write fits files.";
echo " This is very rarely the case. Thus you might just ignore that message."
echo " If you reinstall cfitsio later, please re-run configure and recompile";
FitsIOFound=1
fi
# Check for MPI tools
echo ""
echo "(e) MPI tools (optional)"
echo ""
MPIFound=0
if ( [ -f /usr/include/mpi/mpi.h ] ); then
echo "Found MPI header";
if hash mpirun 2>/dev/null; then
echo "Found mpirun executable"
else
echo "-> Couldn't find the MPI run executable."
echo " Deactivating the compilation of the MPI parts of MEGAlib."
echo " But don't worry. Everything is fine. You normally wouldn't need them anyway."
MPIFound=1
fi
else
echo "-> Couldn't find the MPI header file in /usr/include/mpi."
echo " Deactivating the compilation of the MPI parts of MEGAlib."
echo " But don't worry. Everything is fine. You normally wouldn't need them anyway."
MPIFound=1
fi
# Check for other little helper programs
echo ""
echo "(f) Miscellaneous helper tools"
echo ""
bash ${MEGALIB}/config/configure_misctools -s;
MiscTest=$?;
if [ $MiscTest -eq 1 ]; then
echo ""
echo "-> The miscellaneous helper tools are not mandatory, and only required by secondary programs and functions."
echo " Thus you can continue, if one is missing and install it later when you need it."
echo ""
fi
# Part 5:
# Setup the make environment
echo ""
echo ""
echo "(3) Preparing the Makefiles:"
echo ""
# Choose main Makefile
if [[ ${OS} == linux ]]; then
if [[ ${COMP} == gcc ]]; then
echo "Configuring for Linux with gnu gcc compiler ..."
cp config/Makefile.linuxgcc config/Makefile.config
elif [[ ${COMP} == icc ]]; then
echo "Configuring for Linux with Intel icc compiler ..."
cp config/Makefile.linuxicc config/Makefile.config
elif [[ ${COMP} == clang ]]; then
echo "Configuring for Linux with clang compiler ..."
cp config/Makefile.linuxclang config/Makefile.config
else
echo " "
echo "ERROR: Compiler not supported for linux: ${COMP}"
confhelp
exit 1
fi
elif [[ ${OS} == darwin ]]; then
if [[ ${COMP} == gcc ]]; then
echo "Configuring for MaxOSX ..."
cp config/Makefile.macosx config/Makefile.config
else
echo " "
echo "ERROR: Compiler not supported for linux: ${COMP}"
confhelp
exit 1
fi
else
echo " "
echo "ERROR: Unknown operating system architecture: ${OS}"
confhelp
exit 1
fi
# Set default values for the options
OPTIONS=""
if [[ ${OPT} == normal ]]; then
if [[ ${COMP} == gcc ]] && [[ ${DEBUG} != off ]]; then
OPTIONS+=" -Og"
else
OPTIONS+=" -O -DNDEBUG"
fi
elif [[ $OPT == strong ]]; then
if [[ ${COMP} == gcc ]]; then
if [[ ${DEBUG} != off ]]; then
OPTIONS+=" -Og"
else
OPTIONS+=" -O3 -mtune=native -fno-strict-aliasing -DNDEBUG"
fi
else
OPTIONS+=" -O2 -DNDEBUG"
fi
fi
G4DEBUG="G4DEBUG = 0"
if [[ ${DEBUG} == normal ]] || [[ ${DEBUG} == strong ]]; then
G4DEBUG="G4DEBUG = 1"
OPTIONS+=" -g"
if [[ ${DEBUG} == strong ]]; then
OPTIONS+=" -DDEBUG1"
if [[ ${COMP} == gcc ]] && [[ ${OS} == linux ]]; then
OPTIONS+=" -fsanitize=address"
fi
fi
fi
# Dump the options
rm -f config/Makefile.options
if ([ "${OPTIONS}" != "" ]); then
echo ""
echo "Adding the following compiler optimizations: "
echo "OPT =${OPTIONS}"
if ( [ $Geant4Found -eq 0 ] ); then
echo "$G4DEBUG"
fi
fi
echo "# Additional platform independend Makefile options" >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# This file is overwritten the next time configure is called." >> config/Makefile.options
echo "# If you want to define your own user options, then defined them in Makefile.user" >> config/Makefile.options
echo " " >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# Section A: Additional libraries" >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# Important: Don't modify this sections by yourself " >> config/Makefile.options
echo " " >> config/Makefile.options
echo "GEANT4INSTALLED := ${Geant4Found}" >> config/Makefile.options
echo "HEASOFTINSTALLED := ${FitsIOFound}" >> config/Makefile.options
echo "MPIINSTALLED := ${MPIFound}" >> config/Makefile.options
echo " " >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# Section B: Compiler optimizations" >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# Important comments" >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# If you want to eliminate all massert, mdebug, etc. code use: -DNDEBUG" >> config/Makefile.options
echo "# If you want to produce debug infos in your executables use: -g" >> config/Makefile.options
echo "# The default optimization level is: -O" >> config/Makefile.options
echo "# You can combine all those options: -O -g -DNDEBUG" >> config/Makefile.options
echo "# " >> config/Makefile.options
if [[ ${COMP} = icc ]]; then
cat config/Makefile.icc_optimizations >> config/Makefile.options
fi
if [[ ${ARCH} == linux ]]; then
cat config/Makefile.gcc_optimizations >> config/Makefile.options
fi
echo "Please see the file config/Makefile.options for more optimization options for the Intel and GNU compiler"
echo "" >> config/Makefile.options
echo "OPT := ${OPTIONS}" >> config/Makefile.options
if ( [ $Geant4Found -eq 0 ] ); then
echo "$G4DEBUG" >> config/Makefile.options
fi
echo "" >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# Section C: Geant4 visualization options" >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "# Important: Only OpenGL and DawnFile can be detected by this script " >> config/Makefile.options
echo "# If you have anything else, set it in Makefile.user " >> config/Makefile.options
echo "# " >> config/Makefile.options
echo "" >> config/Makefile.options
if ( [ $Geant4OpenGLFound -eq 0 ] ); then
echo "G4VIS_USE_OPENGLX := 1" >> config/Makefile.options
fi
if ( [ $Geant4DawnFileFound -eq 0 ] ); then
echo "G4VIS_USE_DAWNFILE := 1" >> config/Makefile.options
fi
echo "" >> config/Makefile.options
# If the file config/Makefile.user not exists, create it
if (`test ! -f config/Makefile.user`); then
echo "# Addional user options for the makefile can be set here" >> config/Makefile.user
echo "# This file is not overwritten during the configure process" >> config/Makefile.user
echo " " >> config/Makefile.user
echo " " >> config/Makefile.user
fi
# Part 6:
# Final preparations and clean up
echo ""
echo ""
echo "(4) Preparing for compilation:"
# Check if all directories are present, if not create them
if (`test ! -d include`); then
echo ""
echo "Creating directory include"
mkdir include
fi
if (`test ! -d lib`); then
echo "Creating directory lib"
mkdir lib
fi
# Cosima paths --- we are performing some removes, thus try to make sure we don't remove anything wrong
if ( [ $Geant4Found -eq 0 ] && [ "${G4SYSTEM}" != "" ] ); then
rm -rf src/cosima/bin
cd bin
if (`test -d ${G4SYSTEM}`); then
rm -r ${G4SYSTEM}
fi
cd ..
#ln -s ../../bin src/cosima/bin
#ln -s ../bin bin/${G4SYSTEM}
fi
# Create a developer list
echo ""
echo "Creating list of developers and contributors by parsing through all cpp, cxx, cc, etc. files..."
bash ${MEGALIB}/config/configure_developers -s;
# Store the current options:
echo "${CMD}" >> config/configure_lastgoodoptions
# Set the updates interval:
if [[ ${UPDATES} == off ]]; then
echo ""
echo "Making config/UpdateCheck.txt read-only to prevent periodical update checks..."
touch config/UpdateCheck.txt
chmod a-w config/UpdateCheck.txt
else
echo ""
echo "Setting up config/UpdateCheck.txt for periodical update checks..."
rm -f config/UpdateCheck.txt
cp config/Version.txt config/UpdateCheck.txt
fi
# Remove the old build
echo ""
echo "Removing old build..."
make clean
# Store configuration
echo ""
echo "Storing configuration..."
rm -f config/Configuration.txt
echo "COMPILER=$(gcc --version | head -n 1)" >> config/Configuration.txt
echo "PYTHON3=$(python3 --version)" >> config/Configuration.txt
echo "ROOT=$(root-config --version)" >> config/Configuration.txt
echo "GEANT4=$(geant4-config --version)" >> config/Configuration.txt
echo ""
echo ""
echo "Done! Now type 'make' to compile and link MEGAlib"
echo ""
exit 0