Skip to content

Commit b54f3d3

Browse files
author
Damian Rouson
committed
Generalize patched-trunk-install for multi-OS/dist
1 parent e9daaac commit b54f3d3

File tree

1 file changed

+138
-26
lines changed

1 file changed

+138
-26
lines changed
Lines changed: 138 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,160 @@
11
#!/usr/bin/env bash
22

3-
if [[ ! -f src/libcaf.h ]]; then
4-
echo "Run this script at the top level of the OpenCoarrays source tree."
5-
exit 1
6-
fi
3+
### Diagnostics ###
74

8-
: "${1?'Missing absolute path to patch file'}"
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 <absolute-path>/patch-file.diff"
12+
exit 1
13+
}
14+
[[ $# -eq 0 || "${1}" == "-h" || "${1}" == "--help" || ! -f src/libcaf.h ]] && usage
915

10-
# Absolute path to patch file
1116
patch_file="${1}"
1217

13-
# Exit on error:
18+
# Exit on error or use of an unset variable:
1419
set -o errexit
15-
16-
# Exit on use of unset variable:
1720
set -o nounset
1821

1922
# Return the highest exit code in a chain of pipes:
2023
set -o pipefail
2124

22-
# Install the GCC trunk to default location: prerequisites/installations/gcc/trunk (takes several hours):
23-
./install.sh --package gcc --install-branch trunk --yes-to-all
25+
### Define functions
26+
function choose_package_manager()
27+
{
28+
OS=$(uname)
29+
case "${OS}" in
30+
31+
"Darwin" )
32+
if type port >& /dev/null; then
33+
package_manager="port"
34+
elif type brew >& /dev/null; then
35+
package_manager="brew"
36+
fi
37+
;;
38+
39+
"Linux" )
40+
if [[ ! -f /etc/lsb-release ]]; then
41+
echo "I don't recognize this Linux distribution. Possibly it's too old to have the expected /etc/lsb-release file."
42+
exit 1
43+
fi
44+
. /etc/lsb-release
45+
46+
case "${DISTRIB_ID:-}" in
47+
"Ubuntu" )
48+
package_manager="apt-get"
49+
;;
50+
"Debian" )
51+
package_manager="dnf"
52+
;;
53+
*)
54+
echo "I don't recognize the Linux distribution ${DISTRIB_ID:-}"
55+
exit 1
56+
;;
57+
esac
58+
;;
59+
60+
*)
61+
echo "I don't recognize the operating system \${OS}"
62+
exit 1
63+
;;
64+
esac
65+
}
66+
choose_package_manager
67+
68+
### Install any missing prerequisite packages and executable programs ###
69+
70+
### First install the packages for which package management suffices:
71+
function install_if_missing()
72+
{
73+
# Exit with error message if no first argument:
74+
: "${1?'\n ERROR: install_if_missing function requires a package name as the first argument.'}"
75+
76+
package="${1}" # Interpret the 1st argument as the package name
77+
executable="${2:-${1}}" # Interpret the 2nd argument as the prerequisite executable program (Default = 1st argument)
78+
79+
printf "Checking whether ${executable} is in path... "
80+
81+
if type ${executable} >& /dev/null; then
82+
83+
printf "yes.\n"
84+
85+
else # install package
2486

25-
# Patch the GCC trunk and rebuild (should be much faster than the initial build):
87+
printf "no\n"
88+
echo "sudo ${package_manager} install ${package}"
89+
sudo "${package_manager}" install ${package}
90+
91+
fi
92+
}
93+
94+
# Install subversion to check out the GCC trunk if not already in the PATH:
95+
install_if_missing subversion svn
96+
97+
# Install released versions of the GNU compilers if not already in the PATH:
98+
install_if_missing gfortran
99+
install_if_missing g++
100+
101+
# Install build software:
102+
install_if_missing cmake
103+
install_if_missing make
104+
install_if_missing flex
105+
106+
### Install the prerequisites that must be built from source ###
107+
108+
# Download and build the GCC trunk:
109+
./install.sh --package gcc --install-branch trunk --yes-to-all
110+
111+
# Patch the GCC trunk and rebuild
26112
echo "Patching the GCC source."
27-
pushd prerequistes/downloads/trunk
113+
pushd prerequisites/downloads/trunk
28114
patch -p0 < "${patch_file}"
29115
popd
30116

