Skip to content

Commit 3ccb984

Browse files
author
Damian Rouson
authored
Merge pull request #296 from sourceryinstitute/edit-gcc-download_prerequisites
Edit GCC download_prerequisites
2 parents 3d3aff0 + 3429f4b commit 3ccb984

File tree

6 files changed

+186
-74
lines changed

6 files changed

+186
-74
lines changed
Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Make the build directory, configure, and build
22
# shellcheck disable=SC2154
3+
4+
source ${OPENCOARRAYS_SRC_DIR}/prerequisites/build-functions/edit_GCC_download_prereqs_file_if_necessary.sh
5+
36
build_and_install()
47
{
58
num_threads=${arg_j}
@@ -14,17 +17,37 @@ build_and_install()
1417
mkdir -p "${build_path}"
1518
info "pushd ${build_path}"
1619
pushd "${build_path}"
17-
if [[ "${package_to_build}" == "gcc" ]]; then
20+
21+
if [[ "${package_to_build}" != "gcc" ]]; then
22+
23+
info "Configuring ${package_to_build} ${version_to_build} with the following command:"
24+
info "FC=\"${FC:-'gfortran'}\" CC=\"${CC:-'gcc'}\" CXX=\"${CXX:-'g++'}\" \"${download_path}/${package_source_directory}\"/configure --prefix=\"${install_path}\""
25+
FC="${FC:-'gfortran'}" CC="${CC:-'gcc'}" CXX="${CXX:-'g++'}" "${download_path}/${package_source_directory}"/configure --prefix="${install_path}"
26+
info "Building with the following command:"
27+
info "FC=\"${FC:-'gfortran'}\" CC=\"${CC:-'gcc'}\" CXX=\"${CXX:-'g++'}\" make -j\"${num_threads}\""
28+
FC="${FC:-'gfortran'}" CC="${CC:-'gcc'}" CXX="${CXX:-'g++'}" make "-j${num_threads}"
29+
info "Installing ${package_to_build} in ${install_path}"
30+
if [[ ! -z "${SUDO:-}" ]]; then
31+
info "You do not have write permissions to the installation path ${install_path}"
32+
info "If you have administrative privileges, enter your password to install ${package_to_build}"
33+
fi
34+
info "Installing with the following command: ${SUDO:-} make install"
35+
${SUDO:-} make install
36+
37+
else # ${package_to_build} == "gcc"
38+
39+
# Use GCC's contrib/download_prerequisites script after modifying it, if necessary, to use the
40+
# the preferred download mechanism set in prerequisites/build-functions/set_or_print_downloader.sh
41+
1842
info "pushd ${download_path}/${package_source_directory} "
1943
pushd "${download_path}/${package_source_directory}"
20-
arg_string="${gcc_prereqs_fetch_args[@]:-}"
21-
if [[ "$(uname)" == "Linux" ]]; then
22-
sed -i'' s/"wget --no-verbose -O \"\${directory}\/\${ar}\""/"${gcc_prereqs_fetch} ${arg_string}"/ "${PWD}/contrib/download_prerequisites"
23-
else
24-
# This works on OS X and other POSIX-compliant operating systems:
25-
sed -i '' s/"wget --no-verbose -O \"\${directory}\/\${ar}\""/"${gcc_prereqs_fetch} ${arg_string}"/ "${PWD}/contrib/download_prerequisites"
26-
fi
44+
45+
# Switch download mechanism, if wget is not available
46+
edit_GCC_download_prereqs_file_if_necessary
47+
48+
# Download GCC prerequisities
2749
"${PWD}"/contrib/download_prerequisites
50+
2851
info "popd"
2952
popd
3053
info "Configuring gcc/g++/gfortran builds with the following command:"
@@ -38,21 +61,9 @@ build_and_install()
3861
fi
3962
info "Installing with the following command: ${SUDO:-} make install"
4063
${SUDO:-} make install
41-
else
42-
info "Configuring ${package_to_build} ${version_to_build} with the following command:"
43-
info "FC=\"${FC:-'gfortran'}\" CC=\"${CC:-'gcc'}\" CXX=\"${CXX:-'g++'}\" \"${download_path}/${package_source_directory}\"/configure --prefix=\"${install_path}\""
44-
FC="${FC:-'gfortran'}" CC="${CC:-'gcc'}" CXX="${CXX:-'g++'}" "${download_path}/${package_source_directory}"/configure --prefix="${install_path}"
45-
info "Building with the following command:"
46-
info "FC=\"${FC:-'gfortran'}\" CC=\"${CC:-'gcc'}\" CXX=\"${CXX:-'g++'}\" make -j\"${num_threads}\""
47-
FC="${FC:-'gfortran'}" CC="${CC:-'gcc'}" CXX="${CXX:-'g++'}" make "-j${num_threads}"
48-
info "Installing ${package_to_build} in ${install_path}"
49-
if [[ ! -z "${SUDO:-}" ]]; then
50-
info "You do not have write permissions to the installation path ${install_path}"
51-
info "If you have administrative privileges, enter your password to install ${package_to_build}"
52-
fi
53-
info "Installing with the following command: ${SUDO:-} make install"
54-
${SUDO:-} make install
55-
fi
64+
65+
fi # end if [[ "${package_to_build}" != "gcc" ]]; then
66+
5667
info "popd"
5768
popd
5869
}

