@@ -51,6 +51,7 @@ if [[ -z $1 ]]; then
51
51
else
52
52
install_path=$1
53
53
fi
54
+ build_path=${PWD} /opencoarrays-build
54
55
55
56
56
57
# Interpret the second command-line argument, if present, as the number of threads for 'make'.
@@ -77,7 +78,6 @@ usage()
77
78
echo " Examples:"
78
79
echo " "
79
80
echo " $this_script "
80
- echo " $this_script ${PWD} "
81
81
echo " $this_script /opt/opencoarrays 4"
82
82
echo " $this_script --help"
83
83
echo " "
@@ -118,78 +118,97 @@ find_or_install()
118
118
MPIFC=mpif90
119
119
fi
120
120
121
+ # Start an infinite loop to demarcate a block of code that can be exited via the 'break'
122
+ # command. Alternate exit points/mechanisms include 'return' from this fuction and 'exit'
123
+ # from this script.
121
124
never=false
122
125
until [ $never == true ]; do
123
- # To avoid an infinite loop every branch must end with return, exit, or break
124
126
125
- if [[ $package != " gcc " ]] ; then
127
+ # To avoid an infinite loop every branch must end with return, exit, or break
126
128
127
- return # return
129
+ if [[ $package != " gcc " ]] ; then
128
130
131
+ # Accept any version and return from this function
132
+ return
133
+
129
134
else # package is gcc
130
135
131
136
printf " Checking whether gfortran is version 5.1.0 or later..."
132
- gfortran -o acceptable_compiler ./install_prerequisites/ acceptable_compiler.f90
133
- gfortran -o print_true ./install_prerequisites/ print_true.f90
137
+ gfortran -o acceptable_compiler acceptable_compiler.f90
138
+ gfortran -o print_true print_true.f90
134
139
is_true=` ./print_true`
135
140
acceptable=` ./acceptable_compiler`
136
141
rm acceptable_compiler print_true
137
142
138
143
if [[ $acceptable == $is_true ]]; then
139
144
145
+ # Acceptable gfortran in PATH
140
146
printf " yes\n"
141
147
FC=gfortran
142
148
CC=gcc
143
149
CXX=g++
144
150
145
- return # found an acceptable gfortran in PATH
151
+ return # acceptable gfortran
146
152
147
153
else
148
154
printf " no\n"
149
-
150
155
break # need to install gfortran below
151
156
fi
152
- printf " $this_script : an infinite until loop is missing a break, return, or exit.\n"
157
+ printf " $this_script : an infinite ' until' loop is missing a break, return, or exit (see inner conditional) .\n"
153
158
exit 1 # This should never be reached
154
- fi
155
- printf " $this_script : an infinite until loop is missing a break, return, or exit.\n"
159
+ fi &&
160
+ printf " $this_script : an infinite until loop is missing a break, return, or exit (see outer conditional) .\n" &&
156
161
exit 1 # This should never be reached
157
162
done
158
163
# The $executable is not an acceptable version
159
- fi
164
+ fi && # Ending if type $executable > /dev/null;
160
165
161
- # Now we know the $executable is not in the PATH or is not an acceptable version
162
166
printf " Ok to downloand, build, and install $package from source? (y/n) "
163
- read proceed
164
- if [[ $proceed == " y" ]]; then
167
+ read proceed_with_build
168
+ if [[ $proceed_with_build != " y" ]]; then
169
+ printf " \nOpenCoarrays installation requires $package . Aborting.\n"
170
+ exit 1
171
+ else # permission granted to build
172
+
165
173
printf " Downloading, building, and installing $package \n"
166
- cd install_prerequisites &&
174
+
167
175
if [[ $package == " gcc" ]]; then
176
+
168
177
# Building GCC from source requires flex
169
- printf " Building requires the 'flex' package.\n"
170
- printf " Checking flex is in the PATH... "
178
+ printf " Building gfortran requires the 'flex' package.\n"
179
+ printf " Checking whether flex is in the PATH... "
171
180
if type flex > /dev/null; then
172
181
printf " yes\n"
173
- else
182
+
183
+ else # flex not in path
184
+
174
185
printf " no\n"
175
186
printf " Ok to downloand, build, and install flex from source? (y/n) "
176
187
read build_flex
188
+
177
189
if [[ $build_flex == " y" ]]; then
178
- FC=gfortran CC=gcc CXX=g++ ./build flex
190
+ # Recurse:
191
+ find_or_install flex
179
192
flex_install_path=` ./build flex --default --query` &&
180
- if [[ -f $flex_install_path /bin/flex ]]; then
181
- printf " Installation successful."
182
- printf " $package is in $flex_install_path /bin \n"
183
- fi
184
193
PATH=$flex_install_path /bin:$PATH
194
+ if type flex > /dev/null; then
195
+ printf " " # nothing to do.
196
+ else
197
+ echo " $this_script : an attempt to install GCC prerequeisite flex failed."
198
+ exit 1
199
+ fi
185
200
else
186
201
printf " Aborting. Building GCC requires flex.\n"
187
202
exit 1
188
- fi
189
- fi
190
- fi
191
- FC=gfortran CC=gcc CXX=g++ ./build $package --default $num_threads &&
192
- package_install_path=` ./build $package --default --query` &&
203
+ fi # Ending 'if [[ $build_flex == "y" ]];'
204
+
205
+ fi # Ending 'if type flex > /dev/null;'
206
+
207
+ fi # Ending 'if [[ $package == "gcc" ]];'
208
+
209
+ FC=gfortran CC=gcc CXX=g++ ./build $package --default $num_threads
210
+ package_install_path=` ./build $package --default --query`
211
+
193
212
if [[ -f $package_install_path /bin/$executable ]]; then
194
213
printf " Installation successful."
195
214
printf " $package is in $package_install_path /bin \n"
@@ -204,24 +223,48 @@ find_or_install()
204
223
PATH=$package_install_path /bin:$PATH
205
224
return
206
225
else
207
- printf " Installation unsuccessful."
208
- printf " $package is not in the expected path: $package_install_path /bin \n"
226
+ printf " Installation unsuccessful. "
227
+ printf " $package is not in the following expected path:\n"
228
+ printf " $package_install_path /bin \n"
209
229
exit 1
210
- fi
211
- else
212
- printf " Aborting. OpenCoarrays installation requires $package \n "
213
- exit 1
214
- fi
230
+ fi # End 'if [[ -f $package_install_path/bin/$executable ]]'
231
+
232
+ fi # End 'if [[ $proceed_with_build == "y" ]]; then'
233
+
234
+ # Each branch above should end with a 'return' or 'exit' so we should never reach here.
215
235
printf " $this_script : the dependency installation logic is missing a return or exit.\n"
216
236
exit 1
217
237
}
218
238
219
- # ___________________ Define functions for use in the main body ___________________
239
+ build_opencoarrays ()
240
+ {
241
+ # A default OpenCoarrays build requires CMake and MPICH. MPICH requires GCC.
242
+ find_or_install gcc &&
243
+ find_or_install mpich &&
244
+ find_or_install cmake &&
245
+ mkdir -p $build_path &&
246
+ cd $build_path &&
247
+ if [[ -z $MPICC || -z $MPIFC ]]; then
248
+ echo " Empty MPICC=$MPICC or MPIFC=$MPIFC "
249
+ exit 1
250
+ else
251
+ CC=$MPICC FC=$MPIFC cmake .. -DCMAKE_INSTALL_PREFIX=$install_path &&
252
+ make -j$num_threads &&
253
+ make install &&
254
+ make clean
255
+ fi
256
+ }
257
+ # ___________________ End of function definitions for use in the main body __________________
258
+
259
+ # __________________________________ Start of Main Body _____________________________________
220
260
221
261
if [[ $1 == ' --help' || $1 == ' -h' ]]; then
262
+
222
263
# Print usage information if script is invoked with --help or -h argument
223
264
usage | less
265
+
224
266
elif [[ $1 == ' -v' || $1 == ' -V' || $1 == ' --version' ]]; then
267
+
225
268
# Print script copyright if invoked with -v, -V, or --version argument
226
269
echo " "
227
270
echo " OpenCoarrays installer"
@@ -233,44 +276,33 @@ elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
233
276
echo " BSD 3-Clause License. For more information about these matters, see"
234
277
echo " http://www.sourceryinstitute.org/license.html"
235
278
echo " "
236
- else
237
-
238
-
239
- # Find or install prerequisites and install OpenCoarrays
240
- build_path=${PWD} /opencoarrays-build
241
- installation_record=install-opencoarrays.log
242
- time \
243
- {
244
- # Building OpenCoarrays with CMake requires MPICH and GCC; MPICH requires GCC.
245
- find_or_install gcc &&
246
- find_or_install mpich &&
247
- find_or_install cmake &&
248
- mkdir -p $build_path &&
249
- cd $build_path &&
250
- if [[ -z $MPICC || -z $MPIFC ]]; then
251
- echo " Empty MPICC=$MPICC or MPIFC=$MPIFC "
252
- exit 1
253
- else
254
- CC=$MPICC FC=$MPIFC cmake .. -DCMAKE_INSTALL_PREFIX=$install_path &&
255
- make -j$num_threads &&
256
- make install &&
257
- make clean
258
- fi
259
- } >&1 | tee $installation_record
260
279
261
- # Report installation success or failure
280
+ else # Find or install prerequisites and install OpenCoarrays
281
+
282
+ cd install_prerequisites &&
283
+ installation_record=install-opencoarrays.log &&
284
+ build_opencoarrays >&1 | tee ../$installation_record
262
285
printf " \n"
286
+
287
+ # Report installation success or failure:
263
288
if [[ -f $install_path /bin/caf && -f $install_path /bin/cafrun && -f $install_path /bin/build ]]; then
289
+
290
+ # Installation succeeded
264
291
printf " $this_script : Done.\n\n"
265
292
printf " The OpenCoarrays compiler wrapper (caf), program launcher (cafrun), and\n"
266
293
printf " prerequisite package installer (build) are in the following directory:\n"
267
294
printf " $install_path /bin.\n\n"
268
- else
295
+
296
+ else # Installation failed
297
+
269
298
printf " $this_script : Done. \n\n"
270
299
printf " Something went wrong. The OpenCoarrays compiler wrapper (caf),\n"
271
300
printf " program launcher (cafrun), and prerequisite package installer (build) \n"
272
- printf " are not in the expected location:\n"
301
+ printf " are not in the following expected location:\n"
273
302
printf " $install_path /bin.\n"
274
- printf " Please review the '$installation_record ' file for more information.\n\n"
275
- fi
276
- fi
303
+ printf " Please review the following file for more information:\n"
304
+ printf " $install_path /$installation_record \n\n\n"
305
+
306
+ fi # Ending check for caf, cafrun, build not in expected path
307
+ fi # Ending argument checks
308
+ # ____________________________________ End of Main Body ____________________________________________
0 commit comments