Skip to content

Commit 2653844

Browse files
author
Damian Rouson
committed
Fix #591 by adding new -r/--prefix-root argument
Example: The command ./install.sh -r /opt installs OpenCoarrays and each missing prerequisite package in a path of the form /opt/<package-name>/<package-version>
1 parent f508448 commit 2653844

File tree

7 files changed

+99
-69
lines changed

7 files changed

+99
-69
lines changed

install.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ info "-n (--no-color): ${arg_n}"
164164
info "-o (--only-download): ${arg_o}"
165165
info "-p (--package): ${arg_p}"
166166
info "-P (--print-path): ${arg_P}"
167+
info "-r (--prefix-root): ${arg_r}"
167168
info "-u (--from-url): ${arg_u}"
168169
info "-U (--print-url): ${arg_U}"
169170
info "-v (--version): ${arg_v}"
@@ -197,8 +198,8 @@ info "-Z (--bootstrap): ${arg_Z}"
197198
this_script="$(basename "$0")"
198199
export this_script
199200

200-
export install_path="${arg_i%/}"
201-
info "install_path=\"${install_path}\""
201+
export install_path=${arg_i%/}
202+
export prefix_root="${arg_r:-}"
202203

203204
export num_threads="${arg_j}"
204205
info "num_threads=\"${arg_j}\""
@@ -316,7 +317,12 @@ elif [[ "${arg_p:-}" == "opencoarrays" ]]; then
316317
# shellcheck source=./prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh
317318
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh"
318319
version="$("${opencoarrays_src_dir}/install.sh" -V opencoarrays)"
319-
set_SUDO_if_needed_to_write_to_directory "${install_path}"
320+
321+
if [[ -z "${prefix_root:-}" ]]; then
322+
set_SUDO_if_needed_to_write_to_directory "${install_path}"
323+
else
324+
set_SUDO_if_needed_to_write_to_directory "${prefix_root}"
325+
fi
320326

321327
if grep -s -q Microsoft /proc/version ; then
322328
info "Windows Subsystem for Linux detected. Invoking windows-install.sh with the following command:"