prerequisites/build-functions/download_if_necessary.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# shellcheck shell=bash disable=SC2148
2-
# shellcheck source=./ftp-url.sh
3-
source "${OPENCOARRAYS_SRC_DIR}/prerequisites/build-functions/ftp-url.sh"
2+
# shellcheck source=./ftp_url.sh
3+
source "${OPENCOARRAYS_SRC_DIR}/prerequisites/build-functions/ftp_url.sh"
44
# shellcheck source=./set_SUDO_if_needed_to_write_to_directory.sh
55
source "${OPENCOARRAYS_SRC_DIR}/prerequisites/build-functions/set_SUDO_if_needed_to_write_to_directory.sh"
66

@@ -18,7 +18,7 @@ download_if_necessary()
1818
"wget" )
1919
args=("--no-check-certificate")
2020
;;
21-
"ftp-url" )
21+
"ftp_url" )
2222
args=("-n")
2323
;;
2424
"git" )
@@ -38,7 +38,7 @@ download_if_necessary()
3838
first_three_characters=$(echo "${package_url}" | cut -c1-3)
3939
case "${first_three_characters}" in
4040
"ftp" )
41-
args=("-LO" "-u" "anonymous:")
41+
args=("-LO" "-u" "anonymous: ")
4242
;;
4343
"htt" )
4444
args=("-LO")
@@ -57,14 +57,14 @@ download_if_necessary()
5757
"wget" )
5858
gcc_prereqs_fetch_args=("--no-check-certificate")
5959
;;
60-
"ftp-url" )
60+
"ftp_url" )
6161
gcc_prereqs_fetch_args=("-n")
6262
;;
6363
"curl" )
64-
gcc_prereqs_fetch_args=("-LO" "-u" "anonymous:")
64+
gcc_prereqs_fetch_args=("-LO" "-u" "anonymous: ")
6565
;;
6666
*)
67-
emergency "download_if_necessary.sh: Unrecognized \${gcc_prereqs_fetch_args}=${gcc_prereqs_fetch_args}."
67+
emergency "download_if_necessary.sh: Unrecognized \${gcc_prereqs_fetch}=${gcc_prereqs_fetch}."
6868
;;
6969
esac
7070

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Make the build directory, configure, and build
2+
# shellcheck disable=SC2154
3+
4+
edit_GCC_download_prereqs_file_if_necessary()
5+
{
6+
# Only modify download_prerequisites if wget is unavailable
7+
if type wget &> /dev/null; then
8+
info "wget available. Invoking unmodified GCC script contrib/download_prerequisites."
9+
else
10+
info "wget unavailable. Editing GCC contrib/download_prerequisites to replace it with ${gcc_prereqs_fetch}"
11+
12+
download_prereqs_file="${PWD}/contrib/download_prerequisites"
13+
14+
# Define a file extension for the download_prerequisites backup
15+
backup_extension=".original"
16+
backup_file="${download_prereqs_file}${backup_extension}"
17+
if [[ -f ${backup_file} ]]; then
18+
# Prevent overwriting an existing backup:
19+
backup_extension=""
20+
fi
21+
22+
# Grab the line with the first occurence of 'wget'
23+
wget_line=`grep wget "${download_prereqs_file}" | head -1` || true
24+
if [[ ! -z "${wget_line:-}" ]]; then
25+
# Download_prerequisites contains wget so we haven't modified it
26+
already_modified_downloader="false"
27+
else
28+
# Check whether a backup file already exists
29+
if [[ ! -f "${backup_file}" ]]; then
30+
emergency ": gcc contrib/download_prerequisites does not use wget"
31+
else
32+
already_modified_downloader="true"
33+
fi
34+
fi
35+
36+
# Only modify download_prerequisites once
37+
if [[ ${already_modified_downloader} != "true" ]]; then
38+
39+
# Check for wget format used before GCC 7
40+
if [[ "${wget_line}" == *"ftp"* ]]; then
41+
gcc7_format="false"
42+
wget_command="${wget_line%%ftp*}" # grab everything before ftp
43+
44+
# Check for wget format adopted in GCC 7
45+
elif [[ "${wget_line}" == *"base_url"* ]]; then
46+
gcc7_format="true"
47+
case "${gcc_prereqs_fetch}" in
48+
"ftp_url")
49+
# Insert a new line after line 2 to include ftp_url.sh as a download option
50+
sed -i${backup_extension} -e '2 a\'$'\n'". ${OPENCOARRAYS_SRC_DIR}/prerequisites/build-functions/ftp_url.sh"$'\n' "${download_prereqs_file}"
51+
wget_command='wget --no-verbose -O "${directory}\/${ar}"'
52+
;;
53+
"curl")
54+
wget_command="${wget_line%%\"\$\{directory\}*}" # grab everything before "${base_url}
55+
wget_command="wget${wget_command#*wget}" # keep everything from wget forward
56+
;;
57+
*)
58+
emergency "Unknown download program ${gcc_prereqs_fetch} in edit_GCC_download_prereqs_file_if_necessary.sh"
59+
;;
60+
esac
61+
62+
else
63+
emergency "gcc contrib/download_prerequisites does not use a known URL format"
64+
fi
65+
66+
arg_string="${gcc_prereqs_fetch_args[@]:-} "
67+
68+
if [[ ${gcc7_format} == "true" ]]; then
69+
case "${gcc_prereqs_fetch}" in
70+
"curl")
71+
arg_string="${arg_string} -o "
72+
;;
73+
*)
74+
debug "if problem downloading, ensure that the gcc download_prerequisites edits are compatible with ${gcc_prereqs_fetch}"
75+
;;
76+
esac
77+
# Protect against missing sha512sum command adopted in GCC 7 (not available by default on Lubuntu Linux)
78+
if ! type sha512sum &> /dev/null; then
79+
info "sha512sum unavailable. Turning off file integrity verification in GCC contrib/download_prerequisites."
80+
if [[ "$(uname)" == "Linux" ]]; then
81+
# Adjust for non-POSIX OS
82+
sed -i"${backup_extension}" s/"verify=1"/"verify=0"/ "${download_prereqs_file}"
83+
else
84+
sed -i "${backup_extension}" s/"verify=1"/"verify=0"/ "${download_prereqs_file}"
85+
fi
86+
fi
87+
fi
88+
info "Using the following command to replacing wget in the GCC download_prerequisites file:"
89+
info "sed -i${backup_extension} s/\"${wget_command}\"/\"${gcc_prereqs_fetch} ${arg_string} \"/ \"${download_prereqs_file}\""
90+
if [[ "$(uname)" == "Linux" ]]; then
91+
sed -i"${backup_extension}" s/"${wget_command}"/"${gcc_prereqs_fetch} ${arg_string} "/ "${download_prereqs_file}"
92+
else
93+
sed -i "${backup_extension}" s/"${wget_command}"/"${gcc_prereqs_fetch} ${arg_string} "/ "${download_prereqs_file}"
94+
fi
95+
96+
fi # end if [[ ${already_modified_downloader:-} != "true" ]];
97+
fi # end if ! type wget &> /dev/null;
98+
}

