@@ -51,6 +51,7 @@ if [[ -z $1 ]]; then
5151else
5252 install_path=$1
5353fi
54+ build_path=${PWD} /opencoarrays-build
5455
5556
5657# Interpret the second command-line argument, if present, as the number of threads for 'make'.
@@ -77,7 +78,6 @@ usage()
7778 echo " Examples:"
7879 echo " "
7980 echo " $this_script "
80- echo " $this_script ${PWD} "
8181 echo " $this_script /opt/opencoarrays 4"
8282 echo " $this_script --help"
8383 echo " "
@@ -118,78 +118,97 @@ find_or_install()
118118 MPIFC=mpif90
119119 fi
120120
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.
121124 never=false
122125 until [ $never == true ]; do
123- # To avoid an infinite loop every branch must end with return, exit, or break
124126
125- if [[ $package != " gcc " ]] ; then
127+ # To avoid an infinite loop every branch must end with return, exit, or break
126128
127- return # return
129+ if [[ $package != " gcc " ]] ; then
128130
131+ # Accept any version and return from this function
132+ return
133+
129134 else # package is gcc
130135
131136 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
134139 is_true=` ./print_true`
135140 acceptable=` ./acceptable_compiler`
136141 rm acceptable_compiler print_true
137142
138143 if [[ $acceptable == $is_true ]]; then
139144
145+ # Acceptable gfortran in PATH
140146 printf " yes\n"
141147 FC=gfortran
142148 CC=gcc
143149 CXX=g++
144150
145- return # found an acceptable gfortran in PATH
151+ return # acceptable gfortran
146152
147153 else
148154 printf " no\n"
149-
150155 break # need to install gfortran below
151156 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"
153158 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" &&
156161 exit 1 # This should never be reached
157162 done
158163 # The $executable is not an acceptable version
159- fi
164+ fi && # Ending if type $executable > /dev/null;
160165
161- # Now we know the $executable is not in the PATH or is not an acceptable version
162166 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+
165173 printf " Downloading, building, and installing $package \n"
166- cd install_prerequisites &&
174+
167175 if [[ $package == " gcc" ]]; then
176+
168177 # 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... "
171180 if type flex > /dev/null; then
172181 printf " yes\n"
173- else
182+
183+ else # flex not in path
184+
174185 printf " no\n"
175186 printf " Ok to downloand, build, and install flex from source? (y/n) "
176187 read build_flex
188+
177189 if [[ $build_flex == " y" ]]; then
178- FC=gfortran CC=gcc CXX=g++ ./build flex
190+ # Recurse:
191+ find_or_install flex
179192 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
184193 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
185200 else
186201 printf " Aborting. Building GCC requires flex.\n"
187202 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+
193212 if [[ -f $package_install_path /bin/$executable ]]; then
194213 printf " Installation successful."
195214 printf " $package is in $package_install_path /bin \n"
@@ -204,24 +223,48 @@ find_or_install()
204223 PATH=$package_install_path /bin:$PATH
205224 return
206225 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"
209229 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.
215235 printf " $this_script : the dependency installation logic is missing a return or exit.\n"
216236 exit 1
217237}
218238
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 _____________________________________
220260
221261if [[ $1 == ' --help' || $1 == ' -h' ]]; then
262+
222263 # Print usage information if script is invoked with --help or -h argument
223264 usage | less
265+
224266elif [[ $1 == ' -v' || $1 == ' -V' || $1 == ' --version' ]]; then
267+
225268 # Print script copyright if invoked with -v, -V, or --version argument
226269 echo " "
227270 echo " OpenCoarrays installer"
@@ -233,44 +276,33 @@ elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
233276 echo " BSD 3-Clause License. For more information about these matters, see"
234277 echo " http://www.sourceryinstitute.org/license.html"
235278 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
260279
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
262285 printf " \n"
286+
287+ # Report installation success or failure:
263288 if [[ -f $install_path /bin/caf && -f $install_path /bin/cafrun && -f $install_path /bin/build ]]; then
289+
290+ # Installation succeeded
264291 printf " $this_script : Done.\n\n"
265292 printf " The OpenCoarrays compiler wrapper (caf), program launcher (cafrun), and\n"
266293 printf " prerequisite package installer (build) are in the following directory:\n"
267294 printf " $install_path /bin.\n\n"
268- else
295+
296+ else # Installation failed
297+
269298 printf " $this_script : Done. \n\n"
270299 printf " Something went wrong. The OpenCoarrays compiler wrapper (caf),\n"
271300 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"
273302 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