install.sh-usage

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-e --verbose Enable verbose mode, print script as it is executed.
88
-f --with-fortran [arg] Use specified Fortran compiler (Example: -f /usr/local/bin/gfortran).
99
-h --help Print this page.
10-
-i --install-prefix [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/${version_to_build:-}"
10+
-i --install-prefix [arg] Install package in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/${version_to_build:-}"
1111
-I --install-version [arg] Install package version (Example: -I 7.2.0).
1212
-j --num-threads [arg] Number of threads to use when invoking make (Example: -j 8). Default="4"
1313
-l --list-packages Print packages this script can install.
@@ -17,6 +17,7 @@
1717
-o --only-download Download (without building) the source for the package specified by -p or --package.
1818
-p --package [arg] Install specified package (Examples: -p gcc or -p mpich). Default="opencoarrays"
1919
-P --print-path [arg] Print installation directory for specified package (Example: -P gcc).
20+
-r --prefix-root [arg] Installation path to which package name/version will be appended. (Example: -r /opt).
2021
-u --from-url [arg] Specify a URL to use for downloading a package (Example: -u https://github.com/sourceryinstitute/gcc/archive/teams-rc3.tar.gz).
2122
-U --print-url [arg] Print download location for specified package (Example: -U gcc).
2223
-v --version Print OpenCoarrays version number.

prerequisites/build-functions/set_or_print_installation_path.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ set_or_print_installation_path()
77
[ ! -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+
if [[ $arg_p == "opencoarrays" ]]; then
11+
export version_to_build=$(${OPENCOARRAYS_SRC_DIR}/install.sh -V opencoarrays)
12+
export package_name="opencoarrays"
13+
fi
1014
arg_i_default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/"
11-
if [[ "${arg_i:-}" == "${arg_i_default}" ]]; then
12-
install_path="${arg_i%/}/${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}}/${version_to_build}"
15+
if [[ "${arg_i%/}" == "${arg_i_default}" ]]; then
16+
if [[ -z "${arg_r}" ]]; then
17+
export install_path="${arg_i%/}/${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}}/${version_to_build}"
18+
else
19+
export install_path="${arg_r%/}/${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}}/${version_to_build}"
20+
fi
1321
else
22+
[ ! -z "${arg_r}" ] &&
23+
emergency "Please pass only one of {-i,-r} or a longer equivalent (multiple detected). [exit 105]"
1424
install_path="${arg_i%/}"
1525
fi
1626

prerequisites/build.sh-usage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
-o --only-download Download (without building) the package source specified by -p or --package.
1818
-p --package [arg] Package to install.
1919
-P --print-path [arg] Print installation path for package specified in argument.
20+
-r --prefix-root [arg] Installation path to which package name/version will be appended. (Example: -r /opt).
2021
-t --with-tau [arg] Use the specified TAU parallel performance utilities installation. Default="tauf90"
2122
-T --install-tau [arg] Install TAU in specified path. Default="${OPENCOARRAYS_SRC_DIR}/prerequisites/installations/${package_name:-}/${version_to_build:-}/"
2223
-u --from-url [arg] Specify a URL from which to download a package.

prerequisites/install-functions/build_opencoarrays.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ build_opencoarrays()
3939
else
4040
MPIEXEC="${MPIEXEC_CANDIDATES[0]}"
4141
fi
42+
43+
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_or_print_installation_path.sh"
44+
set_or_print_installation_path
45+
4246
info "Configuring OpenCoarrays in ${PWD} with the command:"
4347
info "CC=\"${CC}\" FC=\"${FC}\" $CMAKE \"${opencoarrays_src_dir}\" \"${WDEVFLAG}\" -DCMAKE_INSTALL_PREFIX=\"${install_path}\" -DMPIEXEC=\"${MPIEXEC}\" -DMPI_C_COMPILER=\"${MPICC}\" -DMPI_Fortran_COMPILER=\"${MPIFC}\""
4448
CC="${CC}" FC="${FC}" $CMAKE "${opencoarrays_src_dir}" "${WDEVFLAG}" -DCMAKE_INSTALL_PREFIX="${install_path}" -DMPIEXEC="${MPIEXEC}" -DMPI_C_COMPILER="${MPICC}" -DMPI_Fortran_COMPILER="${MPIFC}"

prerequisites/install-functions/find_or_install.sh

Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ find_or_install()
4141
package_in_path=false
4242
fi
4343

44-
package_install_path=$(./build.sh -P "$package")
44+
export default_package_install_path=$(./build.sh -P "$package")
4545

46-
printf "Checking whether %s is in %s..." "$executable" "$package_install_path"
47-
if [[ -x "$package_install_path/bin/$executable" ]]; then
46+
printf "Checking whether %s is in %s..." "$executable" "$default_package_install_path"
47+
if [[ -x "$default_package_install_path/bin/$executable" ]]; then
4848
printf "yes.\n"
4949
script_installed_package=true
5050
stack_push script_installed "$package" "$executable"
@@ -78,7 +78,7 @@ find_or_install()
7878

7979
elif [[ "$script_installed_package" == true ]]; then
8080
echo -e "$this_script: Using the $package installed by $this_script\n"
81-
export CMAKE=$package_install_path/bin/$executable
81+
export CMAKE=$default_package_install_path/bin/$executable
8282
stack_push dependency_pkg "none"
8383
stack_push dependency_exe "none"
8484
stack_push dependency_path "none"
@@ -136,9 +136,9 @@ find_or_install()
136136
elif [[ "$script_installed_package" == true ]]; then
137137

138138
echo -e "$this_script: Using the $package installed by $this_script\n"
139-
export MPIFC=$package_install_path/bin/mpifort
140-
export MPICC=$package_install_path/bin/mpicc
141-
export MPICXX=$package_install_path/bin/mpicxx
139+
export MPIFC=$default_package_install_path/bin/mpifort
140+
export MPICC=$default_package_install_path/bin/mpicc
141+
export MPICXX=$default_package_install_path/bin/mpicxx
142142
# Halt the recursion
143143
stack_push dependency_pkg "none"
144144
stack_push dependency_exe "none"
@@ -248,10 +248,10 @@ find_or_install()
248248

249249
elif [[ "$script_installed_package" == true ]]; then
250250
echo -e "$this_script: Using the $package executable $executable installed by $this_script\n"
251-
export FC=$package_install_path/bin/gfortran
252-
export CC=$package_install_path/bin/gcc
253-
export CXX=$package_install_path/bin/g++
254-
gfortran_lib_paths="$package_install_path/lib64/:$package_install_path/lib"
251+
export FC=$default_package_install_path/bin/gfortran
252+
export CC=$default_package_install_path/bin/gcc
253+
export CXX=$default_package_install_path/bin/g++
254+
gfortran_lib_paths="$default_package_install_path/lib64/:$default_package_install_path/lib"
255255
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
256256
echo "$this_script: export LD_LIBRARY_PATH=\"$gfortran_lib_paths\""
257257
export LD_LIBRARY_PATH="$gfortran_lib_paths"
@@ -327,7 +327,7 @@ find_or_install()
327327

328328
if [[ "$script_installed_package" == true ]]; then
329329
echo -e "$this_script: Using the $executable installed by $this_script\n"
330-
export FLEX=$package_install_path/bin/$executable
330+
export FLEX=$default_package_install_path/bin/$executable
331331
# Remove flex from the dependency stack
332332
stack_pop dependency_pkg package_done
333333
stack_pop dependency_exe executable_done
@@ -347,7 +347,7 @@ find_or_install()
347347
if ! ./check_version.sh "$package" "$(./build.sh -V "$package")"; then
348348
printf "yes\n"
349349

350-
export FLEX="$package_install_path/bin/$executable"
350+
export FLEX="$default_package_install_path/bin/$executable"
351351
# Trigger 'find_or_install bison' and subsequent build of $package
352352
stack_push dependency_pkg "bison"
353353
stack_push dependency_exe "yacc"
@@ -387,7 +387,7 @@ find_or_install()
387387

388388
if [[ "$script_installed_package" == true ]]; then
389389
echo -e "$this_script: Using the $package executable $executable installed by $this_script\n"
390-
export YACC=$package_install_path/bin/yacc
390+
export YACC=$default_package_install_path/bin/yacc
391391
# Remove bison from the dependency stack
392392
stack_pop dependency_pkg package_done
393393
stack_pop dependency_exe executable_done
@@ -405,7 +405,7 @@ find_or_install()
405405
echo -e "$this_script: Checking whether $package executable $executable in PATH is version < $minimum_version... "
406406
if ! ./check_version.sh "$package" "$(./build.sh -V "$package")"; then
407407
printf "yes.\n"
408-
export YACC="$package_install_path/bin/$executable"
408+
export YACC="$default_package_install_path/bin/$executable"
409409
# Trigger 'find_or_install m4' and subsequent build of $package
410410
stack_push dependency_pkg "m4"
411411
stack_push dependency_exe "m4"
@@ -445,7 +445,7 @@ find_or_install()
445445

446446
if [[ "$script_installed_package" == true ]]; then
447447
echo -e "$this_script: Using the $package executable $executable installed by $this_script\n"
448-
export M4=$package_install_path/bin/m4
448+
export M4=$default_package_install_path/bin/m4
449449
# Remove m4 from the dependency stack
450450
stack_pop dependency_pkg package_done
451451
stack_pop dependency_exe executable_done
@@ -463,7 +463,7 @@ find_or_install()
463463
echo -e "$this_script: Checking whether $package executable $executable in PATH is version < $minimum_version... "
464464
if ! ./check_version.sh "$package" "$(./build.sh -V "$package")"; then
465465
printf "yes.\n"
466-
export M4="$package_install_path/bin/m4"
466+
export M4="$default_package_install_path/bin/m4"
467467
# Halt the recursion and signal that there are no prerequisites to build
468468
stack_push dependency_pkg "none"
469469
stack_push dependency_exe "none"
@@ -488,7 +488,7 @@ find_or_install()
488488

489489
else # $package not in PATH and not yet installed by this script
490490
# Halt the recursion and signal that there are no prerequisites to build
491-
export M4="$package_install_path/bin/m4"
491+
export M4="$default_package_install_path/bin/m4"
492492
stack_push dependency_pkg "none"
493493
stack_push dependency_exe "none"
494494
stack_push dependency_path "none"
@@ -532,16 +532,30 @@ find_or_install()
532532

533533
stack_pop dependency_pkg package
534534
stack_pop dependency_exe executable
535-
stack_pop dependency_path package_install_path
535+
stack_pop dependency_path default_package_install_path
536536

537537
if [[ $package != "none" ]]; then
538538

539+
export default_package_version=$(./build.sh -V "${package}")
540+
export package_version_to_install=${arg_I:-${default_package_version}}
541+
542+
prefix_root="${prefix_root:-${default_package_install_path%${package}/${package_version_to_install}}}"
543+
544+
if [[ ${package} == "gcc" ]]; then
545+
export package_directory_name="gnu"
546+
else
547+
export package_directory_name=${package}
548+
fi
549+
550+
package_install_prefix="${prefix_root}/${package_directory_name}/${package_version_to_install}"
551+
539552
if [[ "$package" == "$executable" ]]; then
540-
echo "$this_script: Ready to install $executable in $package_install_path"
553+
echo "$this_script: Ready to install $executable in $package_install_prefix"
541554
else
542-
echo "$this_script: Ready to install $package executable $executable in $package_install_path"
555+
echo "$this_script: Ready to install $package executable $executable in $package_install_prefix"
543556
fi
544557

558+
545559
if [[ "${arg_y}" == "${__flag_present}" ]]; then
546560
info "-y or --yes-to-all flag present. Proceeding with non-interactive build."
547561
else
@@ -590,11 +604,6 @@ find_or_install()
590604
FC=gfortran
591605
fi
592606

593-
594-
# Strip trailing package name and version number, if present, from installation path
595-
default_package_version=$(./build.sh -V "${package}")
596-
package_install_prefix="${package_install_path%${package}/${arg_I:-${default_package_version}}*}"
597-
598607
if [[ "${arg_y}" == "${__flag_present}" ]]; then
599608
yes_to_all="-y"
600609
fi
@@ -605,66 +614,65 @@ find_or_install()
605614

606615
echo -e "$this_script: Downloading, building, and installing $package \n"
607616
echo "$this_script: Build command: FC=$FC CC=$CC CXX=$CXX ./build.sh -p $package -i $package_install_prefix -j $num_threads ${yes_to_all:-} ${bootstrap:-}"
617+
608618
FC="$FC" CC="$CC" CXX="$CXX" ./build.sh -p "$package" -i "$package_install_prefix" -j "$num_threads" "${yes_to_all:-}" "${bootstrap:-}"
609619

610-
if [[ -x "$package_install_path/bin/$executable" ]]; then
620+
if [[ ! -x "$package_install_prefix/bin/$executable" ]]; then
621+
622+
echo -e "$this_script: Installation unsuccessful. "
623+
emergency "$executable is not in the path ($package_install_prefix/bin) or the user lacks executable permission."
624+
625+
else
611626
echo -e "$this_script: Installation successful.\n"
612627
if [[ "$package" == "$executable" ]]; then
613-
echo -e "$this_script: $executable is in $package_install_path/bin \n"
628+
echo -e "$this_script: $executable is in $default_package_install_path/bin \n"
614629
else
615-
echo -e "$this_script: $package executable $executable is in $package_install_path/bin \n"
630+
echo -e "$this_script: $package executable $executable is in $default_package_install_path/bin \n"
616631
fi
617-
# TODO Merge all applicable branches under one 'if [[ $package == $executable ]]; then'
632+
618633
if [[ $package == "cmake" ]]; then
619-
echo "$this_script: export CMAKE=$package_install_path/bin/$executable"
620-
export CMAKE="$package_install_path/bin/$executable"
634+
echo "$this_script: export CMAKE=$default_package_install_path/bin/$executable"
635+
export CMAKE="$default_package_install_path/bin/$executable"
621636
elif [[ $package == "bison" ]]; then
622-
echo "$this_script: export YACC=$package_install_path/bin/$executable"
623-
export YACC="$package_install_path/bin/$executable"
637+
echo "$this_script: export YACC=$default_package_install_path/bin/$executable"
638+
export YACC="$default_package_install_path/bin/$executable"
624639
elif [[ $package == "flex" ]]; then
625-
echo "$this_script: export FLEX=$package_install_path/bin/$executable"
626-
export FLEX="$package_install_path/bin/$executable"
640+
echo "$this_script: export FLEX=$default_package_install_path/bin/$executable"
641+
export FLEX="$default_package_install_path/bin/$executable"
627642
elif [[ $package == "m4" ]]; then
628-
echo "$this_script: export M4=$package_install_path/bin/$executable"
629-
export M4="$package_install_path/bin/$executable"
643+
echo "$this_script: export M4=$default_package_install_path/bin/$executable"
644+
export M4="$default_package_install_path/bin/$executable"
630645
elif [[ $package == "gcc" ]]; then
631-
echo "$this_script: export FC=$package_install_path/bin/gfortran"
632-
export FC="$package_install_path/bin/gfortran"
633-
echo "$this_script: export CC=$package_install_path/bin/gcc"
634-
export CC="$package_install_path/bin/gcc"
635-
echo "$this_script: export CXX=$package_install_path/bin/g++"
636-
export CXX="$package_install_path/bin/g++"
637-
gfortran_lib_paths="$package_install_path/lib64/:$package_install_path/lib"
646+
echo "$this_script: export FC=$default_package_install_path/bin/gfortran"
647+
export FC="$default_package_install_path/bin/gfortran"
648+
echo "$this_script: export CC=$default_package_install_path/bin/gcc"
649+
export CC="$default_package_install_path/bin/gcc"
650+
echo "$this_script: export CXX=$default_package_install_path/bin/g++"
651+
export CXX="$default_package_install_path/bin/g++"
652+
gfortran_lib_paths="$default_package_install_path/lib64/:$default_package_install_path/lib"
638653
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
639654
export LD_LIBRARY_PATH="$gfortran_lib_paths"
640655
else
641656
export LD_LIBRARY_PATH="$gfortran_lib_paths:$LD_LIBRARY_PATH"
642657
fi
643658
elif [[ $package == "mpich" ]]; then
644-
echo "$this_script: export MPIFC=$package_install_path/bin/mpifort"
645-
export MPIFC="$package_install_path/bin/mpifort"
646-
echo "$this_script: export MPICC= $package_install_path/bin/mpicc"
647-
export MPICC="$package_install_path/bin/mpicc"
648-
echo "$this_script: export MPICXX=$package_install_path/bin/mpicxx"
649-
export MPICXX="$package_install_path/bin/mpicxx"
659+
echo "$this_script: export MPIFC=$default_package_install_path/bin/mpifort"
660+
export MPIFC="$default_package_install_path/bin/mpifort"
661+
echo "$this_script: export MPICC= $default_package_install_path/bin/mpicc"
662+
export MPICC="$default_package_install_path/bin/mpicc"
663+
echo "$this_script: export MPICXX=$default_package_install_path/bin/mpicxx"
664+
export MPICXX="$default_package_install_path/bin/mpicxx"
650665
else
651666
echo -e "$this_script: WARNING: $package executable $executable installed correctly but the \n"
652667
echo -e "$this_script: corresponding environment variable(s) have not been set. This \n"
653668
echo -e "$this_script: could prevent a complete build of OpenCoarrays. Please report this\n"
654669
echo -e "$this_script: issue at https://github.com/sourceryinstitute/opencoarrays/issues\n"
655670
fi
656671
if [[ -z "${PATH:-}" ]]; then
657-
export PATH="$package_install_path/bin"
672+
export PATH="$default_package_install_path/bin"
658673
else
659-
export PATH="$package_install_path/bin:$PATH"
674+
export PATH="$default_package_install_path/bin:$PATH"
660675
fi
661-
else
662-
echo -e "$this_script: Installation unsuccessful. "
663-
echo -e "$executable is not in the following expected path or the user lacks executable permission for it:\n"
664-
echo -e "$package_install_path/bin \n"
665-
printf "Aborting. [exit 80]"
666-
exit 80
667-
fi # End 'if [[ -x "$package_install_path/bin/$executable" ]]'
668-
669-
fi # End 'if [[ "$package" != "none" ]]; then'
676+
fi
677+
fi # End 'if [[ ! -x "$package_install_prefix/bin/$executable" ]]; then'
670678
}

prerequisites/install-functions/print_header.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ EOF
4444
echo "*** './install.sh --yes-to-all' without quotes to instruct the script to ***"
4545
echo "*** assume affirmative answers to all user queries. ***"
4646
echo ""
47-
printf "%s will be installed in %s\n" "${arg_p}" "${install_path}"
47+
printf "%s will be installed in %s\n" "${arg_p}" "${prefix_root:-${install_path}}"
4848
echo ""
4949
if [[ "${arg_y}" == "${__flag_present}" ]]; then
5050
info "-y or --yes-to-all flag present. Proceeding with non-interactive build."

0 commit comments

Comments
 (0)