forked from amanzi/amanzi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·1267 lines (1003 loc) · 32.7 KB
/
bootstrap.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
# ############################################################################ #
# #
# Amanzi Boost Script #
# #
# Script that builds Amanzi from scratch #
# #
# ############################################################################ #
# ---------------------------------------------------------------------------- #
# Initialize
# ---------------------------------------------------------------------------- #
# Logic parameters
TRUE=1
FALSE=0
# System information
system_name=`uname`
system_arch=`uname -m`
# Test script controls
print_exit=${FALSE}
# Known compiler lists
known_c_compilers="mpicc cc gcc icc"
known_cxx_compilers="mpicxx mpiCC CC g++ icpc"
known_fortran_compilers="mpif90 ftn gfortran ifort"
# Directory information
start_directory=$PWD
amanzi_source_dir=$(cd $(dirname "$0")/;pwd)
# ASCEM Web address
ascem_protocol=https
ascem_site='software.lanl.gov/ascem'
ascem_tpl_site="${ascem_site}/tpls"
# Default root build and install prefix
dflt_build_prefix=`pwd`
dflt_install_prefix=`pwd`
# Source and build directories
amanzi_build_dir="${dflt_build_prefix}/build/amanzi"
amanzi_install_prefix="${dflt_install_prefix}/install/amanzi"
# Mercurial
hg_binary=`which hg`
# CURL
curl_binary=`which curl`
# CMake
cmake_binary=`which cmake`
ctest_binary=`which ctest`
cmake_version=2.8.8
cmake_url=http://www.cmake.org/files/v2.8
cmake_archive_file=cmake-${cmake_version}.tar.gz
# Build configuration
parallel_jobs=2
build_type=Release
# Compiler definitions
build_c_compiler=
build_cxx_compiler=
build_fort_compiler=
# Compiler flags
build_c_flags=
build_cxx_flags=
build_fort_flags=
build_link_flags=
# MPI installation
mpi_root_dir=
# TPL (Third Party Libraries)
# Point to a configuration file
tpl_config_file=
# TPL build parameters
tpl_build_dir=${dflt_build_prefix}/build/tpls
tpl_download_dir=${tpl_build_dir}/Downloads
tpl_install_prefix=${dflt_install_prefix}/install/tpls
# Color output display
no_color=$FALSE
# Amanzi build configuration
structured=$TRUE
unstructured=$TRUE
ccse_tools=$FALSE
stk_mesh=$TRUE
mstk_mesh=$TRUE
moab_mesh=$FALSE
amanzi_branch=
test_suite=$FALSE
reg_tests=$FALSE
netcdf4=${TRUE}
petsc=${TRUE}
hypre=${TRUE}
alquimia=${FALSE}
pflotran=${FALSE}
shared=${FALSE}
spacedim=2
native=${FALSE}
nersc=${FALSE}
nersc_tpl_opts=
nersc_amanzi_opts=
#silo=${TRUE}
# ---------------------------------------------------------------------------- #
#
# Begin Functions
# Basic messages and exiting functions
function exit_now()
{
exit $1
}
function status_message()
{
local GREEN='32m'
if [ "${no_color}" -eq "${TRUE}" ]; then
echo "[`date`] $1"
else
echo -e "[`date`]\033[$GREEN $1\033[m"
fi
}
function error_message()
{
local RED='31m'
if [ "${no_color}" -eq "${TRUE}" ]; then
echo "Amanzi Bootstrap ERROR: $1" 1>&2
else
echo -e "Amanzi Bootstrap ERROR:\033[$RED $1\033[m" 1>&2
fi
}
function warn_message()
{
local PINK='35m'
if [ "${no_color}" -eq "${TRUE}" ]; then
echo "Amanzi Bootstrap Warning: $1" 1>&2
else
echo -e "Amanzi Bootstrap Warning:\033[$PINK $1\033[m" 1>&2
fi
}
function fatal_message()
{
error_message $1
exit_now 10
}
# Utilities
function make_fullpath()
{
if echo $1 | grep "^\/" > /dev/null 2> /dev/null; then
echo $1
else
echo "$start_directory/$1"
fi
}
function mkdir_now()
{
echo "making $1"
if [ ! -e $1 ]; then
mkdir -p $1
fi
}
function download_file()
{
url=$1
file=$2
output=$3
curl_opts=
if [ ! -z "${output}" ]; then
if [ -d "${output}" ]; then
curl_opts="--output $output/$file"
else
curl_opts="--output $output"
fi
else
curl_opts="--remote-name"
fi
cmd="${curl_binary} ${curl_opts} $url/$file"
echo $cmd
${curl_binary} $curl_opts $url/$file
status=$?
if [ "${status}" -ne "0" ]; then
error_message "${curl_binary} returned $status"
error_message "Failed to download $file from $url"
exit_now $status
fi
}
# Command line functions
function set_feature()
{
feature=$1
action=$2
if echo $action | grep "disable" > /dev/null 2>/dev/null; then
eval "${feature}=$FALSE"
fi
if echo $action | grep "enable" > /dev/null 2>/dev/null; then
eval "${feature}=$TRUE"
fi
echo ${!feature}
}
function parse_feature()
{
feature_opt=$1
if echo ${feature_opt} | grep "^--disable-" > /dev/null 2> /dev/null; then
echo ${feature_opt} | sed "s/^--disable-//"
fi
if echo ${feature_opt} | grep "^--enable-" > /dev/null 2> /dev/null; then
echo ${feature_opt} | sed "s/^--enable-//"
fi
}
function parse_option_with_equal()
{
a=$1
opt_name=$2
if echo $a | grep "^--${opt_name}=" > /dev/null 2> /dev/null; then
echo $a | sed "s/^--${opt_name}=//"
fi
}
function print_usage()
{
echo '
Usage: '"$0"' [options]
Options: [defaults in brackets after descriptions]
Configuration:
--help print this message
--parallel=n build in parallel, where n is
number of maximum make jobs ['"${parallel_jobs}"']
--no-color deactivate color-coded status output ['"${no_color}"']
--tpl-config-file=FILE define a CMake TPL configuration file. If this
option is selected, '"$0"' will NOT build the TPLs.
--opt build optimized TPLs and Amanzi binaries. This the default
configuration.
--debug build debug TPLs and Amanzi binaries.
--branch=BRANCH build TPLs and Amanzi found in BRANCH ['"${amanzi_branch}"']
--spacedim=DIM dimension of structured build (DIM=2 or 3) ['"${spacedim}"']
--nersc_build use cmake options required on NERSC machines ['"${nersc}"']
Build features:
Each feature listed here can be enabled/disabled with --[enable|disable]-[feature]
Value in brackets indicates default setting.
structured build structured AMR mesh capability ['"${structured}"']
ccse_tools build structured AMR tools for post processing and tecplot ['"${ccse_tools}"']
unstructured build unstructured mesh capability ['"${unstructured}"']
stk_mesh build the STK Mesh Toolkit ['"${stk_mesh}"']
mstk_mesh build the MSTK Mesh Toolkit ['"${mstk_mesh}"']
moab_mesh build the MOAB Mesh Toolkit ['"${moab_mesh}"']
hypre build the HYPRE solver APIs ['"${hypre}"']
petsc build the PETSc solver APIs ['"${petsc}"']
pflotran build the PFlotran geochemistry backend ['"${pflotran}"']
alquimia build the Alquimia geochemistry solver APIs ['"${alquimia}"']
test_suite run Amanzi Test Suite before installing ['"${test_suite}"']
reg_tests build regression tests into Amanzi Test Suite ['"${reg_tests}"']
shared build Amanzi and tpls using shared libraries ['"${shared}"']
native build Amanzi with native xml output for debugging enabled ['"${native}"']
Tool definitions:
--with-c-compiler=FILE FILE is the C compiler
--with-cxx-compiler=FILE FILE is the C++ compiler
--with-fort-compiler=FILE FILE is the Fortran compiler
--with-c-flags=STRING STRING is additional C compiler flags
--with-cxx-flags=STRING STRING is additional C++ compiler flags
--with-fort-flags=STRING STRING is additional Fortran compiler flags
--with-link-flags=STRING STRING is additional linker flags
--with-cmake[=FILE] FILE is the CMake binary ['"${cmake_binary}"'] without FILE builds CMake
--with-ctest=FILE FILE is the CTest binary ['"${ctest_binary}"'], ignored if --with-cmake is set
--with-hg=FILE FILE is the Mercurial binary ['"${hg_binary}"']
--with-curl=FILE FILE is the CURL binary ['"${curl_binary}"']
--with-mpi=DIR use MPI installed in DIR. Will search for MPI
compiler wrappers under this directory. ['"${mpi_root_dir}"']
Directory and file names:
--prefix=PREFIX install ALL files in tree rooted at PREFIX
['"${dflt_install_prefix}"']
--amanzi-install-prefix=DIR install Amanzi in tree rooted at DIR
['"${amanzi_install_prefix}"']
--amanzi-build-dir=DIR build Amanzi in DIR
['"${amanzi_build_dir}"']
--tpl-install-prefix=DIR install Amanzi TPLs in tree rooted at DIR
['"${tpl_install_prefix}"']
--tpl-build-dir=DIR build Amanzi TPLs in DIR
['"${tpl_build_dir}"']
--tpl-download-dir=DIR direct downloads of Amanzi TPLs to DIR
['"${tpl_download_dir}"']
'
}
function print_variable_values
{
echo '
Tools:
cmake_binary ='"${cmake_binary}"'
ctest_binary ='"${ctest_binary}"'
hg_binary ='"${hg_binary}"'
curl_binary ='"${curl_binary}"'
mpi_root_dir ='"${mpi_root_dir}"'
Compilers:
build_c_compiler ='"${build_c_compiler}"'
build_cxx_compiler ='"${build_cxx_compiler}"'
build_fort_compiler ='"${build_fort_compiler}"'
Compile Flags
build_c_flags ='"${build_c_flags}"'
build_cxx_flags ='"${build_cxx_flags}"'
build_fort_flags ='"${build_fort_flags}"'
Link Flags
build_link_flags ='"${build_link_flags}"'
Build configuration:
build_type ='"${build_type}"'
tpl_config_file ='"${tpl_config_file}"'
parallel ='"${parallel_jobs}"'
shared ='"${shared}"'
spacedim ='"${spacedim}"'
nersc_build ='"${nersc}"'
Build Features:
structured ='"${structured}"'
unstructured ='"${unstructured}"'
ccse_tools ='"${ccse_tools}"'
stk_mesh ='"${stk_mesh}"'
mstk_mesh ='"${mstk_mesh}"'
moab_mesh ='"${moab_mesh}"'
test_suite ='"${test_suite}"'
reg_tests ='"${reg_tests}"'
netcdf4 ='"${netcdf4}"'
hypre ='"${hypre}"'
petsc ='"${petsc}"'
alquimia ='"${alquimia}"'
pflotran ='"${pflotran}"'
native ='"${native}"'
Directories:
prefix ='"${prefix}"'
amanzi_install_prefix ='"${amanzi_install_prefix}"'
amanzi_build_dir ='"${amanzi_build_dir}"'
tpl_install_prefix ='"${tpl_install_prefix}"'
tpl_build_dir ='"${tpl_build_dir}"'
tpl_download_dir ='"${tpl_download_dir}"'
'
}
function parse_argv()
{
argv=( "$@" )
echo "${argv[1]}"
last=$(( ${#argv[@]} - 1 ))
i=0
while [ $i -le ${last} ]
do
opt=${argv[$i]}
echo "i: ${i} opt=$opt last: $last"
case ${opt} in
-h|--h|--help)
print_usage
exit_now 0
;;
--prefix=*)
tmp=`parse_option_with_equal "${opt}" 'prefix'`
prefix=`make_fullpath ${tmp}`
;;
--parallel=[0-9]*)
parallel_jobs=`parse_option_with_equal "${opt}" 'parallel'`
;;
--opt)
build_type=Release
enable_native=${FALSE}
;;
--debug)
build_type=Debug
enable_native=${TRUE}
;;
--disable-*)
feature=`parse_feature "${opt}"`
set_feature ${feature} 'disable'
;;
--enable-*)
feature=`parse_feature "${opt}"`
set_feature ${feature} 'enable'
;;
--no-color)
no_color=${TRUE}
;;
--branch=*)
amanzi_branch=`parse_option_with_equal "${opt}" 'branch'`
;;
--spacedim=*)
spacedim=`parse_option_with_equal "${opt}" 'spacedim'`
;;
--nersc_build)
nersc=${TRUE}
;;
--with-c-compiler=*)
tmp=`parse_option_with_equal "${opt}" 'with-c-compiler'`
build_c_compiler=`make_fullpath $tmp`
;;
--with-c-flags=*)
build_c_flags=`parse_option_with_equal "${opt}" 'with-c-flags'`
;;
--with-cxx-compiler=*)
tmp=`parse_option_with_equal "${opt}" 'with-cxx-compiler'`
build_cxx_compiler=`make_fullpath $tmp`
;;
--with-cxx-flags=*)
build_cxx_flags=`parse_option_with_equal "${opt}" 'with-cxx-flags'`
;;
--with-fort-compiler=*)
tmp=`parse_option_with_equal "${opt}" 'with-fort-compiler'`
build_fort_compiler=`make_fullpath $tmp`
;;
--with-fort-flags=*)
build_fort_flags=`parse_option_with_equal "${opt}" 'with-fort-flags'`
;;
--with-link-flags=*)
build_link_flags=`parse_option_with_equal "${opt}" 'with-link-flags'`
;;
--with-cmake=*)
tmp=`parse_option_with_equal "${opt}" 'with-cmake'`
cmake_binary=`make_fullpath $tmp`
;;
--with-ctest=*)
tmp=`parse_option_with_equal "${opt}" 'with-ctest'`
ctest_binary=`make_fullpath $tmp`
;;
--with-cmake)
cmake_binary=
;;
--with-hg=*)
tmp=`parse_option_with_equal "${opt}" 'with-hg'`
hg_binary=`make_fullpath $tmp`
;;
--with-curl=*)
tmp=`parse_option_with_equal "${opt}" 'with-curl'`
curl_binary=`make_fullpath $tmp`
;;
--with-mpi=*)
tmp=`parse_option_with_equal "${opt}" 'with-mpi'`
mpi_root_dir=`make_fullpath $tmp`
;;
--amanzi-build-dir=*)
tmp=`parse_option_with_equal "${opt}" 'amanzi-build-dir'`
amanzi_build_dir=`make_fullpath $tmp`
;;
--amanzi-install-prefix=*)
tmp=`parse_option_with_equal "${opt}" 'amanzi-install-prefix'`
amanzi_install_prefix=`make_fullpath $tmp`
;;
--tpl-install-prefix=*)
tmp=`parse_option_with_equal "${opt}" 'tpl-install-prefix'`
tpl_install_prefix=`make_fullpath $tmp`
;;
--tpl-build-dir=*)
tmp=`parse_option_with_equal "${opt}" 'tpl-build-dir'`
tpl_build_dir=`make_fullpath $tmp`
;;
--tpl-download-dir=*)
tmp=`parse_option_with_equal "${opt}" 'tpl-download-dir'`
tpl_download_dir=`make_fullpath $tmp`
;;
--tpl-config-file=*)
tmp=`parse_option_with_equal "${opt}" 'tpl-config-file'`
tpl_config_file=`make_fullpath $tmp`
;;
--print)
print_exit=${TRUE}
;;
*)
error_message "'${opt}' is an unknown option or an option missing a value"
exit_now 20
;;
esac
i=$[$i+1]
done
}
# CURL functions
curl_version()
{
$curl_binary --version
}
curl_protocols()
{
vers_string=`$curl_binary --version | grep Protocols: | sed 's/Protocols://'`
echo ${vers_string}
}
curl_test_protocol()
{
local protocols tmp type=$1
protocols=`curl_protocols`
tmp=`echo $protocols | sed "s/.*${type}.*/${type}-TRUE/g"`
if [ "${tmp}" = "${type}-TRUE" ]; then
echo ${TRUE}
else
echo ${FALSE}
fi
}
# CMake functions
function cmake_version
{
ver_string=`${cmake_binary} --version | sed 's/cmake version[ ]*//'`
echo ${ver_string}
}
function download_cmake
{
target_dir=$1
target=
pwd_save=`pwd`
if [ ! -z "${target_dir}" ]; then
mkdir_now ${target_dir}
cd ${target_dir}
target=${target_dir}/${cmake_archive_file}
fi
download_file ${cmake_url} ${cmake_archive_file} ${target}
cd ${pwd_save}
status_message "CMake download complete"
}
function unpack_cmake
{
archive=$1
final_source_dir=$2
pwd_save=`pwd`
# Create the final source destination
mkdir_now ${final_source_dir}
cd ${final_source_dir}
# Untar the archive file removing the leading path component
tar -z -x -f ${archive} --strip-components 1
if [ $? -ne 0 ]; then
error_message "Failed to untar CMake archive file ${archive}"
exit_now 30
fi
cd ${pwd_save}
status_message "Unpack CMake complete"
}
function configure_cmake
{
source_dir=$1
build_dir=$2
install_dir=$3
pwd_save=`pwd`
# Create and cd to the build directory
mkdir_now ${build_dir}
cd ${build_dir}
# Build the bootstrap args
boot_args="--prefix=${install_dir}"
echo "boot_args=$boot_args"
curl_supports_https=`curl_test_protocol https`
if [ "${curl_supports_https}" ]; then
boot_args="${boot_args} --system-curl"
fi
boot_args="${boot_args} --parallel=${parallel_jobs}"
# Run the bootstrap script
bootstrap_script=${source_dir}/bootstrap
if [ ! -e ${bootstrap_script} ]; then
error_message "CMake bootstrap script ${bootstrap_script} does not exist"
exit_now 30
fi
${bootstrap_script} ${boot_args}
if [ $? -ne 0 ]; then
error_message "CMake bootstrap script failed"
exit_now 30
fi
cd ${pwd_save}
status_message "Configure CMake complete"
}
function build_cmake
{
root_build_dir=$1
root_install_dir=$2
root_download_dir=$3
cmake_root_build_dir=${root_build_dir}/cmake
cmake_source_dir=${cmake_root_build_dir}/cmake-${cmake_version}-source
cmake_build_dir=${cmake_root_build_dir}/cmake-${cmake_version}-build
# Download the file
download_file ${cmake_url} ${cmake_archive_file} ${root_download_dir}
# Define the full path name of the archive file
if [ ! -z "${root_download_dir}" ]; then
archive=${root_download_dir}/${cmake_archive_file}
else
archive=${cmake_archive_file}
fi
# Unpack the archive file
unpack_cmake ${archive} ${cmake_source_dir}
# Configure (bootstrap) CMake
configure_cmake ${cmake_source_dir} ${cmake_build_dir} ${root_install_dir}
# Build CMake
cd ${cmake_build_dir}
make -j ${parallel_jobs}
if [ $? -ne 0 ]; then
error_message "Failed to build CMake"
exit_now 30
fi
# Install CMake
make install
if [ $? -ne 0 ]; then
error_message "Failed to install CMake"
exit_now 30
fi
cmake_binary=${root_install_dir}/bin/cmake
ctest_binary=${root_install_dir}/bin/ctest
status_message "CMake build complete"
}
# Mercury functions
function ascem_hg_clone
{
repo=$1
${hg_binary} clone ${ascem_protocol}://${ascem_site}/hg/$repo
if [ $? -ne 0 ]; then
error_message "Failed to clone ${repo} from ${ascem_site}"
exit_now 30
fi
}
function hg_change_branch()
{
branch=$1
save_dir=`pwd`
cd ${amanzi_source_dir}
status_message "Updating ${amanzi_source_dir} to branch ${branch}"
${hg_binary} update ${branch}
if [ $? -ne 0 ]; then
error_message "Failed to update ${amanzi_source_dir} to branch ${branch}"
exit_now 30
fi
cd ${save_dir}
}
# MPI Check
function check_mpi_root
{
if [ -z "${mpi_root_dir}" ]; then
mpi_root_env="${MPIROOT} ${MPI_ROOT} ${MPIHOME} ${MPI_HOME} ${MPI_PREFIX}"
for env_try in ${mpi_root_env}; do
if [ -e "${env_try}" ]; then
mpi_root_dir="${env_try}"
status_message "Located MPI installation in ${mpi_root_dir}"
break
fi
done
else
if [ ! -e "${mpi_root_dir}" ] ; then
error_message "MPI root directory ${mpi_root_dir} does not exist"
exit_now 30
fi
fi
}
# Compiler functions
function define_c_compiler
{
if [ -z "${build_c_compiler}" ]; then
status_message "Searching for a C compiler"
# build a list to search
c_search_list=
if [ -n "${mpi_root_dir}" ]; then
c_search_list="${mpi_root_dir}/bin/mpicc"
fi
if [ -n "${CC}" ]; then
c_search_list="${c_search_list} ${CC}"
fi
c_search_list="${c_search_list} ${known_c_compilers}"
for c_try in ${c_search_list}; do
status_message "Searching for ${c_try}"
full_c_try=`which ${c_try} 2>/dev/null`
if [ -e "${full_c_try}" ]; then
build_c_compiler="${full_c_try}"
break
fi
done
if [ -z "${build_c_compiler}" ]; then
error_message "Failed to locate a C compiler. Please use the --with-c-compiler option."
exit_now 30
fi
fi
status_message "Build with C compiler: ${build_c_compiler}"
export CC=${build_c_compiler}
}
function define_cxx_compiler
{
if [ -z "${build_cxx_compiler}" ]; then
status_message "Searching for a C++ compiler"
# build a list to search
cxx_search_list=
if [ -n "${mpi_root_dir}" ]; then
cxx_search_list="${mpi_root_dir}/bin/mpiCC"
cxx_search_list="${mpi_root_dir}/bin/mpicxx ${cxx_search_list}"
fi
if [ -n "${CXX}" ]; then
cxx_search_list="${cxx_search_list} ${CXX}"
fi
cxx_search_list="${cxx_search_list} ${known_cxx_compilers}"
for cxx_try in ${cxx_search_list}; do
status_message "Searching for ${cxx_try}"
full_cxx_try=`which ${cxx_try} 2>/dev/null`
if [ -e "${full_cxx_try}" ]; then
build_cxx_compiler="${full_cxx_try}"
break
fi
done
if [ -z "${build_cxx_compiler}" ]; then
error_message "Failed to locate a C++ compiler. Please use the --with-cxx-compiler option."
exit_now 30
fi
fi
status_message "Build with C++ compiler: ${build_cxx_compiler}"
export CXX=${build_cxx_compiler}
}
function define_fort_compiler
{
if [ -z "${build_fort_compiler}" ]; then
status_message "Searching for a Fortran compiler"
# build a list to search
fort_search_list=
if [ -n "${mpi_root_dir}" ]; then
fort_search_list="${mpi_root_dir}/bin/mpif90"
fi
if [ -n "${FC}" ]; then
fort_search_list="${fort_search_list} ${FC}"
fi
fort_search_list="${fort_search_list} ${known_fortran_compilers}"
for fort_try in ${fort_search_list}; do
status_message "Searching for ${fort_try}"
full_fort_try=`which ${fort_try} 2>/dev/null`
if [ -e "${full_fort_try}" ]; then
build_fort_compiler="${full_fort_try}"
break
fi
done
if [ -z "${build_fort_compiler}" ]; then
error_message "Failed to locate a Fortran compiler. Please use the --with-fort-compiler option."
exit_now 30
fi
fi
status_message "Build with Fortran compiler: ${build_fort_compiler}"
export FC=${build_fort_compiler}
}
function check_compilers
{
define_c_compiler
define_cxx_compiler
define_fort_compiler
status_message "Compiler Check complete"
}
version_compare_element()
{
(( $1 == $2 )) && return 0 #equal
(( $1 > $2 )) && return 1 #greater than
(( $1 < $2 )) && return 2 #less than
exit 1
}
version_compare()
{
A=(${1//./ })
B=(${2//./ })
i=0
while (( i < ${#A[@]} )) && (( i < ${#B[@]}));
do
version_compare_element "${A[i]}" "${B[i]}"
result=$?
[[ $result =~ [12] ]] && return $result
let i++
done
version_compare_element "${#A[i]}" "${#B[i]}"
return $?
}
# Tool Checks
function check_tools
{
# Check Mercurial
if [ ! -e "${hg_binary}" ]; then
error_message "Mercurial (hg) binary does not exist"
exit_now 10
fi
status_message "Mercury binary: ${hg_binary}"
# Check CURL
if [ ! -e "${curl_binary}" ]; then
error_message "CURL binary does not exist"
exit_now 10
fi
status_message "CURL binary: ${curl_binary}"
# Check CMake and CTest
if [ -z "${cmake_binary}" ]; then
status_message "CMake not defined. Will build"
build_cmake ${tpl_build_dir} ${tpl_install_prefix} ${tpl_download_dir}
fi
if [ ! -e "${cmake_binary}" ]; then
error_message "CMake binary does not exist. Will build."
build_cmake ${tpl_build_dir} ${tpl_install_prefix} ${tpl_download_dir}
else
# CMake binary does exist, not check the version number
ver_string=`${cmake_binary} --version | sed 's/cmake version[ ]*//'`
status_message "Found CMake version: ${ver_string}"
( version_compare "$ver_string" "$cmake_version" )
result=$?
if [ ${result} -eq 2 ]; then
status_message "CMake version is less than required version. Will build CMake version 2.8.8"
build_cmake ${tpl_build_dir} ${tpl_install_prefix} ${tpl_download_dir}
fi
fi
if [ ! -e "${ctest_binary}" ]; then
error_message "CTest binary does not exist. Will deactivate the test suite."
test_suite=${FALSE}
reg_tests=${FALSE}
fi
status_message "CMake binary: ${cmake_binary}"
status_message "CTest binary: ${ctest_binary}"
status_message "Tool check complete"
}
# Directory functions
function define_build_directories
{
# The amanzi build directory
if [ ! -e "${amanzi_build_dir}" ]; then
mkdir_now "${amanzi_build_dir}"
fi
# The TPL build directory
if [ ! -e "${tpl_build_dir}" ]; then
mkdir_now "${tpl_build_dir}"
fi