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