Skip to content

Commit ace106f

Browse files
author
Damian Rouson
committed
Improved build/install directory management.
1 parent 0fd6fca commit ace106f

File tree

9 files changed

+103
-53
lines changed

9 files changed

+103
-53
lines changed

install.sh

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
# (4) Parse the command line using the usage information.
8181

8282
### Start of boilerplate -- do not edit this block #######################
83-
export OPENCOARRAYS_SRC_DIR="${OPENCOARRAYS_SRC_DIR:-${PWD}}"
83+
export OPENCOARRAYS_SRC_DIR="${OPENCOARRAYS_SRC_DIR:-${PWD%/}}"
8484
if [[ ! -f "${OPENCOARRAYS_SRC_DIR}/src/libcaf.h" ]]; then
8585
echo "Please run this script inside the top-level OpenCoarrays source directory or "
8686
echo "set OPENCOARRAYS_SRC_DIR to the OpenCoarrays source directory path."
@@ -149,12 +149,12 @@ info "-D (--print-downloader): ${arg_D}"
149149
info "-e (--verbose): ${arg_e}"
150150
info "-f (--with-fortran): ${arg_f}"
151151
info "-h (--help): ${arg_h}"
152-
info "-i (--install-dir): ${arg_i}"
152+
info "-i (--install-prefix): ${arg_i}"
153153
info "-I (--install-version): ${arg_I}"
154154
info "-j (--num-threads): ${arg_j}"
155155
info "-l (--list-packages): ${arg_l}"
156156
info "-m (--with-cmake): ${arg_m}"
157-
info "-M (--with-mpi): ${arg_M}"
157+
info "-M (--MPI-path): ${arg_M}"
158158
info "-n (--no-color): ${arg_n}"
159159
info "-p (--package): ${arg_p}"
160160
info "-P (--print-path): ${arg_P}"
@@ -188,21 +188,20 @@ info "-V (--print-version): ${arg_V}"
188188
this_script="$(basename "$0")"
189189
export this_script
190190

191-
export install_path="${arg_i}"
192-
info "install_path=${arg_i}"
191+
export install_path="${arg_i%/}"
192+
info "install_path=\"${install_path}\""
193193

194194
export num_threads="${arg_j}"
195-
info "num_threads=${arg_j}"
195+
info "num_threads=\"${arg_j}\""
196196

197197
export opencoarrays_src_dir="${OPENCOARRAYS_SRC_DIR}"
198198
info "opencoarrays_src_dir=${OPENCOARRAYS_SRC_DIR}"
199199

200-
export build_path=$opencoarrays_src_dir/prerequisites/builds
201-
info "build_path=$opencoarrays_src_dir/prerequisites/builds"
202-
203-
export build_script=$opencoarrays_src_dir/prerequisites/build.sh
204-
info "build_script=$opencoarrays_src_dir/prerequisites/build.sh"
200+
export build_path="${opencoarrays_src_dir}"/prerequisites/builds
201+
info "build_path=\"${opencoarrays_src_dir}\"/prerequisites/builds"
205202

203+
export build_script="${opencoarrays_src_dir}"/prerequisites/build.sh
204+
info "build_script=\"${opencoarrays_src_dir}\"/prerequisites/build.sh"
206205

207206
# ___________________ Define functions for use in the Main Body ___________________
208207

@@ -214,12 +213,16 @@ stack_new dependency_pkg
214213
stack_new dependency_exe
215214
stack_new dependency_path
216215
stack_new script_installed
216+
217217
# shellcheck source=./prerequisites/install-functions/find_or_install.sh
218218
source $opencoarrays_src_dir/prerequisites/install-functions/find_or_install.sh
219+
219220
# shellcheck source=./prerequisites/install-functions/print_header.sh
220221
source $opencoarrays_src_dir/prerequisites/install-functions/print_header.sh
222+
221223
# shellcheck source=./prerequisites/install-functions/build_opencoarrays.sh
222224
source $opencoarrays_src_dir/prerequisites/install-functions/build_opencoarrays.sh
225+
223226
# shellcheck source=./prerequisites/install-functions/report_results.sh
224227
source $opencoarrays_src_dir/prerequisites/install-functions/report_results.sh
225228

