forked from cdslaborg/paramonte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·1013 lines (834 loc) · 55.4 KB
/
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
####################################################################################################################################
####################################################################################################################################
#### ####
#### ParaMonte: Parallel Monte Carlo and Machine Learning Library. ####
#### ####
#### Copyright (C) 2012-present, The Computational Data Science Lab ####
#### ####
#### This file is part of the ParaMonte library. ####
#### ####
#### LICENSE ####
#### ####
#### https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md ####
#### ####
####################################################################################################################################
####################################################################################################################################
#### See the file install.sh.usage in the same folder for usage guidelines of this Batch script.
####
#### NOTE: Do not change the contents of this file unless you know what the consequences are.
#### This is the Bash script file that builds objects, shared libraries,
#### as well as the test and example binaries of the ParaMonte library in
#### POSIX-like (non-Windows) environments (such as Unix Shell, Git Bash).
#### Upon invocation of this file from a Bash command-line interface,
#### this script will parse the user-provided flags and their values
#### to build the ParaMonte library.
####
#### To redirect the output to an external file (e.g., install.sh.out), try:
####
#### install.sh >install.sh.out 2>&1
####
#### to redirect output to the external file install.sh.out and run the installation in background, try:
####
#### install.sh >install.sh.out 2>&1 &; jobs; disown
#### jobs; disown
# The following lines must appear in the specified order before anything else in the script.
#paramonte_dir="${paramonte_dir:-${PWD%/}}"
FILE_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
caller_name="$(basename "${BASH_SOURCE[0]}")"
source ./auxil/install.init.sh
#workingDir="$(pwd)"
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Reset the script arguments.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ 0 -lt 1 ]; then # just to allow toggling in notepad++.
unset bdir
export FOR_COARRAY_NUM_IMAGES=3
ddir="${paramonte_dir}/bin"
flag_ddir="-Dddir=${ddir}"
unset list_build
unset list_checking
unset list_fc
unset list_lang
unset list_lib
unset list_mem
unset list_par
unset flag_bench
unset flag_benchpp
unset flag_blas
unset flag_codecov
unset flag_cfi
unset flag_deps
unset flag_exam
unset flag_exampp
unset flag_fpp
unset flag_fresh
unset flag_j
unset flag_lapack
unset flag_matlabdir
unset flag_me
unset flag_mod
unset flag_nproc
unset flag_perfprof
unset flag_pdt
unset flag_purity
unset flag_test
unset flag_ski
unset flag_iki
unset flag_lki
unset flag_cki
unset flag_rki
while [ "$1" != "" ]; do
case "$1" in
#### list args
--build ) shift
verifyArgNotKey "$1" --build
#verifyArgNotEmpty "$1" --build
list_build="$1"
;;
--checking ) shift
verifyArgNotKey "$1" --checking
#verifyArgNotEmpty "$1" --checking
list_checking="$1"
;;
--fc ) shift
verifyArgNotKey "$1" --fc
#verifyArgNotEmpty "$1" --fc
list_fc="$1"
;;
--lang ) shift
verifyArgNotKey "$1" --lang
#verifyArgNotEmpty "$1" --lang
list_lang="$1"
;;
--lib ) shift
verifyArgNotKey "$1" --lib
#verifyArgNotEmpty "$1" --lib
list_lib="$1"
;;
--mem ) shift
verifyArgNotKey "$1" --mem
#verifyArgNotEmpty "$1" --mem
list_mem="$1"
;;
--par ) shift
verifyArgNotKey "$1" --par
#verifyArgNotEmpty "$1" --par
list_par="$1"
;;
#### flag args
--bench ) shift
verifyArgNotKey "$1" --bench
#verifyArgNotEmpty "$1" --bench
flag_bench="-Dbench=$1"
;;
--benchpp ) shift
verifyArgNotKey "$1" --benchpp
#verifyArgNotEmpty "$1" --benchpp
flag_benchpp="-Dbenchpp=$1"
;;
--blas ) shift
verifyArgNotKey "$1" --blas
#verifyArgNotEmpty "$1" --blas
flag_blas="-Dblas=$1"
;;
--codecov ) shift
verifyArgNotKey "$1" --codecov
#verifyArgNotEmpty "$1" --codecov
flag_codecov="-Dcodecov=$1"
;;
--deps ) shift
verifyArgNotKey "$1" --deps
#verifyArgNotEmpty "$1" --deps
flag_deps="-Ddeps=$1"
;;
--exam ) shift
verifyArgNotKey "$1" --exam
#verifyArgNotEmpty "$1" --exam
flag_exam="-Dexam=$1"
;;
--exampp ) shift
verifyArgNotKey "$1" --exampp
#verifyArgNotEmpty "$1" --exampp
flag_exampp="-Dexampp=$1"
;;
--cfi ) shift
verifyArgNotKey "$1" --cfi
#verifyArgNotEmpty "$1" --cfi
flag_cfi="-Dcfi=$1"
;;
--fpp ) shift
verifyArgNotKey "$1" --fpp
#verifyArgNotEmpty "$1" --fpp
flag_fpp="-Dfpp=$1"
;;
--fresh ) shift
verifyArgNotKey "$1" --fresh
#verifyArgNotEmpty "$1" --fresh
flag_fresh="-Dfresh=$1"
;;
--lapack ) shift
verifyArgNotKey "$1" --lapack
#verifyArgNotEmpty "$1" --lapack
flag_lapack="-Dlapack=$1"
;;
--matlabdir ) shift
verifyArgNotKey "$1" --matlabdir
#verifyArgNotEmpty "$1" --matlabdir
flag_matlabdir="-Dmatlabdir=\"$1\""
;;
--me ) shift
verifyArgNotKey "$1" --me
#verifyArgNotEmpty "$1" --me
flag_me="-Dme=\"$1\""
;;
--mod ) shift
verifyArgNotKey "$1" --mod
#verifyArgNotEmpty "$1" --mod
flag_mod="-Dmod=$1"
;;
--nproc ) shift
verifyArgNotKey "$1" --nproc
#verifyArgNotEmpty "$1" --nproc
isNumericValue="$(isnumeric ${nproc})"
if ! [ "${isNumericValue}" = "true" ]; then
reportBadValue "--nproc" $nproc "The spoecified number of processors must be a positive integer."
fi
FOR_COARRAY_NUM_IMAGES="$1"
flag_nproc="-Dnproc=$1"
;;
--perfprof ) shift
verifyArgNotKey "$1" --perfprof
#verifyArgNotEmpty "$1" --perfprof
flag_perfprof="-Dperfprof=$1"
;;
--pdt ) shift
verifyArgNotKey "$1" --pdt
#verifyArgNotEmpty "$1" --pdt
flag_pdt="-Dpdt=$1"
;;
--purity ) shift
verifyArgNotKey "$1" --purity
#verifyArgNotEmpty "$1" --purity
flag_purity="-Dpurity=$1"
;;
--test ) shift
verifyArgNotKey "$1" --test
#verifyArgNotEmpty "$1" --test
flag_test="-Dtest=$1"
;;
#### flag args: type kind
--ski ) shift
verifyArgNotKey "$1" --ski
#verifyArgNotEmpty "$1" --ski
flag_ski="-Dski=$1"
;;
--iki ) shift
verifyArgNotKey "$1" --iki
#verifyArgNotEmpty "$1" --iki
flag_iki="-Diki=$1"
;;
--lki ) shift
verifyArgNotKey "$1" --lki
#verifyArgNotEmpty "$1" --lki
flag_lki="-Dlki=$1"
;;
--cki ) shift
verifyArgNotKey "$1" --cki
#verifyArgNotEmpty "$1" --cki
flag_cki="-Dcki=$1"
;;
--rki ) shift
verifyArgNotKey "$1" --rki
#verifyArgNotEmpty "$1" --rki
flag_rki="-Drki=$1"
;;
#### other args
--bdir ) shift
verifyArgNotKey "$1" --bdir
#verifyArgNotEmpty "$1" --bdir
bdir="$1"
;;
--ddir ) shift
verifyArgNotKey "$1" --ddir
#verifyArgNotEmpty "$1" --ddir
ddir="$1"
flag_ddir="-Dddir=${ddir}"
;;
--help ) usage
echo >&2 ""
echo >&2 ""
exit
;;
-j ) shift
verifyArgNotKey "$1" -j
#verifyArgNotEmpty "$1" -j
flag_j="-j $1"
;;
* ) usage
echo >&2 ""
echo >&2 "-- ParaMonte - FATAL: The specified flag $1 does not exist."
echo >&2 "-- ParaMonte - FATAL: The specified flag $1 does not exist."
echo >&2 ""
echo >&2 "-- ParaMonte - gracefully exiting."
echo >&2 ""
echo >&2 ""
exit 1
esac
shift
done
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Set the default values for the input command line arguments.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ 0 -lt 1 ]; then # just to allow toggling in notepad++.
#### list args
if [ "${list_build}" = "" ]; then
list_build="release"
else
list_build="$(getLowerCase "$list_build")"
fi
if [ "${list_checking}" = "" ]; then
list_checking="nocheck"
else
list_checking="$(getLowerCase "$list_checking")"
fi
if [ "${list_fc}" = "" ]; then
# On Windows OS, particularly with MinGW, CMake fails if the specified compiler name or path does not have the
# the file extension ".exe". Given that this extension is unlikely to change in the future, and that it is not used
# on Unix systems, try suffixing the extension to the compiler file path. If it fails, use the default specified path.
compilers=("ifort" "ifx" "gfortran-13" "gfortran-12" "gfortran-11" "gfortran-10" "gfortran")
if [ "${os}" = "mingw" ] || [ "${os}" = "msys" ] || [ "${os}" = "cygwin" ]; then
extensions=(".exe" "")
else
extensions=("")
fi
for compiler in "${compilers[@]}"; do
for extension in "${extensions[@]}"; do
echo >&2 "${pmnote} Checking existence of compiler \"${compiler}\" executable with extension \"${extension}\""
# check if the specified compiler can be found in the environment.
if command -v "${compiler}${extension}" >/dev/null 2>&1; then
list_fc="$(command -v "${compiler}${extension}")"
break 2
fi
done
done
if [ "${list_fc}" = "" ]; then
echo >&2 "${pmwarn} Failed to detect any compatible Fortran compiler in the environment."
echo >&2 "${pmwarn} You can manually specify the Fortran compiler or its path via the install script flag \"--fc\"."
echo >&2 "${pmwarn} The build will proceed with no guarantee of success."
list_fc="default"
else
echo >&2 "${pmnote} The identified Fortran compiler path is: fc=\"${list_fc}\""
fi
fi
if [ "${list_lang}" = "" ]; then
list_lang="fortran"
else
list_lang="$(getLowerCase "$list_lang")"
list_lang="${list_lang/c++/cpp}"
fi
if [ "${list_lib}" = "" ]; then
list_lib="shared"
else
# Replace `dynamic` with `shared`.
list_lib=${list_lib/dynamic/shared}
list_lib="$(getLowerCase "$list_lib")"
fi
if [ "${list_mem}" = "" ]; then
list_mem="heap"
else
list_mem="$(getLowerCase "$list_mem")"
fi
if [ "${list_par}" = "" ]; then
list_par="serial"
else
# Replace `none` with `serial`.
list_par=${list_par/none/serial}
list_par="$(getLowerCase "$list_par")"
fi
if [ "${flag_j}" = "" ]; then
flag_j="-j"
fi
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Set CMake default flags.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ 0 -lt 1 ]; then # just to allow toggling in notepad++.
if [[ "${flag_fresh}" =~ .*"prereq".* || "${flag_fresh}" =~ .*"all".* ]]; then
if [ -d "${paramonte_req_dir}" ]; then
echo >&2 "${pmnote} Removing the old prerequisites of the ParaMonte library build at: paramonte_req_dir=\"${paramonte_req_dir}\""
rm -rf "${paramonte_req_dir}"
fi
fi
# Set the CMake build generator.
flag_g="-G"
unset cmakeBuildGenerator
if [ "${os}" = "mingw" ]; then
cmakeBuildGenerator="MinGW Makefiles"
elif [ "${os}" = "msys" ]; then
cmakeBuildGenerator="MSYS Makefiles"
else
cmakeBuildGenerator="Unix Makefiles"
fi
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Configure and build the ParaMonte library.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for fc in ${list_fc//;/$'\n'}; do # replace `;` with newline character.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Set up the CMake fc flag.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
unset flag_fc
if [ -f "${fc}" ]; then
fcpath="${fc}"
flag_fc="-Dfc=${fcpath}"
elif ! [[ "${fc}" =~ [Dd][Ee][Ff][Aa][Uu][Ll][Tt] ]]; then
fcpath="$(getPathFC "${fc}")"
if [ -f "${fcpath}" ]; then
flag_fc="-Dfc=${fcpath}"
else
echo >&2 "${pmfatal} Failed to detect the full path for the specified compiler: fcpath=\"${fcpath}\""
reportBadValue "--fc" "${fc}"
fi
echo >&2 "${pmnote} Fortran compiler path: fcpath=\"${fcpath}\""
fi
# Get the compiler ID and version to be used in the build path.
csid=$(getCSID "${fcpath}")
csvs=$(getCSVS "${fcpath}" "${csid}")
echo >&2 "${pmnote} compiler suite: ${csid}"
echo >&2 "${pmnote} compiler version: ${csvs}"
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Build the ParaMonte library with the specified compiler.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for lang in ${list_lang//;/$'\n'}; do # replace `;` with newline character.
flag_lang="-Dlang=${lang}"
#lang_is_dynamic="false"
#if [ "${lang}" = "julia" ] || [ "${lang}" = "matlab" ] || [ "${lang}" = "mathematica" ] || [ "${lang}" = "python" ] || [ "${lang}" = "r" ]; then
# lang_is_dynamic="true"
#fi
## Set source preprocessing output on by default for Fortran.
#if [ "${lang}" = "fortran" ] && [ "${flag_fpp}" = "" ]; then
# flag_fpp="-Dfpp=generic"
#fi
for build in ${list_build//;/$'\n'}; do # replace `;` with newline character.
flag_build="-Dbuild=${build}"
for lib in ${list_lib//;/$'\n'}; do # replace `;` with newline character.
flag_lib="-Dlib=${lib}"
for mem in ${list_mem//;/$'\n'}; do # replace `;` with newline character.
flag_mem="-Dmem=${mem}"
for par in ${list_par//;/$'\n'}; do # replace `;` with newline character.
flag_par="-Dpar=${par}"
for checking in ${list_checking//;/$'\n'}; do # replace `;` with newline character.
flag_checking="-Dchecking=${checking}"
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Set the ParaMonte CMake build directory.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ 0 -lt 1 ]; then # just to allow toggling in notepad++.
# First, determine the MPI library name to be used in the ParaMonte library name and build directory.
if [ "${par}" = "mpi" ]; then
#if [ -z ${me+x} ]; then
if [ "${me}" = "" ]; then
me=mpiexec
fi
if ! [[ -f "${me}" ]]; then
me="$(command -v ${me})"
if ! [[ -f "${me}" ]]; then
echo >&2 "${pmwarn} The specified mpiexec path does not appear to be a valid path to an mpiexec executable: me=\"${me}\""
fi
fi
parname=mpi
mpiVersionInfo="$(${me} --version)"
if [[ "${mpiVersionInfo}" =~ .*"Intel".* ]]; then
parname="impi"
elif [[ "${mpiVersionInfo}" =~ .*[oO][pP][eE][nN][rR][tT][eE].* ]] || [[ "${mpiVersionInfo}" =~ .*[oO][pP][eE][nN]-?[mM][pP][iI].* ]]; then
parname="openmpi"
elif [[ "${mpiVersionInfo}" =~ .*[mM][pP][iI][cC][hH].* ]]; then
parname="mpich"
else # look for mpichversion
mpichversion_path="$(dirname ${me})"/mpichversion
if [ -f "${mpichversion_path}" ] && [[ "$(mpichversion_path)" =~ .*[mM][pP][iI][cC][hH].* ]]; then
parname="mpich"
fi
fi
if [ "${parname}" = "mpi" ]; then
echo >&2 "${pmwarn} The MPI library vendor could not be identified."
echo >&2 "${pmwarn} The MPI library behavior does not match the Intel, MPICH, or OpenMPI libraries."
echo >&2 "${pmwarn} The ParaMonte library name will be suffixed with the generic \"${parname}\" label."
fi
elif [ "${par}" = "omp" ]; then
parname="openmp"
else
parname="${par}"
fi
#if [ -z ${bdir+x} ]; then
if [ "${bdir}" = "" ]; then
paramonte_bld_dir="${paramonte_dir}/bld/${os}/${arch}/${csid}/${csvs}/${build}/${lib}/${mem}/${parname}/${checking}/${lang}"
if [[ "${flag_perfprof}" =~ .*"all".* ]]; then
paramonte_bld_dir="${paramonte_bld_dir}/perfprof"
fi
if [[ "${flag_codecov}" =~ .*"all".* ]]; then
paramonte_bld_dir="${paramonte_bld_dir}/codecov"
fi
echo >&2 "${pmnote} The ParaMonte library build directory: paramonte_bld_dir=\"${paramonte_bld_dir}\""
else
echo >&2 "${pmnote} User-specified library build directory detected: bdir=\"${bdir}\""
paramonte_bld_dir="${bdir}"
fi
# Make the build directory if needed.
if ! [ -d "${paramonte_bld_dir}" ]; then
echo >&2 "${pmnote} Generating the ParaMonte build directory..."
mkdir -p "${paramonte_bld_dir}/"
fi
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Configure and build the library via CMake.
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ 0 -lt 1 ]; then # just to allow toggling in notepad++.
echo >&2 "${pmnote} All generated build files will be stored at: ${paramonte_bld_dir}"
echo >&2 "${pmnote} Changing directory to: ${paramonte_bld_dir}"
echo >&2 ""
echo >&2 "########################################################################################%%"
echo >&2 ""
echo >&2 "${pmnote} Invoking CMake as:"
echo >&2 ""
set -x
(cd "${paramonte_bld_dir}" && \
cmake \
"${paramonte_dir}" \
${flag_g} "${cmakeBuildGenerator}" \
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" \
"${flag_ddir}" \
"${flag_build}" \
"${flag_checking}" \
"${flag_lang}" \
"${flag_lib}" \
"${flag_mem}" \
"${flag_par}" \
${flag_fc} \
${flag_bench} \
${flag_benchpp} \
${flag_blas} \
${flag_codecov} \
${flag_cfi} \
${flag_deps} \
${flag_exam} \
${flag_exampp} \
${flag_fpp} \
${flag_fresh} \
${flag_lapack} \
${flag_matlabdir} \
${flag_me} \
${flag_mod} \
${flag_nproc} \
${flag_perfprof} \
${flag_pdt} \
${flag_purity} \
${flag_test} \
${flag_ski} \
${flag_iki} \
${flag_lki} \
${flag_cki} \
${flag_rki} \
)
verify $? "configuration with cmake"
echo >&2 ""
echo >&2 "########################################################################################%%"
echo >&2 ""
#(cd "${paramonte_bld_dir}" && $makename ${flag_j})
(cd "${paramonte_bld_dir}" && cmake --build "${paramonte_bld_dir}" ${flag_j})
verify $? "build with make"
#(cd "${paramonte_bld_dir}" && $makename install)
(cd "${paramonte_bld_dir}" && cmake --build "${paramonte_bld_dir}" --target install ${flag_j})
verify $? "installation"
#(cd "${paramonte_bld_dir}" && $makename deploy)
(cd "${paramonte_bld_dir}" && cmake --build "${paramonte_bld_dir}" --target deploy ${flag_j})
verify $? "deployment"
#(cd "${paramonte_bld_dir}" && $makename test && echo)
(cd "${paramonte_bld_dir}" && cmake --build "${paramonte_bld_dir}" --target test)
verify $? "testing"
#(cd "${paramonte_bld_dir}" && $makename example)
(cd "${paramonte_bld_dir}" && cmake --build "${paramonte_bld_dir}" --target example)
verify $? "examples build and run"
#(cd "${paramonte_bld_dir}" && $makename benchmark)
(cd "${paramonte_bld_dir}" && cmake --build "${paramonte_bld_dir}" --target benchmark)
verify $? "benchmarks build and run"
fi
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#### CODECOVE: Generate *.gcda *.gcno codecov files for the Fortran test source files
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [[ "${flag_codecov}" =~ .*"all".* ]]; then
# \todo
# \warning
# This version extraction relies on "version " appearing before the lcov version number.
# This must be adjusted to any potential future changes in the LCOV version string.
if command -v lcov >/dev/null 2>&1; then
lcovVersion=$(lcov -v | grep -Po '(?<=version )[^;]+')
else
unset lcovVersion
fi
unset htmlSubDir
if [ "${par}" = "mpi" ]; then
parallelismText="MPI Parallel"
htmlSubDir="mpi"
elif [[ "${par}" =~ .*"caf".* ]]; then
parallelismText="Coarray Parallel"
htmlSubDir="caf"
else
parallelismText="Serial"
htmlSubDir="serial"
fi
htmlDir="${paramonte_external_doc_out_dir}/codecov/fortran/${paramonte_version_major_fortran}/${htmlSubDir}"
htmlTitleCodeCov="ParaMonte ${paramonte_version_fortran} :: ${parallelismText} Fortran - Code Coverage Report"
if [[ ${csid} == [gG][nN][uU] ]] && command -v gcov >/dev/null 2>&1 && command -v lcov >/dev/null 2>&1; then
# gcov should be run with the current directory the same as that when you invoked the compiler.
# Otherwise it will not be able to locate the source files.
# gcov produces files called mangledname.gcov in the current directory.
# These contain the coverage information of the source file they correspond to.
# One .gcov file is produced for each source (or header) file containing code, which was compiled to produce the data files.
# The mangledname part of the output file name is usually simply the source file name, but can be something more complicated
# if the `-l` or `-p` options are given. Refer to those options for details.
#
# -o directory|file
# --object-directory directory
# --object-file file
#
# Specify either the directory containing the gcov data files, or the object path name.
# The .gcno, and .gcda data files are searched for using this option.
# If a directory is specified, the data files are in that directory and named after the input file name, without its extension.
# If a file is specified here, the data files are named after that file, without its extension.
gcovPath="$(command -v gcov)"
echo >&2 "${pmnote} GNU gcov detected at: ${gcovPath}"
echo >&2 "${pmnote} Invoking gcov to generate coverage report..."
paramonte_bld_lcov_dir="${paramonte_bld_dir}"/lcov
rm -rf "${paramonte_bld_lcov_dir}"
mkdir -p "${paramonte_bld_lcov_dir}"
lcovCombinedTraceFileName="all.tracefile.info"
lcovCombinedTraceFilePath="${paramonte_bld_lcov_dir}/${lcovCombinedTraceFileName}"
#unset branchCoverageFlag
# Add the following flag to lcov to enable branch coverage:
# branchCoverageFlag="--rc lcov_branch_coverage=1"
# "${branchCoverageFlag}"
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#### GCOV main source: Generate *.gcda *.gcno codecov files for the Fortran main source files
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ 0 -lt 1 ]; then # just to allow toggling in notepad++. Disable conditional to prevent example coverage report.
colections=("main" "test")
for collection in ${colections[@]}; do
if [ "${collection}" = "main" ]; then
# pm_blas is a unique file name. That is why we choose and use it.
sobjFileDir=$(find "${paramonte_bld_dir}/obj" -name pm_blas*.o)
gcovFileDir=$(find "${paramonte_bld_dir}/obj" -name pm_blas*.gcno)
elif [ "${collection}" = "test" ]; then
# main is a unique file name. That is why we choose and use it.
sobjFileDir=$(find "${paramonte_bld_dir}/test/obj" -name main*.o)
gcovFileDir=$(find "${paramonte_bld_dir}/test/obj" -name main*.gcno)
else
echo >&2 "${pmfatal} Unrecognized coverage report collection."
echo >&2 "${pmfatal} This is an internal ParaMonte build script error."
echo >&2 "${pmfatal} Please report this problem to the ParaMonte library developers on GitHub issues."
exit 1
fi
sobjFileDir=$(dirname "${sobjFileDir}")
gcovFileDir=$(dirname "${gcovFileDir}")
echo >&2 "${pmnote} sobjFileDir=${sobjFileDir}"
echo >&2 "${pmnote} gcovFileDir=${gcovFileDir}"
if [ -d "${sobjFileDir}" ] && [ -d "${gcovFileDir}" ]; then
cd "${gcovFileDir}"
for objFilePath in "${sobjFileDir}"/*.o; do
srcFileName="${objFilePath##*/}" # extract the basename.
srcFileName="${srcFileName%.o}" # extract the filename (without extension).
srcFilePath="${paramonte_src_fortran_main_dir}/${srcFileName}"
echo >&2 "${pmnote} running gcov ${srcFilePath} -o ${gcovFileDir}/${srcFileName}"
gcov "${srcFilePath}" -o "${gcovFileDir}/${srcFileName}.null" || {
echo >&2 "${pmwarn} The ParaMonte Code Coverage analysis of the ${collection} object files via GNU gcov tool failed."
echo >&2 "${pmwarn} The ParaMonte ${collection} source file: ${srcFilePath}"
echo >&2 "${pmwarn} The ParaMonte ${collection} object file: ${objFilePath}"
}
done
cd "${paramonte_bld_lcov_dir}"
lcovCurrentTraceFilePath="${paramonte_bld_lcov_dir}/lcov.${collection}.tracefile.info"
echo >&2 "${pmnote} Invoking LCOV report file for the ParaMonte Fortran ${collection} files: ${lcovCurrentTraceFilePath}"
lcov --capture --directory "${gcovFileDir}" --output-file "${lcovCurrentTraceFilePath}" && {
if [ -f "${lcovCombinedTraceFilePath}" ]; then
echo >&2 "${pmnote} Merging lcov report file with the main report file: ${lcovCombinedTraceFilePath}"
mv "${lcovCombinedTraceFilePath}" "${lcovCombinedTraceFilePath}".temp
lcov --add-tracefile "${lcovCombinedTraceFilePath}".temp -a "${lcovCurrentTraceFilePath}" -o "${lcovCombinedTraceFilePath}"
else
cp -arf "${lcovCurrentTraceFilePath}" "${lcovCombinedTraceFilePath}"
fi
} || {
echo >&2 "${pmwarn} Code Coverage report generation for the ParaMonte ${collection} source files via lcov tool failed."
#exit 1
}
else
echo >&2 "${pmwarn} Failed to detect the *.o, *.gcda, and *.gcno data files for the ParaMonte ${collection} source files."
echo >&2 "${pmwarn} The expected directory path for the object files: ${sobjFileDir}"
echo >&2 "${pmwarn} The expected directory path for the GCOV files: ${gcovFileDir}"
echo >&2 "${pmwarn} The coverage report for the ParaMonte ${collection} source file will not be included."
echo >&2 "${pmwarn} Skipping the GCOV code coverage report generation for the ${collection} files..."
fi
done
fi
####
#### Add the ParaMonte example gcov report files.
####
if [ 1 -lt 0 ]; then # just to allow toggling in notepad++. Disable conditional to prevent example coverage report.
collection="example"
for modpath in "${paramonte_bld_dir}"/pkg/example/pm_arrayCenter*/; do
for exppath in "${modpath}"/*/; do
modname=$(basename "${modpath}")
expname=$(basename "${exppath}")
#### First attempt to infer the cmake object files' directory.
sobjFileDir=$(find "${exppath}" -name main*.o)
sobjFileDir=$(dirname "${sobjFileDir}")
gcovFileDir=$(find "${exppath}" -name main*.gcno)
gcovFileDir=$(dirname "${gcovFileDir}")
if [ -d "${sobjFileDir}" ] && [ -d "${gcovFileDir}" ]; then
cd "${gcovFileDir}"
for objFilePath in "${sobjFileDir}"/*.o; do
srcFilePath="${paramonte_example_dir}/${lang}/${modname}/${expname}/main.F90"
echo >&2 "${pmnote} running gcov ${srcFilePath} --relative-only --source-prefix ${paramonte_bld_dir}/pkg/ -o ${gcovFileDir}/main.F90"
gcov "${srcFilePath}" --relative-only --source-prefix "${paramonte_bld_dir}/pkg/" -o "${gcovFileDir}/main.F90.null" || {
echo >&2 "${pmwarn} The ParaMonte Code Coverage analysis of the test object files via GNU gcov tool failed."
echo >&2 "${pmwarn} The ParaMonte test source file: ${srcFilePath}"
echo >&2 "${pmwarn} The ParaMonte test object file: ${objFilePath}"
}
done
cd "${paramonte_bld_lcov_dir}"
lcovCurrentTraceFilePath="${paramonte_bld_lcov_dir}/lcov.${collection}.${modname}.${expname}.tracefile.info"
echo >&2 "${pmnote} Invoking LCOV report file for the ParaMonte Fortran ${collection} files: ${lcovCurrentTraceFilePath}"
lcov --capture --directory "${gcovFileDir}" --output-file "${lcovCurrentTraceFilePath}" && {
if [ -f "${lcovCombinedTraceFilePath}" ]; then
echo >&2 "${pmnote} Merging lcov report file with the main report file: ${lcovCombinedTraceFilePath}"
mv "${lcovCombinedTraceFilePath}" "${lcovCombinedTraceFilePath}".temp
lcov --add-tracefile "${lcovCombinedTraceFilePath}".temp -a "${lcovCurrentTraceFilePath}" -o "${lcovCombinedTraceFilePath}"
else
cp -arf "${lcovCurrentTraceFilePath}" "${lcovCombinedTraceFilePath}"
fi
} || {
echo >&2 "${pmwarn} Code Coverage report generation failed for the ParaMonte ${collection}${modname}.${expname} source file: ${exppath}"
#exit 1
}
else
echo >&2 "${pmwarn} Failed to detect the *.o, *.gcda, and *.gcno data files for the ParaMonte test source files."
echo >&2 "${pmwarn} The expected directory path for the object files: ${sobjFileDir}"
echo >&2 "${pmwarn} The expected directory path for the GCOV files: ${gcovFileDir}"
echo >&2 "${pmwarn} The coverage report for the ParaMonte test source file will not be included."
echo >&2 "${pmwarn} Skipping the GCOV code coverage report generation for the test files..."
fi
done
done
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# HTML: convert the lcov summary file to the final html report files
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if command -v genhtml >/dev/null 2>&1; then
if [ -d "${htmlDir}" ]; then
rm -rf "${htmlDir}"
else
mkdir -p "${htmlDir}"
fi
#if ! [ -f "${lcovCombinedTraceFilePath}" ]; then
# cp "${lcovOutputFortranFilePath}" "${lcovCombinedTraceFilePath}" || {
# echo >&2 "${pmwarn} Copy action failed:"
# echo >&2 "${pmwarn} from: ${lcovOutputFortranFilePath}"
# echo >&2 "${pmwarn} to: ${lcovCombinedTraceFilePath}"
# }
#fi
genhtml "${lcovCombinedTraceFilePath}" --output-directory "${htmlDir}" --legend --title "${htmlTitleCodeCov}" && {
echo >&2 "${pmnote} The code coverage build files are stored at: ${paramonte_bld_dir}"
echo >&2 "${pmnote} The code coverage report files are stored at: ${htmlDir}"
# postprocess the html files.
# The variable `original` contains what LCOV software generates.
# The variable `modified` contains what what we intend to replace the LCOV header with.
original="<tr><td class=\"title\">LCOV - code coverage report<\/td><\/tr>"
modified="<tr><td class=\"title\">"
modified+="<a href=\"https:\/\/www.cdslab.org\/paramonte\/fortran\/${paramonte_version_major_fortran}\" target=\"_blank\">"
modified+="<img alt=\"https:\/\/www.cdslab.org\/paramonte\/fortran\/${paramonte_version_major_fortran}\" src=\"https:\/\/raw.githubusercontent.com\/cdslaborg\/paramonte\/16e8fc2abd6a4263c9f6ee25f7a9f45435443688\/img\/banner.png\"\/>"
modified+="<\/a>"
modified+="<\/td><\/tr>"
footer="<tr><td class=\"versionInfo\">"
footer+="<a href=\"https:\/\/www.cdslab.org\/paramonte\"><b>ParaMonte: Parallel Monte Carlo and Machine Learning Library<\/b><\/a> <br>"
footer+="<a href=\"https:\/\/www.cdslab.org\" target=\"_blank\"><b>The Computational Data Science Lab<\/b><\/a><br>"
footer+="© Copyright 2012 - $(date +%Y)"
footer+="<\/td><\/tr>"
shopt -s globstar
for htmlFilePath in "${htmlDir}"/**/*.html; do # Whitespace-safe and recursive
#sed -i "s/${paramonte_bld_dir//\//\\/}\/pkg\///g" "${htmlFilePath}"
sed -i "s/${original}/${modified}/g" "${htmlFilePath}"
sed -i "/<tr><td class=\"versionInfo\">/c\\${footer}" "${htmlFilePath}"
done
#scfile="${paramonte_dir}/auxil/sc.html"
#if [ -f "${scfile}" ]; then
# echo >&2
# echo >&2 "${pmnote} processing the sc file contents..."
# echo >&2
# sccontents=`cat "${paramonte_dir}/auxil/sc.html"`
# sed -e '/<\/body>/r${scfile}' "${htmlFilePath}"
#else
# echo >&2
# echo >&2 "${pmnote} ${warning} ${paramonte_dir}/auxil/sc.html is missing in your clone."
# echo >&2 "${pmnote} ${warning} This is not critical, unless you are a ParaMonte developer and"
# echo >&2 "${pmnote} ${warning} aim to publicly release this code coverage report. To obtain a "
# echo >&2 "${pmnote} ${warning} copy of the file, contact the ParaMonte lead developer at"
# echo >&2 "${pmnote} ${warning} "
# echo >&2 "${pmnote} ${warning} [email protected]"
# echo >&2
#fi
} || {
echo >&2 "${pmwarn} Code Coverage report generation via genhtml failed."
}
# "${branchCoverageFlag}" \
#--title "<a href=\"https://github.com/cdslaborg/paramonte\" target=\"_blank\">ParaMonte Fortran</a> code coverage report" \
## generate test files code coverage
#
#sobjFortranTestDir=$(find "${paramonte_bld_obj_dir}" -name test_pm_*.o)
#sobjFortranTestDir=$(dirname "${sobjFortranTestDir}")
#
#lcovFortranTestDir="${paramonte_bld_dir}"/test/lcov
#mkdir -p "${lcovFortranTestDir}"
#cd "${lcovFortranTestDir}"
#
#lcov --capture --directory "${sobjFortranTestDir}" --output-file ./paramonte.coverage.info
#
#genhtml paramonte.coverage.info --output-directory "${lcovFortranTestDir}/html"
else
echo >&2 "${pmwarn} Failed to find the GENHTML test coverage summarizer."
echo >&2 "${pmwarn} The genhtml program is required to generate the coverage report."
echo >&2 "${pmwarn} If you believe genhtml is already installed on your system,"
echo >&2 "${pmwarn} please make sure the path its directory is added to the"
echo >&2 "${pmwarn} PATH environmental variable of your terminal."
echo >&2 "${pmwarn} Once added, rerun the ParaMonte code coverage."
fi
cd "${paramonte_dir}"
else
echo >&2 "${pmfatal} Note: Code coverage with compilers other than GNU gfortran is currently unsupported."
echo >&2 "${pmfatal} Fatal Error: Failed to find the GNU compilers, GNU GCOV and/or LCOV coverage software."
echo >&2 "${pmfatal} The GCOV and LCOV software are required to generate the coverage report."
echo >&2 "${pmfatal} If you believe GCOV/LCOV are already installed on your system,"
echo >&2 "${pmfatal} please make sure the path to their binary directories are"
echo >&2 "${pmfatal} added to the PATH environmental variable of your terminal."
echo >&2 "${pmfatal} Once added, rerun the ParaMonte code coverage."
echo >&2 "${pmfatal} "
echo >&2 "${pmfatal} Gracefully exiting The ParaMonte build script."
exit 1
fi
fi # codecov
done
done
done
done
done