117+
# Build the patched GCC trunk
31118
echo "Rebuilding the patched GCC source."
32119
./install.sh --package gcc --install-branch trunk --yes-to-all
33120

34-
# Ensure the just-installed libraries are used when compiling
35-
export LD_LIBRARY_PATH="${PWD}/prerequisites/installations/gcc/trunk/lib64":"${LD_LIBRARY_PATH}"
121+
# Verify that GCC installed in the expected path
122+
patched_GCC_install_path=${PWD}/prerequisites/installations/gcc/trunk
123+
if ! type "${patched_GCC_install_path}"/bin/gfortran >& /dev/null; then
124+
echo "gfortran is not installed in the expected location ${patched_GCC_install_path}."
125+
exit 1
126+
fi
127+
128+
# Ensure that the just-installed GCC libraries are used when linking
129+
echo "Setting and exporting LD_LIBRARY_PATH"
130+
if [[ -d "${PWD}/prerequisites/installations/gcc/trunk/lib64" ]]; then
131+
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
132+
export LD_LIBRARY_PATH="${patched_GCC_install_path}/lib64/"
133+
else
134+
export LD_LIBRARY_PATH="${patched_GCC_install_path}/lib64/:${LD_LIBRARY_PATH}"
135+
fi
136+
fi
137+
echo "\${LD_LIBRARY_PATH}=${LD_LIBRARY_PATH:-}"
36138

37-
# Build MPICH with the patched compiler and install MPICH in the default location: prerequisites/installations/mpich/3.1.4:
139+
# Build MPICH with the patched compilers.
140+
echo "Building MPICH with the patched compilers."
38141
./install.sh --package mpich --yes-to-all \
39-
--with-fortran "${PWD}/prerequisites/installations/gcc/trunk/bin/gfortran" \
40-
--with-c "${PWD}/prerequisites/installations/gcc/trunk/bin/gcc" \
41-
--with-C "${PWD}/prerequisites/installations/gcc/trunk/bin/g++"
42-
43-
# Build OpenCoarrays with the patched compiler and install OpenCoarrays in the default location: prerequisites/installations:
44-
./install.sh ---yes-to-all \
45-
--with-fortran "${PWD}/prerequisites/installations/gcc/trunk/bin/gfortran" \
46-
--with-c "${PWD}/prerequisites/installations/gcc/trunk/bin/gcc" \
47-
--with-C "${PWD}/prerequisites/installations/gcc/trunk/bin/g++"
48-
--with-mpi "${PWD}/prerequisites/installations/mpich/3.1.4/"
142+
--with-fortran "${patched_GCC_install_path}/bin/gfortran" \
143+
--with-c "${patched_GCC_install_path}/bin/gcc" \
144+
--with-C "${patched_GCC_install_path}/bin/g++"
145+
146+
# Verify that MPICH installed where expected
147+
mpich_install_path=$(./install.sh -P mpich)
148+
if type ! "${mpich_install_path}"/bin/mpif90; then
149+
echo "MPICH is not installed in the expected location ${mpich_install_path}."
150+
exit 1
151+
fi
152+
153+
# Build OpenCoarrays with the patched compilers and the just-built MPICH
154+
echo "Building OpenCoarrays with the patched compilers"
155+
# Build OpenCoarrays with the patched compiler:
156+
./install.sh --yes-to-all \
157+
--with-fortran "${patched_GCC_install_path}/bin/gfortran" \
158+
--with-c "${patched_GCC_install_path}/bin/gcc" \
159+
--with-C "${patched_GCC_install_path}/bin/g++"
160+
--with-mpi "${mpich_install_path}"

0 commit comments

Comments
 (0)