]>
Commit | Line | Data |
---|---|---|
69baf0a3 | 1 | #! /bin/sh |
38000825 | 2 | #! -*- coding:utf-8; mode:shell-script; -*- |
69baf0a3 | 3 | |
38000825 MK |
4 | # Download some prerequisites needed by GCC. |
5 | # Run this from the top level of the GCC source tree and the GCC build will do | |
6 | # the right thing. Run it with the `--help` option for more information. | |
69baf0a3 | 7 | # |
be60f802 | 8 | # (C) 2010-2021 Free Software Foundation |
69baf0a3 AH |
9 | # |
10 | # This program is free software: you can redistribute it and/or modify | |
11 | # it under the terms of the GNU General Public License as published by | |
12 | # the Free Software Foundation, either version 3 of the License, or | |
13 | # (at your option) any later version. | |
14 | # | |
15 | # This program is distributed in the hope that it will be useful, but | |
16 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | # General Public License for more details. | |
19 | # | |
20 | # You should have received a copy of the GNU General Public License | |
21 | # along with this program. If not, see http://www.gnu.org/licenses/. | |
22 | ||
38000825 MK |
23 | program='download_prerequisites' |
24 | version='(unversioned)' | |
25 | ||
26 | # MAINTAINERS: If you update the package versions below, please | |
27 | # remember to also update the files `contrib/prerequisites.sha512` and | |
28 | # `contrib/prerequisites.md5` with the new checksums. | |
29 | ||
be60f802 TB |
30 | gmp='gmp-6.2.1.tar.bz2' |
31 | mpfr='mpfr-4.1.0.tar.bz2' | |
32 | mpc='mpc-1.2.1.tar.gz' | |
33 | isl='isl-0.24.tar.bz2' | |
db50aea6 | 34 | gettext='gettext-0.22.tar.gz' |
38000825 | 35 | |
d51dd316 | 36 | base_url='http://gcc.gnu.org/pub/gcc/infrastructure/' |
38000825 MK |
37 | |
38 | echo_archives() { | |
39 | echo "${gmp}" | |
40 | echo "${mpfr}" | |
41 | echo "${mpc}" | |
db50aea6 | 42 | echo "${gettext}" |
38000825 MK |
43 | if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi |
44 | } | |
45 | ||
46 | graphite=1 | |
47 | verify=1 | |
48 | force=0 | |
b1c0468f DR |
49 | OS=$(uname) |
50 | ||
b1c0468f DR |
51 | if type wget > /dev/null ; then |
52 | fetch='wget' | |
53 | else | |
d51dd316 | 54 | fetch='curl -LO' |
b1c0468f DR |
55 | fi |
56 | chksum_extension='sha512' | |
38000825 MK |
57 | directory='.' |
58 | ||
59 | helptext="usage: ${program} [OPTION...] | |
60 | ||
61 | Downloads some prerequisites needed by GCC. Run this from the top level of the | |
62 | GCC source tree and the GCC build will do the right thing. | |
63 | ||
64 | The following options are available: | |
65 | ||
66 | --directory=DIR download and unpack packages into DIR instead of '.' | |
67 | --force download again overwriting existing packages | |
68 | --no-force do not download existing packages again (default) | |
69 | --isl download ISL, needed for Graphite loop optimizations (default) | |
70 | --graphite same as --isl | |
71 | --no-isl don't download ISL | |
72 | --no-graphite same as --no-isl | |
73 | --verify verify package integrity after download (default) | |
74 | --no-verify don't verify package integrity | |
75 | --sha512 use SHA512 checksum to verify package integrity (default) | |
76 | --md5 use MD5 checksum to verify package integrity | |
77 | --help show this text and exit | |
78 | --version show version information and exit | |
79 | " | |
78c56a5a | 80 | |
38000825 | 81 | versiontext="${program} ${version} |
83ffe9cd | 82 | Copyright (C) 2016-2023 Free Software Foundation, Inc. |
38000825 MK |
83 | This is free software; see the source for copying conditions. There is NO |
84 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." | |
85 | ||
86 | die() { | |
87 | echo "error: $@" >&2 | |
88 | exit 1 | |
89 | } | |
90 | ||
91 | for arg in "$@" | |
92 | do | |
93 | case "${arg}" in | |
94 | --help) | |
95 | echo "${helptext}" | |
96 | exit | |
97 | ;; | |
98 | --version) | |
99 | echo "${versiontext}" | |
100 | exit | |
101 | ;; | |
102 | esac | |
103 | done | |
104 | unset arg | |
105 | ||
0deabebe | 106 | # Emulate Linux's 'md5sum --check' on macOS |
b1c0468f DR |
107 | md5_check() { |
108 | # Store the standard input: a line from contrib/prerequisites.md5: | |
109 | md5_checksum_line=$(cat -) | |
110 | # Grab the text before the first space | |
111 | md5_checksum_expected="${md5_checksum_line%% *}" | |
112 | # Grab the text after the first space | |
113 | file_to_check="${md5_checksum_line##* }" | |
114 | # Calculate the md5 checksum for the downloaded file | |
115 | md5_checksum_output=$(md5 -r "${file_to_check}") | |
116 | # Grab the text before the first space | |
117 | md5_checksum_detected="${md5_checksum_output%% *}" | |
79a017c4 | 118 | [ "${md5_checksum_expected}" = "${md5_checksum_detected}" ] \ |
b1c0468f DR |
119 | || die "Cannot verify integrity of possibly corrupted file ${file_to_check}" |
120 | echo "${file_to_check}: OK" | |
121 | } | |
122 | ||
123 | ||
38000825 MK |
124 | argnext= |
125 | for arg in "$@" | |
126 | do | |
127 | if [ "x${argnext}" = x ] | |
128 | then | |
129 | case "${arg}" in | |
130 | --directory) | |
131 | argnext='directory' | |
132 | ;; | |
133 | --directory=*) | |
134 | directory="${arg#--directory=}" | |
135 | ;; | |
136 | --force) | |
137 | force=1 | |
138 | ;; | |
139 | --no-force) | |
140 | force=0 | |
141 | ;; | |
142 | --isl|--graphite) | |
143 | graphite=1 | |
144 | ;; | |
145 | --no-isl|--no-graphite) | |
146 | graphite=0 | |
147 | ;; | |
148 | --verify) | |
149 | verify=1 | |
150 | ;; | |
151 | --no-verify) | |
152 | verify=0 | |
153 | ;; | |
154 | --sha512) | |
b1c0468f | 155 | chksum_extension='sha512' |
38000825 MK |
156 | verify=1 |
157 | ;; | |
158 | --md5) | |
b1c0468f | 159 | chksum_extension='md5' |
38000825 MK |
160 | verify=1 |
161 | ;; | |
162 | -*) | |
163 | die "unknown option: ${arg}" | |
164 | ;; | |
165 | *) | |
166 | die "too many arguments" | |
167 | ;; | |
168 | esac | |
169 | else | |
170 | case "${arg}" in | |
171 | -*) | |
172 | die "Missing argument for option --${argnext}" | |
173 | ;; | |
174 | esac | |
175 | case "${argnext}" in | |
176 | directory) | |
177 | directory="${arg}" | |
178 | ;; | |
179 | *) | |
180 | die "The impossible has happened" | |
181 | ;; | |
182 | esac | |
183 | argnext= | |
184 | fi | |
185 | done | |
186 | [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}" | |
187 | unset arg argnext | |
188 | ||
0deabebe AP |
189 | case $chksum_extension in |
190 | sha512) | |
191 | case $OS in | |
192 | "Darwin"|"FreeBSD"|"DragonFly"|"AIX") | |
193 | chksum='shasum -a 512 --check' | |
194 | ;; | |
195 | "OpenBSD") | |
196 | chksum='sha512 -c' | |
197 | ;; | |
198 | *) | |
199 | chksum='sha512sum -c' | |
200 | ;; | |
201 | esac | |
202 | ;; | |
203 | md5) | |
204 | case $OS in | |
205 | "Darwin") | |
206 | chksum='md5_check' | |
207 | ;; | |
208 | *) | |
209 | chksum='md5sum -c' | |
210 | ;; | |
211 | esac | |
212 | ;; | |
213 | *) | |
214 | die "Unkown checksum $chksum_extension" | |
215 | ;; | |
216 | esac | |
217 | ||
38000825 MK |
218 | [ -e ./gcc/BASE-VER ] \ |
219 | || die "You must run this script in the top-level GCC source directory" | |
220 | ||
221 | [ -d "${directory}" ] \ | |
222 | || die "No such directory: ${directory}" | |
223 | ||
224 | for ar in $(echo_archives) | |
225 | do | |
226 | if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi | |
227 | [ -e "${directory}/${ar}" ] \ | |
def4c0b4 | 228 | || ( cd "${directory}" && ${fetch} --no-verbose "${base_url}${ar}" ) \ |
38000825 MK |
229 | || die "Cannot download ${ar} from ${base_url}" |
230 | done | |
231 | unset ar | |
232 | ||
233 | if [ ${verify} -gt 0 ] | |
234 | then | |
b1c0468f | 235 | chksumfile="contrib/prerequisites.${chksum_extension}" |
38000825 MK |
236 | [ -r "${chksumfile}" ] || die "No checksums available" |
237 | for ar in $(echo_archives) | |
238 | do | |
239 | grep "${ar}" "${chksumfile}" \ | |
b1c0468f | 240 | | ( cd "${directory}" && ${chksum} ) \ |
38000825 MK |
241 | || die "Cannot verify integrity of possibly corrupted file ${ar}" |
242 | done | |
243 | unset chksumfile | |
a8db5990 | 244 | fi |
38000825 MK |
245 | unset ar |
246 | ||
247 | for ar in $(echo_archives) | |
248 | do | |
249 | package="${ar%.tar*}" | |
250 | if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi | |
796190e5 IL |
251 | case $ar in |
252 | *.gz) | |
253 | uncompress='gzip -d' | |
254 | ;; | |
255 | *.bz2) | |
256 | uncompress='bzip2 -d' | |
257 | ;; | |
258 | *) | |
259 | uncompress='cat' | |
260 | ;; | |
261 | esac | |
38000825 | 262 | [ -e "${directory}/${package}" ] \ |
796190e5 | 263 | || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \ |
38000825 MK |
264 | || die "Cannot extract package from ${ar}" |
265 | unset package | |
266 | done | |
267 | unset ar | |
268 | ||
269 | for ar in $(echo_archives) | |
270 | do | |
271 | target="${directory}/${ar%.tar*}/" | |
272 | linkname="${ar%-*}" | |
273 | if [ ${force} -gt 0 ]; then rm -f "${linkname}"; fi | |
274 | [ -e "${linkname}" ] \ | |
275 | || ln -s "${target}" "${linkname}" \ | |
276 | || die "Cannot create symbolic link ${linkname} --> ${target}" | |
277 | unset target linkname | |
278 | done | |
279 | unset ar | |
280 | ||
281 | echo "All prerequisites downloaded successfully." |