|
1 | 1 | # Make the build directory, configure, and build |
2 | 2 | # 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 | +} |
4 | 90 |
|
5 | 91 | build_and_install() |
6 | 92 | { |
@@ -41,70 +127,9 @@ build_and_install() |
41 | 127 | info "pushd ${download_path}/${package_source_directory} " |
42 | 128 | pushd "${download_path}/${package_source_directory}" |
43 | 129 |
|
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 | + |
108 | 133 | # Download GCC prerequisities |
109 | 134 | "${PWD}"/contrib/download_prerequisites |
110 | 135 |
|
|
0 commit comments