-
Notifications
You must be signed in to change notification settings - Fork 0
/
geant4-config
executable file
·651 lines (555 loc) · 17.4 KB
/
geant4-config
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
#!/bin/sh
#-----------------------------------------------------------------------
# sh config query script for Geant4 11.0.2 on UNIX platforms
# Autogenerated by CMake DO NOT EDIT
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Determine location of this script.
# NB, we don't always use the result of this calculation, but it does not
# hurt to do it. Only possible error is if too long a chain of symbolic
# links are used to point to the physical script.
#
# Resolve symbolic links to script - we should end up with a physical file
script="$0"
calldir=`pwd`
loopcount=""
while [ "x`readlink $script`" != "x" ] ; do
preloc=`dirname $script`
script=`readlink $script`
if [ ${script##/} = ${script##~} ] ; then
# The symbolic link was relative...
script="$preloc/$script"
fi
loopcount="l$loopcount"
if [ ${#loopcount} -gt 10 ] ; then
echo "error: more than 10 symbolic links to geant4-config traversed."
exit 1
fi
done
# If we still have a relative path, then it must be relative to the
# calling dir. NB we don't attempt to resolve directory symbolic
# links or remove '.' or '..'
if [ ${script##/} = ${script##~} ] ; then
script="$calldir/$script"
fi
#-----------------------------------------------------------------------
# Finally, grab the directory in which the script is located
# Used below should we be setup to be relocatable.
scriptloc=`dirname $script`
#-----------------------------------------------------------------------
# Expansion and calculation of all needed variables
#
prefix=$scriptloc/..
exec_prefix=
libdir=${prefix}/lib64
includedirs="${prefix}/include/Geant4"
name="geant4"
description="Geant4 toolkit for the simulation of the passage of particles through matter"
version="11.0.2"
# 'Requires' that may affect cflags and libs.
# Basic flags and libraries for visualization
vis_cflags="-DG4UI_USE_TCSH"
vis_libs="-lG4Tree \
-lG4FR \
-lG4GMocren \
-lG4visHepRep \
-lG4RayTracer \
-lG4VRML \
-lG4vis_management \
-lG4modeling"
#-----------------------------------------------------------------------
# Core setup...
#
cflags="-W -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe -pthread -ftls-model=initial-exec -std=c++17"
feature_list=""
# - CXX Standard
geant4_cxx_std="17"
# - static libs
have_staticlibs="no"
feature_list="${feature_list} staticlibs[${have_staticlibs}]"
# No action as yet
# - multithreading
have_multithreading="yes"
feature_list="${feature_list} multithreading[${have_multithreading}]"
if test "x${have_multithreading}" = "xyes" ; then
geant4_tls_model="initial-exec"
if test "x${geant4_tls_model}" = "xauto" ; then
geant4_tls_model=""
fi
else
geant4_tls_model=""
fi
# - smart stacking
have_smartstack="no"
feature_list="${feature_list} smartstack[${have_smartstack}]"
if test "x${have_smartstack}" = "xyes" ; then
cflags="-DG4_USESMARTSTACK ${cflags}"
fi
# - ParticleHP was built as HP. Pure feature
have_php_as_hp="no"
feature_list="${feature_list} php_as_hp[${have_php_as_hp}]"
# - Includes and Libs
for g4incdir in ${includedirs} ; do
cflags="${cflags} -I${g4incdir}"
done
libs="-lG4interfaces \
-lG4persistency \
-lG4error_propagation \
-lG4readout \
-lG4physicslists \
-lG4tasking \
-lG4run \
-lG4event \
-lG4tracking \
-lG4parmodels \
-lG4processes \
-lG4analysis \
-lG4digits_hits \
-lG4track \
-lG4particles \
-lG4geometry \
-lG4materials \
-lG4graphics_reps \
-lG4intercoms \
-lG4global \
-lG4tools \
"
#-----------------------------------------------------------------------
# - Extra optional features that were enabled.
# - ALL
geant4_uses_opengl="no"
geant4_uses_x11="no"
# - CLHEP
have_clhep="yes"
feature_list="${feature_list} clhep[${have_clhep}]"
if test "x${have_clhep}" = "xno" ; then
cflags="${cflags} -I"
libs="${libs} "
fi
if test "x${have_clhep}" = "xyes" ; then
libs="${libs} -lG4clhep"
fi
# - EXPAT
have_expat="no"
feature_list="${feature_list} expat[${have_expat}]"
if test "x${have_expat}" = "xyes" ; then
libs="${libs} -lG4expat"
fi
# - ZLIB
have_zlib="yes"
feature_list="${feature_list} zlib[${have_zlib}]"
if test "x${have_zlib}" = "xyes" ; then
libs="${libs} -lG4zlib"
fi
# - GDML
have_gdml="no"
feature_list="${feature_list} gdml[${have_gdml}]"
if test "x${have_gdml}" = "xyes" ; then
cflags="${cflags} "
fi
# - PTL
have_ptl="yes"
feature_list="${feature_list} ptl[${have_ptl}]"
if test "x${have_ptl}" = "xyes" ; then
libs="${libs} -lG4ptl"
fi
# - USolids
have_usolids="no"
feature_list="${feature_list} usolids[${have_usolids}]"
if test "x${have_usolids}" = "xyes" ; then
cflags="${cflags} "
fi
# - Freetype
have_freetype="no"
feature_list="${feature_list} freetype[${have_freetype}]"
# - HDF5
have_hdf5="no"
feature_list="${feature_list} hdf5[${have_hdf5}]"
# - G3toG4
have_g3tog4="no"
feature_list="${feature_list} g3tog4[${have_g3tog4}]"
if test "x${have_g3tog4}" = "xyes" ; then
libs="-lG3toG4 ${libs}"
fi
# - Qt
have_qt="no"
feature_list="${feature_list} qt[${have_qt}]"
if test "x${have_qt}" = "xyes" ; then
vis_cflags="${vis_cflags} \
-DG4UI_USE_QT -DG4VIS_USE_OPENGLQT "
if test "x${qt_version}" \< "5.15.0" ; then
vis_libs="-lG4visQt3D ${vis_libs}"
libs="-lG4visQt3D ${libs}"
vis_cflags="${vis_cflags} -DG4UI_USE_QT3D"
fi
geant4_uses_opengl="yes"
fi
# - Motif
have_motif="no"
feature_list="${feature_list} motif[${have_motif}]"
if test "x${have_motif}" = "xyes" ; then
vis_cflags="${vis_cflags} -DG4UI_USE_XM -DG4VIS_USE_OPENGLXM"
geant4_uses_x11="yes"
geant4_uses_opengl="yes"
fi
# - RayTracerX11
have_raytracerx11="no"
feature_list="${feature_list} raytracer-x11[${have_raytracerx11}]"
if test "x${have_raytracerx11}" = "xyes" ; then
vis_cflags="${vis_cflags} -DG4VIS_USE_RAYTRACERX"
geant4_uses_x11="yes"
fi
# - OpenGL with X11
have_openglx11="no"
feature_list="${feature_list} opengl-x11[${have_openglx11}]"
if test "x${have_openglx11}" = "xyes" ; then
vis_cflags="${vis_cflags} -DG4VIS_USE_OPENGLX"
geant4_uses_opengl="yes"
geant4_uses_x11="yes"
fi
# - OpenInventor
# Whilst it *is* an Xt based driver, don't *think* Xt or X11 appear
# in the public interface, nor do the Inventor headers...
have_openinventor="no"
feature_list="${feature_list} openinventor[${have_openinventor}]"
if test "x${have_openinventor}" = "xyes" ; then
vis_cflags="${vis_cflags} -DG4VIS_USE_OI -DG4VIS_USE_OIX"
vis_libs="-lG4OpenInventor ${vis_libs}"
fi
# - If we have any OpenGL based feature, then we need to add in the
# OpenGL global define and the G4OpenGL/G4gl2ps libraries.
if test "x${geant4_uses_opengl}" = "xyes" ; then
vis_cflags="-DG4VIS_USE_OPENGL ${vis_cflags}"
vis_libs="-lG4OpenGL -lG4gl2ps ${vis_libs}"
fi
# - If we have any X11 based feature, then we *may* need the X11 includes
if test "x${geant4_uses_x11}" = "xyes" ; then
vis_cflags=" ${vis_cflags}"
fi
#-----------------------------------------------------------------------
# Datasets
# - List creation for sh compatibility, see:
# https://wiki.ubuntu.com/DashAsBinSh
# Note however that the guide in the link uses the GNU awk extension
# 'length' to find the number of elements in the array. This will fail
# on other awk implementations. Use standard feature of split function
# returning number of elements.
dataset_url="https://cern.ch/geant4-data/datasets"
dataset_timeout="1500"
dataset_list=$(awk 'BEGIN { n = split( "G4NDL|G4NEUTRONHPDATA|/usr/local/share/Geant4-11.0.2/data/G4NDL4.6|G4NDL.4.6.tar.gz|d07e43499f607e01f2c1ce06d7a09f3e;G4EMLOW|G4LEDATA|/usr/local/share/Geant4-11.0.2/data/G4EMLOW8.0|G4EMLOW.8.0.tar.gz|6795805f39ac73a71333276756004d99;PhotonEvaporation|G4LEVELGAMMADATA|/usr/local/share/Geant4-11.0.2/data/PhotonEvaporation5.7|G4PhotonEvaporation.5.7.tar.gz|81ff27deb23af4aa225423e6b3a06b39;RadioactiveDecay|G4RADIOACTIVEDATA|/usr/local/share/Geant4-11.0.2/data/RadioactiveDecay5.6|G4RadioactiveDecay.5.6.tar.gz|acc1dbeb87b6b708b2874ced729a3a8f;G4PARTICLEXS|G4PARTICLEXSDATA|/usr/local/share/Geant4-11.0.2/data/G4PARTICLEXS4.0|G4PARTICLEXS.4.0.tar.gz|d82a4d171d50f55864e28b6cd6f433c0;G4PII|G4PIIDATA|/usr/local/share/Geant4-11.0.2/data/G4PII1.3|G4PII.1.3.tar.gz|05f2471dbcdf1a2b17cbff84e8e83b37;RealSurface|G4REALSURFACEDATA|/usr/local/share/Geant4-11.0.2/data/RealSurface2.2|G4RealSurface.2.2.tar.gz|ea8f1cfa8d8aafd64b71fb30b3e8a6d9;G4SAIDDATA|G4SAIDXSDATA|/usr/local/share/Geant4-11.0.2/data/G4SAIDDATA2.0|G4SAIDDATA.2.0.tar.gz|d5d4e9541120c274aeed038c621d39da;G4ABLA|G4ABLADATA|/usr/local/share/Geant4-11.0.2/data/G4ABLA3.1|G4ABLA.3.1.tar.gz|180f1f5d937733b207f8d5677f76296e;G4INCL|G4INCLDATA|/usr/local/share/Geant4-11.0.2/data/G4INCL1.0|G4INCL.1.0.tar.gz|85fe937b6df46d41814f07175d3f5b51;G4ENSDFSTATE|G4ENSDFSTATEDATA|/usr/local/share/Geant4-11.0.2/data/G4ENSDFSTATE2.3|G4ENSDFSTATE.2.3.tar.gz|6f18fce8f217e7aaeaa3711be9b2c7bf", array, ";"); for (i=1;i<=n;i++) { print array[i]; } }')
#-----------------------------------------------------------------------
# function print_datasets
# print dataset information with one line per dataset and each
# line in the format
# <NAME> <ENVVARNAME> <PATH>
print_datasets()
{
for ds in ${dataset_list} ; do
dataset_name=$(echo $ds | cut -d "|" -f1)
dataset_envvar=$(echo $ds | cut -d "|" -f2)
dataset_path=$(echo $ds | cut -d "|" -f3)
echo ${dataset_name} ${dataset_envvar} ${dataset_path}
done
exit 0
}
#-----------------------------------------------------------------------
# function check_datasets
# Check whether datasets exist as directories at the expected
# location. Print dataset name, path and install status
#
check_datasets()
{
for ds in ${dataset_list} ; do
dataset_name=$(echo $ds | cut -d "|" -f1)
dataset_path=$(echo $ds | cut -d "|" -f3)
dataset_status="NOTFOUND"
if test -d ${dataset_path} ; then
dataset_status="INSTALLED"
fi
echo ${dataset_name} ${dataset_status} ${dataset_path}
done
}
#-----------------------------------------------------------------------
# function install_datasets
# Download and install datasets if they are not already installed
#
install_datasets()
{
G4CURL=$(which curl)
if test "x${G4CURL}" = "x" ; then
echo "- error: no curl executable found"
exit 1
fi
G4OPENSSL=$(which openssl)
if test "x${G4OPENSSL}" = "x" ; then
echo "- error: no openssl executable found"
exit 1
fi
G4TAR=$(which tar)
if test "x${G4TAR}" = "x" ; then
echo "- error: no tar executable found"
exit 1
fi
datasets_to_install=''
for ds in ${dataset_list} ; do
dataset_path=$(echo $ds | cut -d "|" -f3)
if test ! -d ${dataset_path} ; then
datasets_to_install="${datasets_to_install} ${ds}"
fi
done
dataset_install="ok"
if test "x${datasets_to_install}" != "x" ; then
# - Create download cache
g4downloaddir=$(mktemp -d -t g4dlcXXXXXXXXXX)
if test -d ${g4downloaddir} ; then
echo "+ created download cache"
else
echo "- error : failed to create '${g4downloaddir}'"
dataset_install="fail"
break
fi
# - Download/install loop
for ds in ${datasets_to_install} ; do
# Create base path (repetitive)
dataset_path=$(echo $ds | cut -d "|" -f3)
mkdir -p $(dirname ${dataset_path})
if [ "$?" != "0" ] || [ ! -w $(dirname ${dataset_path}) ] ; then
echo "- error : failed to create base directory '$(dirname ${dataset_path})'"
dataset_install="fail"
break
fi
# - Download bundle to cache
dataset_file=$(echo $ds | cut -d "|" -f4)
echo "+ downloading ${dataset_file}"
${G4CURL} -L -f -m ${dataset_timeout} -o ${g4downloaddir}/${dataset_file} ${dataset_url}/${dataset_file}
curl_status="$?"
if [ "$curl_status" != "0" ] ; then
echo "- download of '${dataset_file}' failed : CURL error $?"
dataset_install="fail"
break
fi
# Validate bundle hash (basic)
dataset_md5=$(echo $ds | cut -d "|" -f5)
actual_md5=$(${G4OPENSSL} dgst -md5 ${g4downloaddir}/${dataset_file} | cut -d" " -f2)
echo "+ checking md5 of ${dataset_file}"
if [ "${actual_md5}" != "${dataset_md5}" ] ; then
echo "- md5 mismatch for '${dataset_file}' : ${actual_md5}(actual) != ${dataset_md5}(expected)"
dataset_install="fail"
break
fi
# Unpack bundle
echo "+ untar ${dataset_file}"
${G4TAR} -C ${g4downloaddir} -xf ${g4downloaddir}/${dataset_file}
tar_status="$?"
if [ "$tar_status" != "0" ] ; then
echo "- untar of '${dataset_file}' failed : tar error $?"
dataset_install="fail"
break
fi
# Install bundle
echo "+ installing $(basename ${dataset_path})"
cp -R ${g4downloaddir}/$(basename ${dataset_path}) $(dirname ${dataset_path})
cp_status="$?"
if [ "$cp_status" != "0" ] ; then
echo "- copy of '$(basename ${dataset_path})' failed : cp error $?"
# Extra task - remove anything copied...
rm -Rf ${dataset_path}
dataset_install="fail"
break
fi
done
# - Clean up download cache
rm -Rf ${g4downloaddir}
if test -d ${g4downloaddir} ; then
echo "- failed to remove '${g4downloaddir}'"
else
echo "+ cleaned download cache"
fi
fi
if [ "${dataset_install}" = "ok" ] ; then
echo "+ all datasets installed"
exit 0
else
echo "- dataset installation failed"
exit 1
fi
exit 1
}
#-----------------------------------------------------------------------
# function help
# print help on available command line arguments and enabled
# and disabled features of the toolkit
#
help()
{
cat<<EOF
Usage: geant4-config [OPTION...]
--prefix output installation prefix of Geant4
--version output version for Geant4
--cxxstd C++ Standard compiled against
--tls-model Thread Local Storage model used
--libs output all linker flags
--cflags output all preprocessor
and compiler flags
--libs-without-gui output linker flags without
GUI components
--cflags-without-gui output preprocessor and compiler
flags without GUI components
--has-feature FEATURE output yes if FEATURE is supported,
or no if not supported
--datasets output dataset name, environment variable
and path, with one line per dataset
--check-datasets output dataset name, installation status and
expected installation location, with one line
per dataset
--install-datasets download and install any missing datasets,
requires a network connection and for the dataset
path to be user writable
Known Features:
EOF
for f in ${feature_list} ; do
echo " $f"
done
cat<<EOF
Help options:
-?, --help show this help message
--usage display brief usage message
EOF
exit 1
}
#-----------------------------------------------------------------------
# function usage
# print basic usage message
#
usage()
{
cat<<EOF
Usage: geant4-config [--prefix] [--version] [--libs] [--cflags]
EOF
exit 1
}
#-----------------------------------------------------------------------
# Process arguments
#
if test $# -eq 0 ; then
usage
fi
while test $# -gt 0 ; do
case "$1" in
-*=*)
optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
;;
*)
optarg=
;;
esac
case "$1" in
--prefix)
echo ${prefix}
;;
--version)
echo ${version}
;;
--cxxstd)
echo ${geant4_cxx_std}
;;
--tls-model)
echo ${geant4_tls_model}
;;
--libs)
echo "-L${libdir}" ${vis_libs} ${libs}
;;
--cflags)
echo ${vis_cflags} ${cflags}
;;
--libs-without-gui)
echo "-L${libdir}" ${libs}
;;
--cflags-without-gui)
echo ${cflags}
;;
--has-feature)
shift
case "$1" in
static)
echo ${have_staticlibs}
;;
multithreading)
echo ${have_multithreading}
;;
smartstack)
echo ${have_smartstack}
;;
clhep)
echo ${have_clhep}
;;
expat)
echo ${have_expat}
;;
zlib)
echo ${have_zlib}
;;
gdml)
echo ${have_gdml}
;;
usolids)
echo ${have_usolids}
;;
freetype)
echo ${have_freetype}
;;
hdf5)
echo ${have_hdf5}
;;
g3tog4)
echo ${have_g3tog4}
;;
qt)
echo ${have_qt}
;;
motif)
echo ${have_motif}
;;
raytracer-x11)
echo ${have_raytracerx11}
;;
opengl-x11)
echo ${have_openglx11}
;;
openinventor)
echo ${have_openinventor}
;;
php_as_hp)
echo ${have_php_as_hp}
;;
*)
echo "no"
;;
esac
;;
--datasets)
print_datasets
;;
--check-datasets)
check_datasets
;;
--install-datasets)
install_datasets
;;
-?)
help
;;
--help)
help
;;
--usage)
usage
;;
*)
usage
;;
esac
shift
done
# Finally...
exit 0