Skip to content

Commit 9559099

Browse files
authored
Merge branch 'master' into comment-caf-token
2 parents 679f822 + a04f099 commit 9559099

File tree

2 files changed

+314
-0
lines changed

2 files changed

+314
-0
lines changed

windows-install.sh

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
#/usr/bin/env bash
2+
#
3+
# windows-install.sh
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-2016, Sourcery, Inc.
9+
# Copyright (c) 2015-2016, 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+
# Portions of this script derive from BASH3 Boilerplate and are distributed under
36+
# the following license:
37+
#
38+
# The MIT License (MIT)
39+
#
40+
# Copyright (c) 2014 Kevin van Zonneveld
41+
#
42+
# Permission is hereby granted, free of charge, to any person obtaining a copy
43+
# of this software and associated documentation files (the "Software"), to deal
44+
# in the Software without restriction, including without limitation the rights
45+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46+
# copies of the Software, and to permit persons to whom the Software is
47+
# furnished to do so, subject to the following conditions:
48+
#
49+
# The above copyright notice and this permission notice shall be included in all
50+
# copies or substantial portions of the Software.
51+
#
52+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
58+
# SOFTWARE.
59+
#
60+
#
61+
# - https://github.com/kvz/bash3boilerplate
62+
# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/
63+
#
64+
# Version: 2.0.0
65+
#
66+
# Authors:
67+
#
68+
# - Kevin van Zonneveld (http://kvz.io)
69+
# - Izaak Beekman (https://izaakbeekman.com/)
70+
# - Alexander Rathai ([email protected])
71+
# - Dr. Damian Rouson (http://www.sourceryinstitute.org/) (documentation)
72+
#
73+
# Licensed under MIT
74+
# Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)
75+
76+
# The invocation of bootstrap.sh below performs the following tasks:
77+
# (1) Import several bash3boilerplate helper functions & default settings.
78+
# (2) Set several variables describing the current file and its usage page.
79+
# (3) Parse the usage information (default usage file name: current file's name with -usage appended).
80+
# (4) Parse the command line using the usage information.
81+
82+
### Start of boilerplate -- do not edit this block #######################
83+
export OPENCOARRAYS_SRC_DIR="${OPENCOARRAYS_SRC_DIR:-${PWD%/}}"
84+
if [[ ! -f "${OPENCOARRAYS_SRC_DIR}/src/libcaf.h" ]]; then
85+
echo "Please run this script inside the top-level OpenCoarrays source directory or "
86+
echo "set OPENCOARRAYS_SRC_DIR to the OpenCoarrays source directory path."
87+
exit 1
88+
fi
89+
export B3B_USE_CASE="${B3B_USE_CASE:-${OPENCOARRAYS_SRC_DIR}/prerequisites/use-case}"
90+
if [[ ! -f "${B3B_USE_CASE:-}/bootstrap.sh" ]]; then
91+
echo "Please set B3B_USE_CASE to the bash3boilerplate use-case directory path."
92+
exit 2
93+
else
94+
# shellcheck source=./prerequisites/use-case/bootstrap.sh
95+
source "${B3B_USE_CASE}/bootstrap.sh" "$@"
96+
fi
97+
### End of boilerplate -- start user edits below #########################
98+
99+
# Set expected value of present flags that take no arguments
100+
export __flag_present=1
101+
102+
# Set up a function to call when receiving an EXIT signal to do some cleanup. Remove if
103+
# not needed. Other signals can be trapped too, like SIGINT and SIGTERM.
104+
function cleanup_before_exit () {
105+
info "Cleaning up. Done"
106+
}
107+
trap cleanup_before_exit EXIT # The signal is specified here. Could be SIGINT, SIGTERM etc.
108+
109+
### Validation (decide what's required for running your script and error out)
110+
#####################################################################
111+
112+
[ -z "${LOG_LEVEL:-}" ] && emergency "Cannot continue without LOG_LEVEL. "
113+
114+
# shellcheck disable=SC2154
115+
if [[ "${arg_d}" == "${__flag_present}" ]]; then
116+
print_debug_only=7
117+
if [ "$(( LOG_LEVEL < print_debug_only ))" -ne 0 ]; then
118+
debug "Supressing info and debug messages: one of {-l, -v, -P, -U, -V, -D} present."
119+
suppress_info_debug_messages
120+
fi
121+
fi
122+
123+
# Get linux_distribution name
124+
{
125+
info "__file: ${__file}"
126+
info "__dir: ${__dir}"
127+
info "__base: ${__base}"
128+
info "__os: ${__os}"
129+
info "__usage: ${__usage}"
130+
info "LOG_LEVEL: ${LOG_LEVEL}"
131+
132+
info "-c (--with-c): [arg] ${arg_c}"
133+
info "-C (--with-cxx): [arg] ${arg_C}"
134+
info "-d (--debug): ${arg_d}"
135+
info "-e (--verbose): ${arg_e}"
136+
info "-f (--with-fortran): ${arg_e}"
137+
info "-i (--install-prefix): ${arg_i}"
138+
info "-j (--num-threads): ${arg_j}"
139+
info "-m (--with-cmake): [arg] ${arg_m}"
140+
info "-n (--no-color): ${arg_n}"
141+
info "-v (--version): ${arg_v}"
142+
info "-V (--version-number): ${arg_V}"
143+
}
144+
145+
# __________ Process command-line arguments and environment variables _____________
146+
147+
export this_script="$(basename "$0")"
148+
debug "this_script=\"${this_script}\""
149+
150+
export install_prefix="${arg_i%/:-${PWD}/prerequisites/installations}"
151+
info "install_prefix=\"${install_prefix}\""
152+
153+
export num_threads="${arg_j}"
154+
info "num_threads=\"${arg_j}\""
155+
156+
set_opencoarrays_version()
157+
{
158+
cmake_project_line="$(grep project "${OPENCOARRAYS_SRC_DIR}/CMakeLists.txt" | grep VERSION)"
159+
text_after_version_keyword="${cmake_project_line##*VERSION}"
160+
text_before_language_keyword="${text_after_version_keyword%%LANGUAGES*}"
161+
opencoarrays_version=$text_before_language_keyword
162+
export opencoarrays_version="${opencoarrays_version//[[:space:]]/}"
163+
}
164+
set_opencoarrays_version
165+
166+
export build_path="${OPENCOARRAYS_SRC_DIR%/}"/prerequisites/builds/opencoarrays/$opencoarrays_version
167+
info "build_path=\"${build_path}\""
168+
169+
export CMAKE="${arg_m:-cmake}"
170+
171+
verify_this_is_ubuntu()
172+
{
173+
if [[ ${__os} != "Linux" ]]; then
174+
emergency "${__os} not supported: this script is intended for use in Windows Subsystem for Linux "
175+
fi
176+
linux_standard_base_i=`lsb_release -i`
177+
untrimmed_name=${linux_standard_base_i##*Distributor ID:}
178+
linux_distribution="${untrimmed_name//[[:space:]]/}"
179+
info "Linux distribution: ${linux_distribution}"
180+
if [[ "${linux_distribution:-}" != "Ubuntu" ]]; then
181+
info "Please run this script inside the Windows Subsystem for Linux (WSL) Ubuntu 16.04 or later,"
182+
info "which might require joining the Windows Insider Preview program and selecting 'Fast' updates."
183+
emergency "Error: see above."
184+
fi
185+
}
186+
verify_this_is_ubuntu
187+
188+
# Ubuntu 16.04 apt-get installs gfortran 5.4.0 or later, which is acceptable for many uses of OpenCoarrays
189+
verify_acceptable_release_number()
190+
{
191+
linux_standard_base_r=`lsb_release -r`
192+
untrimmed_name=${linux_standard_base_r##*Release:}
193+
release_number="${untrimmed_name//[[:space:]]/}"
194+
major_release="${release_number%%.*}"
195+
minor_release="${release_number##*.}"
196+
info "Release: ${major_release}.${minor_release}"
197+
if [[ $major_release -lt 16 ]]; then
198+
emergency "Please upgrade to Windows Subsystem for Linux (WSL) Ubuntu 16.04 or later."
199+
elif [[ $major_release -eq 16 ]]; then
200+
if [[ $minor_release -lt "04" ]]; then
201+
emergency "Please upgrade to Windows Subsystem for Linux (WSL) Ubuntu 16.04 or later."
202+
fi
203+
fi
204+
}
205+
verify_acceptable_release_number
206+
207+
if [[ "${arg_V}" == "${__flag_present}" ]]; then
208+
# Print just the version number
209+
info "$opencoarrays_version"
210+
211+
elif [[ "${arg_v}" == "${__flag_present}" ]]; then
212+
213+
# Print copyright info and version number
214+
info "OpenCoarrays ${opencoarrays_version}"
215+
info ""
216+
info "OpenCoarrays installer"
217+
info "Copyright (C) 2015-2017 Sourcery, Inc."
218+
echo "Copyright (C) 2015-2017 Sourcery Institute"
219+
info ""
220+
info "OpenCoarrays comes with NO WARRANTY, to the extent permitted by law."
221+
info "You may redistribute copies of ${this_script} under the terms of the"
222+
echo "BSD 3-Clause License. For more information about these matters, see"
223+
info "http://www.sourceryinstitute.org/license.html"
224+
info ""
225+
else
226+
227+
export FC=${arg_f:-gfortran}
228+
export CC=${arg_c:-gcc}
229+
export CXX=${arg_C:-g++}
230+
231+
# Check for and, if necessary, install OpenCoarrays prerequisites
232+
233+
if ! type "$CMAKE" >& /dev/null; then
234+
sudo apt-get install cmake
235+
fi
236+
if ! type "$CXX" >& /dev/null; then
237+
sudo apt-get install g++
238+
fi
239+
if ! type "$FC" >& /dev/null; then
240+
sudo apt-get install gfortran
241+
fi
242+
243+
if ! type mpif90 >& /dev/null; then
244+
sudo apt-get install mpich
245+
fi
246+
247+
set_SUDO_if_needed_to_write_to_install_dir()
248+
{
249+
info "Checking whether the directory ${install_prefix} exists... "
250+
if [[ -d "${install_prefix}" ]]; then
251+
info "yes"
252+
info "Checking whether I have write permissions to ${install_prefix} ... "
253+
if [[ -w "${install_prefix}" ]]; then
254+
info "yes"
255+
else
256+
info "no"
257+
SUDO="sudo"
258+
fi
259+
else
260+
info "no"
261+
info "Checking whether I can create ${install_prefix} ... "
262+
if mkdir -p "${install_prefix}" >& /dev/null; then
263+
info "yes."
264+
else
265+
info "no."
266+
SUDO="sudo"
267+
fi
268+
fi
269+
}
270+
set_SUDO_if_needed_to_write_to_install_dir
271+
272+
# Install OpenCoarrays
273+
274+
if [[ -d "$build_path" ]]; then
275+
rm -rf "$build_path"
276+
fi
277+
mkdir -p "$build_path"
278+
cd "$build_path"
279+
info "Configuring OpenCoarrays with the following command:"
280+
info "FC=\"$FC\" CC=\"$CC\" \"$CMAKE\" \"$OPENCOARRAYS_SRC_DIR\" -DCMAKE_INSTALL_PREFIX=\"$install_prefix\""
281+
FC="$FC" CC="$CC" "$CMAKE" "$OPENCOARRAYS_SRC_DIR" -DCMAKE_INSTALL_PREFIX="$install_prefix"
282+
info "Building OpenCoarrays with the following command:"
283+
info "make -j $arg_j"
284+
make -j $arg_j
285+
info "Installing OpenCoarrays with the following command:"
286+
info "${SUDO:-} make install"
287+
${SUDO:-} make install
288+
if [[ -f "$install_prefix"/lib/libcaf_mpi.a && -f "${install_prefix}/bin/caf" && -f "${install_prefix}/bin/cafrun" ]]; then
289+
info "OpenCoarrays has been installed in"
290+
info "$install_prefix"
291+
else
292+
info "Something went wrong. OpenCoarrays is not in the expected location:"
293+
emergency "$install_prefix"
294+
fi
295+
# See http://stackoverflow.com/questions/31057694/gethostbyname-fail-after-switching-internet-connections/31222970
296+
loopback_line=`grep $NAME /etc/hosts`
297+
if [[ -z "${loopback_line:-}" ]]; then
298+
info "To ensure the correct functioning of MPI, please add the following line to your /etc/hosts file:"
299+
info "127.0.0.1 $NAME"
300+
fi
301+
fi

windows-install.sh-usage

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-c --with-c [arg] Use specified C compiler. Default="gcc"
2+
-C --with-cxx [arg] Use specified C++ compiler. Default="g++"
3+
-d --debug Enable debug mode.
4+
-e --verbose Enable verbose mode, print script as it is executed.
5+
-f --with-fortran [arg] Use specified Fortran compiler. Default="gfortran"
6+
-h --help Print this page.
7+
-i --install-prefix [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/opencoarrays/${version_to_build:-}"
8+
-j --num-threads [arg] Number of threads to use when invoking make. Default="1"
9+
-m --with-cmake [arg] Use specified CMake installation. Default="cmake"
10+
-n --no-color Disable color output.
11+
-v --version Print OpenCoarrays version number and copyright.
12+
-V --version-number Print OpenCoarrays version number.
13+
-y --yes-to-all Build non-interactively by assuming affirmative user responses.

0 commit comments

Comments
 (0)