Skip to content

Commit 8b2ee88

Browse files
author
Damian Rouson
committed
Documented and refactored corrected install.sh and install_prerequisites/build to improve clarity and robustness and to correct an error that occurred when the GCC build prerequisite 'flex' is present but the gfortran version in the path is < 5.1.0.
Signed-off-by: Damian Rouson <[email protected]>
1 parent ef039ee commit 8b2ee88

File tree

2 files changed

+124
-84
lines changed

2 files changed

+124
-84
lines changed

install.sh

Lines changed: 99 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ if [[ -z $1 ]]; then
5151
else
5252
install_path=$1
5353
fi
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

221261
if [[ $1 == '--help' || $1 == '-h' ]]; then
262+
222263
# Print usage information if script is invoked with --help or -h argument
223264
usage | less
265+
224266
elif [[ $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 ____________________________________________

install_prerequisites/build

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bin/bash
1+
#!/bin/bash
22
#
33
# build
44
#
@@ -232,8 +232,10 @@ download_if_necessary()
232232
if [[ $package_to_build == 'gcc' ]]; then
233233
if [[ $version_to_build == 'trunk' ]]; then
234234
gcc_tail='trunk'
235+
elif [[ $version_to_build == '--avail' || $version_to_build == '-a' ]]; then
236+
gcc_tail='branches'
235237
else
236-
gcc_tail=/branches/$version_to_build
238+
gcc_tail=/branches/$version_to_build
237239
fi
238240
fi
239241
package_url_tail=(
@@ -265,14 +267,19 @@ download_if_necessary()
265267
echo "Found $url_tail in the current directory. Skipping download"
266268
elif [ -d "$url_tail" ]; then
267269
# This happens with directories downloaded via version control solftware.
268-
# Cowardly refusing to tackle the complexities of version control in a script.
270+
# I'm cowardly refusing to tackle the complexities of version control in a script.
269271
# Braver solutions might involve "svn cleanup $url_tail && svn update $url_tail"
270272
# or "git pull --rebase".
271-
echo "Found $url_tail subdirectory in the present working directory."
272-
echo "Please rename or remove it and restart the '$this_script' script."
273+
echo "Found '$url_tail' subdirectory in ${PWD}."
274+
echo "Please rename or remove it and restart the installation script."
275+
exit 1
273276
else
274-
if [[ "$fetch" == "svn" || "$fetch" == "cvs" ]]; then
275-
args=checkout
277+
if [[ "$fetch" == "svn" ]]; then
278+
if [[ $version_to_build == '--avail' || $version_to_build == '-a' ]]; then
279+
args=ls
280+
else
281+
args=checkout
282+
fi
276283
elif [[ "$fetch" == "wget" ]]; then
277284
args=--no-check-certificate
278285
elif [[ "$fetch" == "ftp" ]]; then
@@ -283,13 +290,16 @@ download_if_necessary()
283290
printf "Downloading $package_to_build $version_to_build.\n"
284291
printf "Download command: $fetch $args $url\n"
285292
$fetch $args $url
293+
if [[ $version_to_build == '--avail' || $version_to_build == '-a' ]]; then
294+
exit 1
295+
fi
286296
fi
287297
}
288298

289299
# Unpack pkg-config if the unpacked tar ball is not in the present working directory
290300
unpack_if_necessary()
291301
{
292-
if [[ $fetch == "svn" || $fetch == "git" || $fetch == "cvs" ]]; then
302+
if [[ $fetch == "svn" || $fetch == "git" ]]; then
293303
package_source_directory=$url_tail
294304
else
295305
printf "Unpacking $url_tail. \n"
@@ -335,15 +345,13 @@ elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
335345
echo ""
336346
else
337347
# Download, unpack, and build CMake
338-
time \
339-
{
340-
check_prerequisites &&
341-
download_if_necessary &&
342-
unpack_if_necessary &&
343-
CC=$CC CXX=$CXX build_and_install $package_to_build $version_to_build $install_path $num_threads
344-
} >&1 | tee build-$package_to_build.log
345-
printf "\n"
346-
printf "$this_script: Done. Check for $package_to_build in the installation path $install_path\n"
348+
check_prerequisites &&
349+
download_if_necessary &&
350+
unpack_if_necessary &&
351+
CC=$CC CXX=$CXX build_and_install $package_to_build $version_to_build $install_path $num_threads \
352+
>&1 | tee build-$package_to_build.log &&
353+
printf "\n" &&
354+
printf "$this_script: Done. Check for $package_to_build in the installation path $install_path\n" &&
347355
printf "\n"
348356
fi
349357

0 commit comments

Comments
 (0)