Skip to content

Commit d50f50f

Browse files
author
Damian Rouson
committed
Update editing of download_prerequisites for GCC 7
1 parent 71a94b7 commit d50f50f

File tree

5 files changed

+142
-114
lines changed

5 files changed

+142
-114
lines changed

prerequisites/build-functions/build_and_install.sh

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

591
build_and_install()
692
{
@@ -41,70 +127,9 @@ build_and_install()
41127
info "pushd ${download_path}/${package_source_directory} "
42128
pushd "${download_path}/${package_source_directory}"
43129

44-
backup_extension=".original"
45-
wget_line=`grep wget "${PWD}/contrib/download_prerequisites" | head -1` || true
46-
if [[ ! -z "${wget_line:-}" ]]; then
47-
48-
already_modified_downloader="false"
49-
50-
else # Check whether gcc contrib/download_prerequisites was already backed up and then modified
51-
52-
if [[ ! -f "${PWD}/contrib/download_prerequisites${backup_extension}" ]]; then
53-
emergency "build_and_install.sh: gcc contrib/download_prerequisites does not use wget"
54-
fi
55-
already_modified_downloader="true"
56-
fi
57-
58-
if [[ ${already_modified_downloader:-} != "true" ]]; then
59-
60-
# Check for wget format used in GCC 5-6
61-
if [[ "${wget_line}" == *"ftp"* ]]; then
62-
wget_command="${wget_line%%ftp*}"
63-
64-
# Check for wget format adopted in GCC 7
65-
elif [[ "${wget_line}" == *"base_url"* ]]; then
66-
wget_command="${wget_line%%\"\$\{directory\}/\$\{ar\}\"*}"
67-
wget_command="wget${wget_command#*wget}"
68-
else
69-
emergency "build_and_install.sh: gcc contrib/download_prerequisites does not use a known URL format"
70-
fi
71-
info "GCC contrib/download_prerequisites wget command is '${wget_command}'"
72-
73-
arg_string="${gcc_prereqs_fetch_args[@]:-}"
74-
gcc_download_changed=7.0.0
75-
if [[ "$(version "$version_to_build")" -gt "$(version "$gcc_download_changed")" || $version_to_build == "trunk" || $version_to_build == "$gcc_download_changed" ]]; then
76-
case "${gcc_prereqs_fetch}" in
77-
"curl")
78-
arg_string="${arg_string} -o "
79-
;;
80-
"wget")
81-
debug "build_and_install.sh: using wget"
82-
;;
83-
*)
84-
debug "build_and_install.sh: if problems occur, check whether the modification of download_prerequisites is compatible with the download method ${gcc_prereqs_fetch}"
85-
;;
86-
esac
87-
if ! type sha512sum &> /dev/null; then
88-
info "build_and_install.sh: sha512sum unavailable. Turning off file integrity verification in GCC contrib/download_prerequisites."
89-
sed -i''${backup_extension} s/"verify=1"/"verify=0"/ "${PWD}/contrib/download_prerequisites"
90-
fi
91-
fi
92-
# Don't try to overwrite the unmodified download_prerequisites file if exists or if we don't have write permissions to it
93-
if [[ -f "${PWD}/contrib/download_prerequisites"${backup_extension} ]]; then
94-
backup_extension=""
95-
fi
96-
info "Replacing GCC contrib/download_prerequisites wget with the following command:"
97-
if [[ "$(uname)" == "Linux" ]]; then
98-
info "sed -i'${backup_extension}' s/\"${wget_command}\"/\"${gcc_prereqs_fetch} ${arg_string}\"/ \"${PWD}/contrib/download_prerequisites\""
99-
sed -i''${backup_extension} s/"${wget_command}"/"${gcc_prereqs_fetch} ${arg_string}"/ "${PWD}/contrib/download_prerequisites"
100-
else
101-
# This works on OS X and other POSIX-compliant operating systems:
102-
info "sed -i '${backup_extension}' s/\"${wget_command}\"/\"${gcc_prereqs_fetch} ${arg_string}\"/ \"${PWD}/contrib/download_prerequisites\""
103-
sed -i ''${backup_extension} s/"${wget_command}"/"${gcc_prereqs_fetch} ${arg_string}"/ "${PWD}/contrib/download_prerequisites"
104-
fi
105-
106-
fi # end if [[ ${already_modified_downloader:-} != "true" ]];
107-
130+
# Switch download mechanism, if wget is not available
131+
edit_GCC_download_prereqs_file_if_necessary
132+
108133
# Download GCC prerequisities
109134
"${PWD}"/contrib/download_prerequisites
110135

prerequisites/build-functions/download_if_necessary.sh

Lines changed: 5 additions & 5 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" )
@@ -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" )
6464
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

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="[email protected]"
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)