66
66
67
67
build_path=${PWD} /opencorrays-build
68
68
69
- # Interpret the second command-line argument, if present, as the number of threads for 'make'.
70
- # Otherwise, default to single-threaded 'make'.
71
- if [ -z $2 ]; then
69
+ # Interpret the second command-line argument, if present, as the number of threads for 'make'.
70
+ # Otherwise, default to single-threaded 'make'.
71
+ if [[ -z $2 ] ]; then
72
72
num_threads=1
73
73
else
74
74
num_threads=$2
75
75
fi
76
76
77
- CC_DEFAULT=gcc
78
- FC_DEFAULT=gfortran
79
- MPICC_DEFAULT=mpicc
80
- MPIFC_DEFAULT=mpif90
81
-
82
- printf " Checking whether CC and FC are both defined..."
83
- if [[ -z $CC || -z $FC ]]; then
84
- CC=$CC_DEFAULT
85
- FC=$FC_DEFAULT
86
- printf " no.\n"
87
- printf " Using default CC=$CC , FC=$FC \n"
88
- fi
89
-
90
- printf " Checking whether MPICC and MPIFC are both defined..."
91
- if [[ -z $MPICC || -z $MPIF90 ]]; then
92
- MPICC=$MPICC_DEFAULT
93
- MPIFC=$MPIFC_DEFAULT
94
- printf " no.\n"
95
- printf " Using default MPICC=$MPICC , MPIFC=$MPIFC \n"
96
- fi
97
-
98
77
find_or_install ()
99
78
{
100
- package_to_check=$1
101
- printf " Checking whether $package_to_check is in the PATH... "
102
- if type $package_to_check > /dev/null; then
79
+ package=$1
80
+ # This is a bash 3 hack standing in for a bash 4 hash (bash 3 is the lowest common
81
+ # denominator because, for licensing reasons, OS X only has bash 3 by default.)
82
+ # See http://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash
83
+ package_executable_array=(
84
+ " gcc:gfortran"
85
+ " cmake:cmake"
86
+ " mpich:mpif90"
87
+ " _unknown:0"
88
+ )
89
+ for element in " ${package_executable_array[@]} " ; do
90
+ KEY=" ${element%%:* } "
91
+ VALUE=" ${element##*: } "
92
+ if [[ " $KEY " == " _unknown" ]]; then
93
+ # No recognizeable argument passed so print usage information and exit:
94
+ printf " $this_script : Package name not recognized in function find_or_install.\n"
95
+ exit 1
96
+ elif [[ $package == " $KEY " ]]; then
97
+ executable=$VALUE
98
+ break
99
+ fi
100
+ done
101
+ printf " Checking whether $executable is in the PATH... "
102
+ if type $executable > /dev/null; then
103
103
printf " yes.\n"
104
- return
105
- fi
106
- # Set the MPI Fortran compiler for building OpenCoarrays prerequisites.
107
- if [ ! -z $MPIF90 ]; then
108
-
109
- # MPIF90 environment variable is not empty
110
- printf " Environment variable MPIF90=$MPIF90 .\n"
111
- if type $MPIF90 > /dev/null; then
112
- # MPIF90 environment variable specifies an executable program
113
- printf " Using MPIF90=$MPIF90 as the MPI Fortran compiler.\n"
114
- else
115
- # The specified MPIF90 was not found or does not execute. Time to bail.
116
- printf " MPIF90=$MPIF90 not found. Please set the MPIF90 environment variable to the \n"
117
- printf " name of an MPI Fortran compiler and prepend the path if it is not in your PATH.\n"
118
- exit 1
104
+
105
+ if [[ $package == " mpich" ]]; then
106
+ echo " Using the pre-installed mpicc and mpif90"
107
+ MPICC=mpicc
108
+ MPIFC=mpif90
119
109
fi
120
110
121
- else # MPIF90 environment variable is empty
122
-
123
- printf " Environment variable MPIF90 is empty. Trying mpif90'.\n"
124
-
125
- if type $MPIF90_DEFAULT > /dev/null; then
126
- # mpif90 is an executable program in the user's PATH
127
- printf " Found mpif90 in your path. Using mpif90 as the MPI Fortran compiler.\n"
128
- MPIF90=$MPIF90_DEFAULT
129
-
130
- else #
131
- printf " No $MPIF90_DEFAULT in your path. Ok to download and install the default MPI (MPICH)? (y/n).\n"
132
- read proceed
133
- if [[ $proceed == " y" ]]; then
134
- printf " Downloading, building, and installing MPICH.\n"
135
- cd install_prerequisites &&
136
- FC=$FC_DEFAULT CC=$CC_DEFAULT ./build mpich &&
137
- mpich_install_path=` ./build mpich --default --query` &&
138
- if [[ -f " $mpich_install_path /bin/mpif90" ]]; then
139
- printf " Installed $MPI_F90 in $mpich_install_path (You might add the 'bin' subdirectory to your PATH).\n"
111
+ never=false
112
+ until [ $never == true ]; do
113
+ # To avoid an infinite loop every branch must end with return, exit, or break
114
+
115
+ if [[ $package != " gcc" ]]; then
116
+
117
+ return # return
118
+
119
+ else # package is gcc
120
+
121
+ printf " Checking whether gfortran is version 5.1.0 or later..."
122
+ gfortran -o acceptable_compiler ./install_prerequisites/acceptable_compiler.f90
123
+ gfortran -o print_true ./install_prerequisites/print_true.f90
124
+ is_true=` ./print_true`
125
+ acceptable=` ./acceptable_compiler`
126
+ rm acceptable_compiler print_true
127
+
128
+ if [[ $acceptable == $is_true ]]; then
129
+
130
+ printf " yes\n"
131
+ FC=gfortran
132
+ CC=gcc
133
+ CXX=g++
134
+
135
+ return # found an acceptable gfortran in PATH
136
+
140
137
else
141
- printf " Can't find mpif90 in the expected location: $mpich_install_path /bin/mpif90 \n"
142
- fi
143
- else
144
- printf " Please install an MPI Fortran compiler and restart $this_script .\n"
145
- exit 1
138
+ printf " no\n"
139
+
140
+ break # need to install gfortran below
141
+ fi
142
+ printf " $this_script : an infinite until loop is missing a break, return, or exit.\n"
143
+ exit 1 # This should never be reached
144
+ fi
145
+ printf " $this_script : an infinite until loop is missing a break, return, or exit.\n"
146
+ exit 1 # This should never be reached
147
+ done
148
+ # The $executable is not an acceptable version
149
+ fi
150
+
151
+ # Now we know the $executable is not in the PATH or is not an acceptable version
152
+ printf " Ok to downloand, build, and install $package from source?\n"
153
+ if [[ $proceed == " y" ]]; then
154
+ printf " Downloading, building, and installing $package \n"
155
+ cd install_prerequisites &&
156
+ FC=gfortran CC=gcc CXX=g++ ./build $package &&
157
+ package_install_path=` ./build $package --default --query` &&
158
+ if [[ -f $package_install_path /bin/$executable ]]; then
159
+ printf " Installation successful."
160
+ printf " $package is in $package_install_path /bin \n"
161
+ if [[ $package == " gcc" ]]; then
162
+ FC=$package_install_path /bin/gfortran
163
+ CC=$package_install_path /bin/gcc
164
+ CXX=$package_install_path /bin/g++
165
+ elif [[ $package == " mpich" ]]; then
166
+ MPICC=$package_install_path /bin/mpicc
167
+ MPIFC=$package_install_path /bin/mpif90
168
+ else
169
+ PATH=$package_install_path /bin:$PATH
146
170
fi
171
+ return
172
+ else
173
+ printf " Installation unsuccessful."
174
+ printf " $package is not in the expected path: $package_install_path /bin \n"
175
+ exit 1
147
176
fi
148
-
177
+ else
178
+ printf " Aborting. OpenCoarrays installation requires $package "
149
179
exit 1
150
- fi
180
+ fi
181
+ printf " $this_script : the dependency installation logic is missing a return or exit.\n"
151
182
exit 1
152
183
}
153
184
185
+ # ##### Main Body ##########
186
+
154
187
if [[ $1 == ' --help' || $1 == ' -h' ]]; then
155
188
# Print usage information if script is invoked with --help or -h argument
156
189
usage | less
@@ -172,29 +205,36 @@ else
172
205
installation_record=install-opencoarrays.log
173
206
time \
174
207
{
175
- find_or_install " cmake" &&
176
- find_or_install " $MPIFC " &&
177
- find_or_install " $MPICC " &&
208
+ # Find or install GCC first to ensure we build MPICH with an acceptable version of GCC
209
+ find_or_install gcc &&
210
+ find_or_install mpich &&
211
+ find_or_install cmake &&
178
212
mkdir -p opencoarrays-build &&
179
213
cd opencoarrays-build &&
180
- CC=$MPICC FC=$MPIFC cmake .. -DCMAKE_INSTALL_PREFIX=$install_path &&
181
- make &&
182
- make install &&
183
- make clean
214
+ if [[ -z $MPICC || -z $MPIFC ]]; then
215
+ echo " Empty MPICC=$MPICC or MPIFC=$MPIFC "
216
+ exit 1
217
+ else
218
+ CC=$MPICC FC=$MPIFC cmake .. -DCMAKE_INSTALL_PREFIX=$install_path &&
219
+ make &&
220
+ make install &&
221
+ make clean
222
+ fi
184
223
} >&1 | tee $installation_record
185
224
186
225
# Report installation success or failure
187
226
printf " \n"
188
227
if [[ -f $install_path /bin/caf && -f $install_path /bin/cafrun && -f $install_path /bin/build ]]; then
189
- printf " $this_script : Done.\n"
228
+ printf " $this_script : Done.\n\n "
190
229
printf " The OpenCoarrays compiler wrapper (caf), program launcher (cafrun), and\n"
191
230
printf " prerequisite package installer (build) are in the following directory:\n"
192
- printf " $install_path /bin.\n"
231
+ printf " $install_path /bin.\n\n "
193
232
else
233
+ printf " $this_script : Done. \n\n"
194
234
printf " Something went wrong. The OpenCoarrays compiler wrapper (caf),\n"
195
235
printf " program launcher (cafrun), and prerequisite package installer (build) \n"
196
236
printf " are not in the expected location:\n"
197
237
printf " $install_path /bin.\n"
198
- printf " Please review the '$installation_record ' file for more information.\n"
238
+ printf " Please review the '$installation_record ' file for more information.\n\n "
199
239
fi
200
240
fi
0 commit comments