Skip to content

Commit 6cfcd1d

Browse files
committed
Firt complete draft of the installation script. It has been tested so far on Linux with an acceptable set of pre-installed prerequisites. It needs to be tested on on OS X and with uninstalled or unacceptable prerequisites to test the the building of the prerequisites.
Signed-off-by: Damian Rouson <[email protected]>
1 parent 82e96e5 commit 6cfcd1d

File tree

4 files changed

+126
-79
lines changed

4 files changed

+126
-79
lines changed

install.sh

Lines changed: 118 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -66,91 +66,124 @@ fi
6666

6767
build_path=${PWD}/opencorrays-build
6868

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
7272
num_threads=1
7373
else
7474
num_threads=$2
7575
fi
7676

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-
9877
find_or_install()
9978
{
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
103103
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
119109
fi
120110

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+
140137
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
146170
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
147176
fi
148-
177+
else
178+
printf "Aborting. OpenCoarrays installation requires $package"
149179
exit 1
150-
fi
180+
fi
181+
printf "$this_script: the dependency installation logic is missing a return or exit.\n"
151182
exit 1
152183
}
153184

185+
###### Main Body ##########
186+
154187
if [[ $1 == '--help' || $1 == '-h' ]]; then
155188
# Print usage information if script is invoked with --help or -h argument
156189
usage | less
@@ -172,29 +205,36 @@ else
172205
installation_record=install-opencoarrays.log
173206
time \
174207
{
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 &&
178212
mkdir -p opencoarrays-build &&
179213
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
184223
} >&1 | tee $installation_record
185224

186225
# Report installation success or failure
187226
printf "\n"
188227
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"
190229
printf "The OpenCoarrays compiler wrapper (caf), program launcher (cafrun), and\n"
191230
printf "prerequisite package installer (build) are in the following directory:\n"
192-
printf "$install_path/bin.\n"
231+
printf "$install_path/bin.\n\n"
193232
else
233+
printf "$this_script: Done. \n\n"
194234
printf "Something went wrong. The OpenCoarrays compiler wrapper (caf),\n"
195235
printf "program launcher (cafrun), and prerequisite package installer (build) \n"
196236
printf "are not in the expected location:\n"
197237
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"
199239
fi
200240
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program main
2+
use iso_fortran_env, only : compiler_version
3+
implicit none
4+
print *,compiler_version() >= " GCC version 5.1.0"
5+
end program

install_prerequisites/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ else
340340
check_prerequisites &&
341341
download_if_necessary &&
342342
unpack_if_necessary &&
343-
CC=$CC CXX=$CXX build_and_install package $version_to_build $install_path $num_threads
343+
CC=$CC CXX=$CXX build_and_install $package_to_build $version_to_build $install_path $num_threads
344344
} >&1 | tee build-$package_to_build.log
345345
printf "\n"
346346
printf "$this_script: Done. Check for $package_to_build in the installation path $install_path\n"

install_prerequisites/print_true.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print *,.true.
2+
end

0 commit comments

Comments
 (0)