Skip to content

Commit 71a94b7

Browse files
author
Damian Rouson
committed
Update gcc download_prerequisites edits for GCC 7
1 parent 7e56c59 commit 71a94b7

File tree

2 files changed

+96
-25
lines changed

2 files changed

+96
-25
lines changed
Lines changed: 94 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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); }'; }
4+
35
build_and_install()
46
{
57
num_threads=${arg_j}
@@ -14,17 +16,98 @@ build_and_install()
1416
mkdir -p "${build_path}"
1517
info "pushd ${build_path}"
1618
pushd "${build_path}"
17-
if [[ "${package_to_build}" == "gcc" ]]; then
19+
20+
if [[ "${package_to_build}" != "gcc" ]]; then
21+
22+
info "Configuring ${package_to_build} ${version_to_build} with the following command:"
23+
info "FC=\"${FC:-'gfortran'}\" CC=\"${CC:-'gcc'}\" CXX=\"${CXX:-'g++'}\" \"${download_path}/${package_source_directory}\"/configure --prefix=\"${install_path}\""
24+
FC="${FC:-'gfortran'}" CC="${CC:-'gcc'}" CXX="${CXX:-'g++'}" "${download_path}/${package_source_directory}"/configure --prefix="${install_path}"
25+
info "Building with the following command:"
26+
info "FC=\"${FC:-'gfortran'}\" CC=\"${CC:-'gcc'}\" CXX=\"${CXX:-'g++'}\" make -j\"${num_threads}\""
27+
FC="${FC:-'gfortran'}" CC="${CC:-'gcc'}" CXX="${CXX:-'g++'}" make "-j${num_threads}"
28+
info "Installing ${package_to_build} in ${install_path}"
29+
if [[ ! -z "${SUDO:-}" ]]; then
30+
info "You do not have write permissions to the installation path ${install_path}"
31+
info "If you have administrative privileges, enter your password to install ${package_to_build}"
32+
fi
33+
info "Installing with the following command: ${SUDO:-} make install"
34+
${SUDO:-} make install
35+
36+
else # ${package_to_build} == "gcc"
37+
38+
# Use GCC's contrib/download_prerequisites script after modifying it, if necessary, to use the
39+
# the preferred download mechanism set in prerequisites/build-functions/set_or_print_downloader.sh
40+
1841
info "pushd ${download_path}/${package_source_directory} "
1942
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
43+
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+
108+
# Download GCC prerequisities
27109
"${PWD}"/contrib/download_prerequisites
110+
28111
info "popd"
29112
popd
30113
info "Configuring gcc/g++/gfortran builds with the following command:"
@@ -38,21 +121,9 @@ build_and_install()
38121
fi
39122
info "Installing with the following command: ${SUDO:-} make install"
40123
${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
124+
125+
fi # end if [[ "${package_to_build}" != "gcc" ]]; then
126+
56127
info "popd"
57128
popd
58129
}

prerequisites/build-functions/download_if_necessary.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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")
@@ -61,7 +61,7 @@ download_if_necessary()
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
*)
6767
emergency "download_if_necessary.sh: Unrecognized \${gcc_prereqs_fetch_args}=${gcc_prereqs_fetch_args}."

0 commit comments

Comments
 (0)