|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# build |
| 4 | +# |
| 5 | +# -- This script installs OpenCoarrays and its prerequisites. |
| 6 | +# |
| 7 | +# OpenCoarrays is distributed under the OSI-approved BSD 3-clause License: |
| 8 | +# Copyright (c) 2015, Sourcery, Inc. |
| 9 | +# Copyright (c) 2015, Sourcery Institute |
| 10 | +# All rights reserved. |
| 11 | +# |
| 12 | +# Redistribution and use in source and binary forms, with or without modification, |
| 13 | +# are permitted provided that the following conditions are met: |
| 14 | +# |
| 15 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 16 | +# list of conditions and the following disclaimer. |
| 17 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this |
| 18 | +# list of conditions and the following disclaimer in the documentation and/or |
| 19 | +# other materials provided with the distribution. |
| 20 | +# 3. Neither the names of the copyright holders nor the names of their contributors |
| 21 | +# may be used to endorse or promote products derived from this software without |
| 22 | +# specific prior written permission. |
| 23 | +# |
| 24 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 25 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 26 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 27 | +# IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 28 | +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 29 | +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 | +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 31 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 32 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 | +# POSSIBILITY OF SUCH DAMAGE. |
| 34 | + |
| 35 | +this_script=`basename $0` |
| 36 | + |
| 37 | +usage() |
| 38 | +{ |
| 39 | + echo "" |
| 40 | + echo " $this_script - Bash script for installing OpenCoarrays and its prerequisites" |
| 41 | + echo "" |
| 42 | + echo " Usage (optional arguments in square brackets): " |
| 43 | + echo " $this_script [<options>] or [<installation-path> <number-of-threads>]" |
| 44 | + echo "" |
| 45 | + echo " Options:" |
| 46 | + echo " --help, -h Show this help message" |
| 47 | + echo "" |
| 48 | + echo " Examples:" |
| 49 | + echo "" |
| 50 | + echo " $this_script" |
| 51 | + echo " $this_script ${PWD}" |
| 52 | + echo " $this_script /opt/opencoarrays 4" |
| 53 | + echo " $this_script --help" |
| 54 | + echo "" |
| 55 | + exit 1 |
| 56 | +} |
| 57 | + |
| 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 | + |
| 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 | + |
| 98 | +find_or_install() |
| 99 | +{ |
| 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 |
| 103 | + 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 |
| 119 | + fi |
| 120 | + |
| 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" |
| 140 | + 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 |
| 146 | + fi |
| 147 | + fi |
| 148 | + |
| 149 | + exit 1 |
| 150 | + fi |
| 151 | + exit 1 |
| 152 | +} |
| 153 | + |
| 154 | +if [[ $1 == '--help' || $1 == '-h' ]]; then |
| 155 | + # Print usage information if script is invoked with --help or -h argument |
| 156 | + usage | less |
| 157 | +elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then |
| 158 | + # Print script copyright if invoked with -v, -V, or --version argument |
| 159 | + echo "" |
| 160 | + echo "OpenCoarrays installer" |
| 161 | + echo "Copyright (C) 2015 Sourcery, Inc." |
| 162 | + echo "Copyright (C) 2015 Sourcery Institute" |
| 163 | + echo "" |
| 164 | + echo "$this_script comes with NO WARRANTY, to the extent permitted by law." |
| 165 | + echo "You may redistribute copies of $this_script under the terms of the" |
| 166 | + echo "BSD 3-Clause License. For more information about these matters, see" |
| 167 | + echo "http://www.sourceryinstitute.org/license.html" |
| 168 | + echo "" |
| 169 | +else |
| 170 | + |
| 171 | + # Find or install prerequisites and install OpenCoarrays |
| 172 | + installation_record=install-opencoarrays.log |
| 173 | + time \ |
| 174 | + { |
| 175 | + find_or_install "cmake" && |
| 176 | + find_or_install "$MPIFC" && |
| 177 | + find_or_install "$MPICC" && |
| 178 | + mkdir -p opencoarrays-build && |
| 179 | + cd opencoarrays-build && |
| 180 | + CC=$MPICC FC=$MPIFC cmake .. -DCMAKE_INSTALL_PREFIX=$install_path && |
| 181 | + make && |
| 182 | + make install |
| 183 | + } >&1 | tee $installation_record |
| 184 | + |
| 185 | + # Report installation success or failure |
| 186 | + printf "\n" |
| 187 | + if [[ -f $install_path/bin/caf && -f $install_path/bin/cafrun && -f $install_path/bin/build ]]; then |
| 188 | + printf "$this_script: Done.\n" |
| 189 | + printf "The OpenCoarrays compiler wrapper (caf), program launcher (cafrun), and\n" |
| 190 | + printf "prerequisite package installer (build) are in the following directory:\n" |
| 191 | + printf "$install_path/bin.\n" |
| 192 | + else |
| 193 | + printf "Something went wrong. The OpenCoarrays compiler wrapper (caf),\n" |
| 194 | + printf "program launcher (cafrun), and prerequisite package installer (build) \n" |
| 195 | + printf "are not in the expected location:\n" |
| 196 | + printf "$install_path/bin.\n" |
| 197 | + printf "Please review the '$installation_record' file for more information.\n" |
| 198 | + fi |
| 199 | +fi |
0 commit comments