|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +### Diagnostics ### |
| 4 | + |
| 5 | +# Print usage information and exit if this script was invoked with no arugments or with -h or --help |
| 6 | +# as the first argument or in a location other than the top-level OpenCoarrays source directory |
| 7 | +function usage() |
| 8 | +{ |
| 9 | + echo "Usage:" |
| 10 | + echo " cd <opencoarrays-source-directory>" |
| 11 | + echo " ./developer_scripts/patched-trunk-install.sh <patch-file>" |
| 12 | + exit 1 |
| 13 | +} |
| 14 | +[[ $# -eq 0 || "${1}" == "-h" || "${1}" == "--help" || ! -f src/libcaf.h ]] && usage |
| 15 | + |
| 16 | +patch_file="${1}" |
| 17 | + |
| 18 | +function set_absolute_path() |
| 19 | +{ |
| 20 | + : "${1?'set_absolute_path: no argument provided'}" |
| 21 | + |
| 22 | + arg=${1} |
| 23 | + first_character=$(echo "${arg}" | cut -c1-1) |
| 24 | + if [[ "${first_character}" == "/" ]]; then |
| 25 | + absolute_path="${arg}" |
| 26 | + else |
| 27 | + absolute_path="${PWD%%/}/${arg}" |
| 28 | + fi |
| 29 | +} |
| 30 | +set_absolute_path "${patch_file}" |
| 31 | + |
| 32 | +# Exit on error or use of an unset variable: |
| 33 | +set -o errexit |
| 34 | +set -o nounset |
| 35 | + |
| 36 | +# Return the highest exit code in a chain of pipes: |
| 37 | +set -o pipefail |
| 38 | + |
| 39 | +### Define functions |
| 40 | +function choose_package_manager() |
| 41 | +{ |
| 42 | + OS=$(uname) |
| 43 | + case "${OS}" in |
| 44 | + |
| 45 | + "Darwin" ) |
| 46 | + if type brew >& /dev/null; then |
| 47 | + package_manager="brew" |
| 48 | + elif type port >& /dev/null; then |
| 49 | + package_manager="port" |
| 50 | + fi |
| 51 | + ;; |
| 52 | + |
| 53 | + "Linux" ) |
| 54 | + if [[ ! -f /etc/lsb-release ]]; then |
| 55 | + echo "I don't recognize this Linux distribution. Possibly it's too old to have the expected /etc/lsb-release file." |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + . /etc/lsb-release |
| 59 | + |
| 60 | + case "${DISTRIB_ID:-}" in |
| 61 | + "Ubuntu" ) |
| 62 | + package_manager="apt-get" |
| 63 | + ;; |
| 64 | + "Debian" ) |
| 65 | + package_manager="dnf" |
| 66 | + ;; |
| 67 | + *) |
| 68 | + echo "I don't recognize the Linux distribution ${DISTRIB_ID:-}" |
| 69 | + exit 1 |
| 70 | + ;; |
| 71 | + esac |
| 72 | + ;; |
| 73 | + |
| 74 | + *) |
| 75 | + echo "I don't recognize the operating system \${OS}" |
| 76 | + exit 1 |
| 77 | + ;; |
| 78 | + esac |
| 79 | +} |
| 80 | +choose_package_manager |
| 81 | + |
| 82 | +### Install any missing prerequisite packages and executable programs ### |
| 83 | + |
| 84 | +### First install the packages for which package management suffices: |
| 85 | +function install_if_missing() |
| 86 | +{ |
| 87 | + # Exit with error message if no first argument: |
| 88 | + : "${1?'\n ERROR: install_if_missing function requires a package name as the first argument.'}" |
| 89 | + |
| 90 | + package="${1}" # Interpret the 1st argument as the package name |
| 91 | + executable="${2:-${1}}" # Interpret the 2nd argument as the prerequisite executable program (Default = 1st argument) |
| 92 | + |
| 93 | + printf "Checking whether ${executable} is in path... " |
| 94 | + |
| 95 | + if type ${executable} >& /dev/null; then |
| 96 | + |
| 97 | + printf "yes.\n" |
| 98 | + |
| 99 | + else # install package |
| 100 | + |
| 101 | + printf "no\n" |
| 102 | + echo "sudo ${package_manager} install ${package}" |
| 103 | + sudo "${package_manager}" install ${package} |
| 104 | + |
| 105 | + fi |
| 106 | +} |
| 107 | + |
| 108 | +# Install subversion to check out the GCC trunk if not already in the PATH: |
| 109 | +install_if_missing subversion svn |
| 110 | + |
| 111 | +# Install released versions of the GNU compilers if not already in the PATH: |
| 112 | +install_if_missing gfortran |
| 113 | +install_if_missing g++ |
| 114 | + |
| 115 | +# Install build software: |
| 116 | +install_if_missing cmake |
| 117 | +install_if_missing make |
| 118 | +install_if_missing flex |
| 119 | + |
| 120 | +### Install the prerequisites that must be built from source ### |
| 121 | + |
| 122 | +# Download and build the GCC trunk: |
| 123 | +echo "Downloading the GCC trunk." |
| 124 | +./install.sh --only-download --package gcc --install-branch trunk |
| 125 | + |
| 126 | +# Patch the GCC trunk and rebuild |
| 127 | +echo "Patching the GCC source using ${absolute_path}." |
| 128 | +pushd prerequisites/downloads/trunk |
| 129 | + patch -p0 < "${absolute_path}" |
| 130 | +popd |
| 131 | + |
| 132 | +# Build the patched GCC trunk |
| 133 | +echo "Rebuilding the patched GCC source." |
| 134 | +./install.sh --package gcc --install-branch trunk --yes-to-all |
| 135 | + |
| 136 | +# Verify that GCC installed in the expected path |
| 137 | +patched_GCC_install_path=${PWD}/prerequisites/installations/gcc/trunk |
| 138 | +if ! type "${patched_GCC_install_path}"/bin/gfortran >& /dev/null; then |
| 139 | + echo "gfortran is not installed in the expected location ${patched_GCC_install_path}." |
| 140 | + exit 1 |
| 141 | +fi |
| 142 | + |
| 143 | +# Ensure that the just-installed GCC libraries are used when linking |
| 144 | +echo "Setting and exporting LD_LIBRARY_PATH" |
| 145 | + |
| 146 | +function prepend_to_LD_LIBRARY_PATH() { |
| 147 | + : ${1?'set_LD_LIBRARY_PATH: missing path'} |
| 148 | + new_path="${1}" |
| 149 | + if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then |
| 150 | + export LD_LIBRARY_PATH="${new_path}" |
| 151 | + else |
| 152 | + export LD_LIBRARY_PATH="${new_path}:${LD_LIBRARY_PATH}" |
| 153 | + fi |
| 154 | +} |
| 155 | + |
| 156 | +old_path="${LD_LIBRARY_PATH:-}" |
| 157 | + |
| 158 | +if [[ -d "${PWD}/prerequisites/installations/gcc/trunk/lib" ]]; then |
| 159 | + prepend_to_LD_LIBRARY_PATH "${patched_GCC_install_path}/lib/" |
| 160 | +fi |
| 161 | + |
| 162 | +if [[ -d "${PWD}/prerequisites/installations/gcc/trunk/lib64" ]]; then |
| 163 | + prepend_to_LD_LIBRARY_PATH "${patched_GCC_install_path}/lib64/" |
| 164 | +fi |
| 165 | + |
| 166 | +echo "\${LD_LIBRARY_PATH}=${LD_LIBRARY_PATH:=}" |
| 167 | + |
| 168 | +if [[ "${LD_LIBRARY_PATH}" == "${old_path}" ]]; then |
| 169 | + echo "gfortran libraries did not install where expected: ${patched_GCC_install_path}/lib64 or ${patched_GCC_install_path}/lib" |
| 170 | + exit 1 |
| 171 | +fi |
| 172 | + |
| 173 | +# Build MPICH with the patched compilers. |
| 174 | +echo "Building MPICH with the patched compilers." |
| 175 | +./install.sh --package mpich --yes-to-all \ |
| 176 | + --with-fortran "${patched_GCC_install_path}/bin/gfortran" \ |
| 177 | + --with-c "${patched_GCC_install_path}/bin/gcc" \ |
| 178 | + --with-cxx "${patched_GCC_install_path}/bin/g++" |
| 179 | + |
| 180 | +# Verify that MPICH installed where expected |
| 181 | +mpich_install_path=$(./install.sh -P mpich) |
| 182 | +if ! type "${mpich_install_path}"/bin/mpif90; then |
| 183 | + echo "MPICH is not installed in the expected location ${mpich_install_path}." |
| 184 | + exit 1 |
| 185 | +fi |
| 186 | + |
| 187 | +# Build OpenCoarrays with the patched compilers and the just-built MPICH |
| 188 | +echo "Building OpenCoarrays with the patched compilers" |
| 189 | +# Build OpenCoarrays with the patched compiler: |
| 190 | +./install.sh --yes-to-all \ |
| 191 | + --with-fortran "${patched_GCC_install_path}/bin/gfortran" \ |
| 192 | + --with-c "${patched_GCC_install_path}/bin/gcc" \ |
| 193 | + --with-cxx "${patched_GCC_install_path}/bin/g++" \ |
| 194 | + --with-mpi "${mpich_install_path}" |
0 commit comments