prerequisites/build-functions/ftp-url.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /bin/sh
2+
# Download a file from an anonymous ftp site
3+
#
4+
# Usage:
5+
# ftp_url <ftp-mode> ftp://<fully-qualified-domain>:/<path-to-file>/<file-name>
6+
#
7+
# Example:
8+
# ftp_url -n ftp://ftp.gnu.org:/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.bz2
9+
ftp_url()
10+
{
11+
ftp_mode="${1}"
12+
url="${2}"
13+
14+
if [ "${ftp_mode}" != "-n" ]; then
15+
echo "Unexpected ftp mode received by ftp_url.sh: ${ftp_mode}"
16+
fi
17+
18+
protocol="${url%%:*}" # grab text_before_first_colon
19+
if [ "${protocol}" != "ftp" ]; then
20+
echo "URL with unexpected protocol received by ftp_url.sh: ${text_before_first_colon}"
21+
fi
22+
23+
text_after_double_slash="${url##*//}"
24+
FTP_SERVER="${text_after_double_slash%%/*}" # grab remaining text before first slash
25+
FILE_NAME="${url##*/}" # grab text after final slash
26+
27+
text_after_final_colon="${url##*:}"
28+
FILE_PATH="${text_after_final_colon#*//}"
29+
FILE_PATH="${FILE_PATH#*/}"
30+
FILE_PATH="${FILE_PATH%/*}"
31+
32+
USERNAME=anonymous
33+
PASSWORD="noone@nowhere.com"
34+
echo "starting anonymous download: ${protocol} ${ftp_mode} ${FTP_SERVER};... cd ${FILE_PATH}; ...; get ${FILE_NAME}"
35+
36+
ftp "${ftp_mode}" "${FTP_SERVER}" <<Done-ftp
37+
user "${USERNAME}" "${PASSWORD}"
38+
cd "${FILE_PATH}"
39+
passive
40+
binary
41+
get "${FILE_NAME}"
42+
bye
43+
Done-ftp
44+
45+
echo "finished anonymous ftp"
46+
}

prerequisites/build-functions/set_or_print_downloader.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ set_or_print_downloader()
2828
elif type ftp &> /dev/null; then
2929
if [[ "${package_name}" == "gcc" || "${package_name}" == "wget" || "${package_name}" == "make" ||
3030
"${package_name}" == "bison" || "${package_name}" == "m4" ]]; then
31-
gcc_prereqs_fetch=wget
31+
gcc_prereqs_fetch=ftp_url
3232
fi
3333
else
3434
tried="curl, wget, and ftp"

0 commit comments

Comments
 (0)