|
| 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 | +} |
0 commit comments