3232# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3333# POSSIBILITY OF SUCH DAMAGE.
3434
35+ # This file is organized into three sections:
36+ # 1. Command-line argument processor.
37+ # 2. Function definitions.
38+ # 3. Main body.
39+ # The script depends on several external programs, including a second script that
40+ # builds prerequisite software. Building prerequisites requires network access
41+ # unless tar balls of the prerequisites are present.
42+
43+ # ___________________ Process command-line arguments ___________________
44+
3545this_script=` basename $0 `
3646
47+ # Interpret the first command-line argument, if present, as the OpenCoarrays installation path.
48+ # Otherwise, install in a subdirectory of the present working directory.
49+ if [[ -z $1 ]]; then
50+ install_path=${PWD} /opencoarrays-installation
51+ else
52+ install_path=$1
53+ fi
54+
55+
56+ # Interpret the second command-line argument, if present, as the number of threads for 'make'.
57+ # Otherwise, default to single-threaded 'make'.
58+ if [[ -z $2 ]]; then
59+ num_threads=1
60+ else
61+ num_threads=$2
62+ fi
63+
64+ # ___________________ Define functions for use in the main body ___________________
65+
3766usage ()
3867{
3968 echo " "
@@ -55,25 +84,6 @@ usage()
5584 exit 1
5685}
5786
58- # Interpret the first command-line argument, if present, as the installation path.
59- # Otherwise, install in a subdirectory of the present working directory.
60- default_install_path=${PWD} /opencoarrays-installation
61- if [[ -z $1 ]]; then
62- install_path=$default_install_path
63- else
64- install_path=$1
65- fi
66-
67- build_path=${PWD} /opencorrays-build
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
72- num_threads=1
73- else
74- num_threads=$2
75- fi
76-
7787find_or_install ()
7888{
7989 package=$1
@@ -153,7 +163,12 @@ find_or_install()
153163 if [[ $proceed == " y" ]]; then
154164 printf " Downloading, building, and installing $package \n"
155165 cd install_prerequisites &&
156- FC=gfortran CC=gcc CXX=g++ ./build $package &&
166+ if [[ $package == " gcc" ]]; then
167+ FC=gfortran CC=gcc CXX=g++ ./build flex --default $num_threads
168+ flex_install_path=` ./build flex --default --query` &&
169+ PATH=$flex_install_path /bin:$PATH
170+ fi
171+ FC=gfortran CC=gcc CXX=g++ ./build $package --default $num_threads &&
157172 package_install_path=` ./build $package --default --query` &&
158173 if [[ -f $package_install_path /bin/$executable ]]; then
159174 printf " Installation successful."
@@ -165,9 +180,8 @@ find_or_install()
165180 elif [[ $package == " mpich" ]]; then
166181 MPICC=$package_install_path /bin/mpicc
167182 MPIFC=$package_install_path /bin/mpif90
168- else
169- PATH=$package_install_path /bin:$PATH
170183 fi
184+ PATH=$package_install_path /bin:$PATH
171185 return
172186 else
173187 printf " Installation unsuccessful."
@@ -182,7 +196,7 @@ find_or_install()
182196 exit 1
183197}
184198
185- # ##### Main Body ##########
199+ # ___________________ Define functions for use in the main body ___________________
186200
187201if [[ $1 == ' --help' || $1 == ' -h' ]]; then
188202 # Print usage information if script is invoked with --help or -h argument
@@ -201,23 +215,25 @@ elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then
201215 echo " "
202216else
203217
218+
204219 # Find or install prerequisites and install OpenCoarrays
220+ build_path=${PWD} /opencoarrays-build
205221 installation_record=install-opencoarrays.log
206222 time \
207223 {
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 &&
212- mkdir -p opencoarrays-build &&
213- cd opencoarrays-build &&
224+ # Building OpenCoarrays with CMake requires MPICH and GCC; MPICH requires GCC.
225+ find_or_install gcc &&
226+ find_or_install mpich &&
227+ find_or_install cmake &&
228+ mkdir -p $build_path &&
229+ cd $build_path &&
214230 if [[ -z $MPICC || -z $MPIFC ]]; then
215231 echo " Empty MPICC=$MPICC or MPIFC=$MPIFC "
216232 exit 1
217233 else
218234 CC=$MPICC FC=$MPIFC cmake .. -DCMAKE_INSTALL_PREFIX=$install_path &&
219- make &&
220- make install &&
235+ make -j $num_threads &&
236+ make install &&
221237 make clean
222238 fi
223239 } >&1 | tee $installation_record
0 commit comments