@@ -232,7 +235,7 @@ source $opencoarrays_src_dir/prerequisites/install-functions/report_results.sh
232235
if [[ "${arg_v}" == "${__flag_present}" || "${arg_V}" == "opencoarrays" ]]; then
233236

234237
# Print script copyright if invoked with -v, -V, or --version argument
235-
cmake_project_line=$(grep project CMakeLists.txt | grep VERSION)
238+
cmake_project_line=$(grep project ${opencoarrays_src_dir}/CMakeLists.txt | grep VERSION)
236239
text_after_version_keyword="${cmake_project_line##*VERSION}"
237240
text_before_language_keyword="${text_after_version_keyword%%LANGUAGES*}"
238241
opencoarrays_version=$text_before_language_keyword
@@ -249,7 +252,7 @@ if [[ "${arg_v}" == "${__flag_present}" || "${arg_V}" == "opencoarrays" ]]; then
249252
echo "http://www.sourceryinstitute.org/license.html"
250253
echo ""
251254
elif [[ "${arg_V}" == "opencoarrays" ]]; then
252-
echo "${opencoarrays_version}"
255+
echo "${opencoarrays_version//[[:space:]]/}"
253256
fi
254257

255258
elif [[ ! -z "${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}" || "${arg_l}" == "${__flag_present}" ]]; then
@@ -261,29 +264,48 @@ elif [[ ! -z "${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}" || "${arg_l}" == "${__fla
261264
[ ! -z "${arg_U}" ] && build_flag="-U"
262265
[ ! -z "${arg_V}" ] && build_flag="-V"
263266
[ "${arg_l}" == "${__flag_present}" ] && build_flag="-l"
264-
"${opencoarrays_src_dir}"/prerequisites/build.sh "${build_flag}" "${build_arg}"
265-
# Add lines other packages the current script builds
266-
if [[ "${arg_l}" == "${__flag_present}" ]]; then
267-
echo "opencoarrays (version $("${opencoarrays_src_dir}/install.sh" -V opencoarrays))"
268-
echo "ofp (version: ofp-sdf for OS X )"
267+
268+
if [[ "${arg_P}" == "opencoarrays" ]]; then
269+
270+
version="$("${opencoarrays_src_dir}/install.sh" -V opencoarrays)"
271+
echo "${install_path%/}/opencoarrays/${version}"
272+
273+
else
274+
275+
info "Invoking build script with the following command:"
276+
info "\"${opencoarrays_src_dir}\"/prerequisites/build.sh \"${build_flag}\" \"${build_arg}\""
277+
"${opencoarrays_src_dir}"/prerequisites/build.sh "${build_flag}" "${build_arg}"
278+
279+
# Add lines other packages the current script builds
280+
if [[ "${arg_l}" == "${__flag_present}" ]]; then
281+
echo "opencoarrays (version $("${opencoarrays_src_dir}/install.sh" -V opencoarrays))"
282+
echo "ofp (version: ofp-sdf for OS X )"
283+
fi
269284
fi
270285

271286
elif [[ "${arg_p:-}" == "opencoarrays" ]]; then
272287

288+
273289
cd prerequisites || exit 1
274290
installation_record=install-opencoarrays.log
275291
# shellcheck source=./prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh
276292
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh"
293+
version="$("${opencoarrays_src_dir}/install.sh" -V opencoarrays)"
294+
install_path="${install_path}/opencoarrays/${version}"
277295
set_SUDO_if_needed_to_write_to_directory "${install_path}"
278296
build_opencoarrays 2>&1 | tee ../"${installation_record}"
279297
report_results 2>&1 | tee -a ../"${installation_record}"
280298

281299
elif [[ "${arg_p:-}" == "ofp" ]]; then
282300

301+
info "Invoking Open Fortran Parser build script with the following command:"
302+
info "\"${opencoarrays_src_dir}\"/prerequisites/install-ofp.sh"
283303
"${opencoarrays_src_dir}"/prerequisites/install-ofp.sh
284304

285305
elif [[ ! -z "${arg_p:-}" ]]; then
286306

307+
info "Invoking build script with the following command:"
308+
info "\"${opencoarrays_src_dir}\"/prerequisites/build.sh ${@:-}"
287309
"${opencoarrays_src_dir}"/prerequisites/build.sh ${@:-}
288310

289311
fi

install.sh-usage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
-e --verbose Enable verbose mode, print script as it is executed.
66
-f --with-fortran [arg] Use specified Fortran compiler.
77
-h --help Print this page.
8-
-i --install-dir [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/"
8+
-i --install-prefix [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/"
99
-I --install-version [arg] Install package version.
1010
-j --num-threads [arg] Number of threads to use when invoking make. Default="1"
1111
-l --list-packages Print packages this script can install.
1212
-m --with-cmake [arg] Use specified CMake installation. Default="cmake"
13-
-M --with-mpi [arg] Use specified MPI installation. Default="mpif90"
13+
-M --MPI-path [arg] Use specified MPI installation.
1414
-n --no-color Disable color output.
1515
-p --package [arg] Install specified package. Default="opencoarrays"
1616
-P --print-path [arg] Print installation directory for specified package.

prerequisites/build-functions/build_and_install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build_and_install()
77

88
info "Building ${package_to_build} ${version_to_build}"
99
info "Build path: ${build_path}"
10+
info "Installation path: ${install_path}"
1011

1112
set_SUDO_if_needed_to_write_to_directory "${build_path}"
1213
set_SUDO_if_needed_to_write_to_directory "${install_path}"

prerequisites/build-functions/set_or_print_installation_path.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
set_or_print_installation_path()
55
{
66
# Verify requirements
7-
[ ! -z "${arg_P}" ] && [ ! -z "${arg_D:-${arg_p:-${arg_U:-${arg_V}}}}" ] &&
7+
[ ! -z "${arg_P}" ] && [ ! -z "${arg_p:-${arg_D:-${arg_U:-${arg_V}}}}" ] &&
88
emergency "Please pass only one of {-D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
99

10-
install_path="${arg_i}/${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}}/${version_to_build}"
10+
install_path="${arg_i%/}/${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}}/${version_to_build}"
1111

1212
# If -P is present, print ${install_path} and exit with normal status
1313
if [[ ! -z "${arg_P:-}" ]]; then

prerequisites/build-functions/set_or_print_url.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ set_or_print_url()
5858
"flex;flex-${version_to_build}.tar.bz2"
5959
"bison;bison-${version_to_build}.tar.gz"
6060
"make;make-${version_to_build}.tar.bz2"
61-
"cmake;cmake-${version_to_build}.tar.gz "
61+
"cmake;cmake-${version_to_build}.tar.gz"
6262
"subversion;subversion-${version_to_build}.tar.gz"
6363
)
6464
for package in "${package_url_tail[@]}" ; do

prerequisites/build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# (4) Parse the command line using the usage information.
3232

3333

34-
export OPENCOARRAYS_SRC_DIR="${OPENCOARRAYS_SRC_DIR:-${PWD}/..}"
34+
export OPENCOARRAYS_SRC_DIR="${OPENCOARRAYS_SRC_DIR:-${PWD%prerequisites*}}"
3535
export __usage=${OPENCOARRAYS_SRC_DIR}/prerequisites/build.sh-usage
3636
if [[ ! -f "${OPENCOARRAYS_SRC_DIR}/src/libcaf.h" ]]; then
3737
echo "Please run this script inside the OpenCoarrays source \"prerequisites\" subdirectory"
@@ -97,7 +97,7 @@ info "-D (--print-downloader): ${arg_D} "
9797
info "-e (--verbose): ${arg_e} "
9898
info "-f (--with-fortran): ${arg_f} "
9999
info "-h (--help): ${arg_h} "
100-
info "-i (--install-dir): ${arg_i} "
100+
info "-i (--install-prefix): ${arg_i} "
101101
info "-j (--num-threads): ${arg_j} "
102102
info "-I (--install-version): ${arg_I} "
103103
info "-l (--list-packages): ${arg_l} "
@@ -112,6 +112,7 @@ info "-U (--print-url): ${arg_U} "
112112
info "-v (--version): ${arg_v} "
113113
info "-V (--print-version): ${arg_V} "
114114
}
115+
115116
# shellcheck source=./build-functions/set_or_print_default_version.sh
116117
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_or_print_default_version.sh"
117118
set_or_print_default_version "${@}"

prerequisites/build.sh-usage

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
-e --verbose Enable verbose mode, print script as it is executed.
77
-f --with-fortran [arg] Specify Fortran compiler location. Default="gfortran"
88
-h --help This page.
9-
-i --install-dir [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/"
9+
-i --install-prefix [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR%/}/prerequisites/installations/"
1010
-j --num-threads [arg] Number of threads to use when invoking make. Default="1"
1111
-I --install-version [arg] Package version to install. (To see default, use -V or --print-version)
1212
-l --list-packages List the packages this script can install.
1313
-L --list-branches List the repository branches this script can download.
14-
-m --with-cmake [arg] Specify CMake location. Default="'`which cmake`'"
15-
-M --with-mpi [arg] Specify MPI location. Default="'`which mpif90`'"
14+
-m --with-cmake [arg] Use the specified CMake installation. Default="cmake"
15+
-M --MPI-path [arg] Use the specified MPI installation.
1616
-n --no-color Disable color output.
1717
-p --package [arg] Package to install.
1818
-P --print-path [arg] Print installation path for package specified in argument.
19-
-t --with-tau [arg] Use the specified TAU parallel performance utilities installation. Default="'`which tauf90`'"
19+
-t --with-tau [arg] Use the specified TAU parallel performance utilities installation. Default="tauf90"
2020
-T --install-tau [arg] Install TAU in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/${version_to_build:-}/"
2121
-U --print-url [arg] Print URL for package specified in argument.
2222
-v --version Print OpenCoarrays version number.

prerequisites/install-functions/build_opencoarrays.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
build_opencoarrays()
33
{
44
print_header
5-
info "find_or_install mpich"
5+
info "Invoking find_or_install mpich"
66
find_or_install mpich
7-
info "find_or_install cmake"
7+
info "Invoking find_or_install cmake"
88
find_or_install cmake
9+
build_path="${build_path}"/opencoarrays/$("${opencoarrays_src_dir}"/install.sh -V opencoarrays)
910
mkdir -p "$build_path"
1011
pushd "$build_path"
1112
if [[ -z "${MPICC:-}" || -z "${MPIFC:-}" || -z "${CMAKE:-}" ]]; then

prerequisites/install-functions/find_or_install.sh

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ find_or_install()
3232
else
3333
printf "$this_script: Checking whether $package executable $executable is in the PATH..."
3434
fi
35-
if type "$executable" > /dev/null; then
35+
if type "$executable" >& /dev/null; then
3636
printf "yes.\n"
3737
package_in_path=true
3838
package_version_in_path=$("$executable" --version|head -1)
@@ -43,7 +43,7 @@ find_or_install()
4343

4444
package_install_path=$(./build.sh -P "$package")
4545

46-
printf "Checking whether $executable is in the prerequisites/instalations directory.."
46+
printf "Checking whether $executable is in $package_install_path..."
4747
if [[ -x "$package_install_path/bin/$executable" ]]; then
4848
printf "yes.\n"
4949
script_installed_package=true
@@ -111,27 +111,28 @@ find_or_install()
111111
# MPIFC, MPICC, and MPICXX environment variables. Every branch must also manage the
112112
# dependency stack.
113113

114-
if [[ ! -z "${arg_f}" ]]; then
115-
116-
# -f or --with-fortran argument specifies a compiler, which we use if mpif90
117-
# invokes the specified compiler. Otherwise, we halt and print an error message.
118-
119-
mpif90_wraps=$(mpif90 --version)
120-
compiler=$(${arg_f} --version)
121-
if [[ "${mpif90_wraps}" != "${compiler}" ]]; then
122-
emergency "The specified compiler ${arg_f} differs from the compiler that mpif90 invokes."
123-
else
124-
info "mpif90 invokes the specified compiler ${arg_f}"
125-
fi
126-
export MPIFC=mpif90
127-
export MPICC=mpicc
128-
export MPICXX=mpicxx
114+
# If the user specified a Fortran compiler, verify that mpif90 wraps the specified compiler
115+
if [[ ! -z "${arg_M:-}" ]]; then
129116

117+
echo -e "$this_script: Using the $package specified by -M or --MPI-path: ${arg_M}\n"
118+
export MPIFC="${arg_M}"/bin/mpif90
119+
export MPICC="${arg_M}"/bin/mpicc
120+
export MPICXX="${arg_M}"/bin/mpicxx
130121
# Halt the recursion
131122
stack_push dependency_pkg "none"
132123
stack_push dependency_exe "none"
133124
stack_push dependency_path "none"
134125

126+
if [[ ! -z "${arg_f:-}" ]]; then
127+
# -f or --with-fortran argument specifies a compiler, which we use if mpif90
128+
# invokes the specified compiler. Otherwise, we halt and print an error message.
129+
MPIFC_wraps=$(${MPIFC} --version)
130+
compiler=$(${arg_f} --version)
131+
if [[ "${MPIFC_wraps}" != "${compiler}" ]]; then
132+
emergency "Specified MPI ${MPIFC_wraps} wraps a compiler other than the specified Fortran compiler ${compiler}"
133+
fi
134+
fi
135+
135136
elif [[ "$script_installed_package" == true ]]; then
136137

137138
echo -e "$this_script: Using the $package installed by $this_script\n"
@@ -198,7 +199,26 @@ find_or_install()
198199
# Every branch that discovers an acceptable pre-existing installation must set the
199200
# FC, CC, and CXX environment variables. Every branch must also manage the dependency stack.
200201

201-
if [[ "$script_installed_package" == true ]]; then
202+
if [[ ! -z "${arg_f:-}" ]]; then
203+
204+
info "-f (or --with-fortran) argument detected with value ${arg_f}"
205+
[ -z "${arg_c:-}" ] && emergency "-f (--with-fortran) specifies Fortran compiler; Please also specify C/C++ compilers"
206+
[ -z "${arg_C:-}" ] && emergency "-f (--with-fortran) specifies Fortran compiler; Please also specify C/C++ compilers"
207+
208+
export FC="${arg_f}"
209+
export CC="${arg_c}"
210+
export CXX="${arg_C}"
211+
212+
# Remove $package from the dependency stack
213+
stack_pop dependency_pkg package_done
214+
stack_pop dependency_exe executable_done
215+
stack_pop dependency_path package_done_path
216+
# Halt the recursion and signal that none of $package's prerequisites need to be built
217+
stack_push dependency_pkg "none"
218+
stack_push dependency_exe "none"
219+
stack_push dependency_path "none"
220+
221+
elif [[ "$script_installed_package" == true ]]; then
202222
echo -e "$this_script: Using the $package executable $executable installed by $this_script\n"
203223
export FC=$package_install_path/bin/gfortran
204224
export CC=$package_install_path/bin/gcc
@@ -485,9 +505,9 @@ find_or_install()
485505
if [[ $package != "none" ]]; then
486506

487507
if [[ "$package" == "$executable" ]]; then
488-
echo "$this_script: Ready to build $executable in $package_install_path"
508+
echo "$this_script: Ready to install $executable in $package_install_path"
489509
else
490-
echo "$this_script: Ready to build $package executable $executable in $package_install_path"
510+
echo "$this_script: Ready to install $package executable $executable in $package_install_path"
491511
fi
492512

493513
echo -e "$this_script: Ok to download (if necessary), build, and install $package from source? (Y/n) "
@@ -534,9 +554,14 @@ find_or_install()
534554
FC=gfortran
535555
fi
536556

557+
558+
# Strip trailing package name and version number, if present, from installation path
559+
default_package_version=$(./build.sh -V ${package})
560+
package_install_prefix="${package_install_path%${package}/${arg_I:-${default_package_version}}*}"
561+
537562
echo -e "$this_script: Downloading, building, and installing $package \n"
538-
echo "$this_script: Build command: FC=$FC CC=$CC CXX=$CXX ./build.sh -p $package -i $package_install_path -j $num_threads"
539-
FC="$FC" CC="$CC" CXX="$CXX" ./build.sh -p "$package" -i "$package_install_path" -j "$num_threads"
563+
echo "$this_script: Build command: FC=$FC CC=$CC CXX=$CXX ./build.sh -p $package -i $package_install_prefix -j $num_threads"
564+
FC="$FC" CC="$CC" CXX="$CXX" ./build.sh -p "$package" -i "$package_install_prefix" -j "$num_threads"
540565

541566
if [[ -x "$package_install_path/bin/$executable" ]]; then
542567
echo -e "$this_script: Installation successful.\n"

0 commit comments

Comments
 (0)