middle-end/115426 - wrong gimplification of "rm" asm output operand
[official-gcc.git] / contrib / download_prerequisites
blob6adc97ef89679852b8e10f9f4d292032af001b21
1 #! /bin/sh
2 #! -*- coding:utf-8; mode:shell-script; -*-
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.
8 # (C) 2010-2021 Free Software Foundation
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.
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.
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/.
23 program='download_prerequisites'
24 version='(unversioned)'
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.
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'
34 gettext='gettext-0.22.tar.gz'
36 base_url='http://gcc.gnu.org/pub/gcc/infrastructure/'
38 echo_archives() {
39 echo "${gettext}"
40 if "${only_gettext}"; then return; fi
41 echo "${gmp}"
42 echo "${mpfr}"
43 echo "${mpc}"
44 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
47 graphite=1
48 verify=1
49 force=0
50 only_gettext=false
51 OS=$(uname)
53 if type wget > /dev/null ; then
54 fetch='wget'
55 else
56 fetch='curl -LO'
58 chksum_extension='sha512'
59 directory='.'
61 helptext="usage: ${program} [OPTION...]
63 Downloads some prerequisites needed by GCC. Run this from the top level of the
64 GCC source tree and the GCC build will do the right thing.
66 The following options are available:
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
79 --only-gettext inhibit downloading any package but gettext
80 --help show this text and exit
81 --version show version information and exit
84 versiontext="${program} ${version}
85 Copyright (C) 2016-2024 Free Software Foundation, Inc.
86 This is free software; see the source for copying conditions. There is NO
87 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
89 die() {
90 echo "error: $@" >&2
91 exit 1
94 for arg in "$@"
96 case "${arg}" in
97 --help)
98 echo "${helptext}"
99 exit
101 --version)
102 echo "${versiontext}"
103 exit
105 esac
106 done
107 unset arg
109 # Emulate Linux's 'md5sum --check' on macOS
110 md5_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%% *}"
121 [ "${md5_checksum_expected}" = "${md5_checksum_detected}" ] \
122 || die "Cannot verify integrity of possibly corrupted file ${file_to_check}"
123 echo "${file_to_check}: OK"
127 argnext=
128 for arg in "$@"
130 if [ "x${argnext}" = x ]
131 then
132 case "${arg}" in
133 --directory)
134 argnext='directory'
136 --directory=*)
137 directory="${arg#--directory=}"
139 --force)
140 force=1
142 --no-force)
143 force=0
145 --isl|--graphite)
146 graphite=1
148 --no-isl|--no-graphite)
149 graphite=0
151 --verify)
152 verify=1
154 --no-verify)
155 verify=0
157 --sha512)
158 chksum_extension='sha512'
159 verify=1
161 --md5)
162 chksum_extension='md5'
163 verify=1
165 --only-gettext)
166 only_gettext=true
169 die "unknown option: ${arg}"
172 die "too many arguments"
174 esac
175 else
176 case "${arg}" in
178 die "Missing argument for option --${argnext}"
180 esac
181 case "${argnext}" in
182 directory)
183 directory="${arg}"
186 die "The impossible has happened"
188 esac
189 argnext=
191 done
192 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
193 unset arg argnext
195 case $chksum_extension in
196 sha512)
197 case $OS in
198 "Darwin"|"FreeBSD"|"DragonFly"|"AIX")
199 chksum='shasum -a 512 --check'
201 "OpenBSD")
202 chksum='sha512 -c'
205 chksum='sha512sum -c'
207 esac
209 md5)
210 case $OS in
211 "Darwin")
212 chksum='md5_check'
215 chksum='md5sum -c'
217 esac
220 die "Unkown checksum $chksum_extension"
222 esac
224 [ -e ./gcc/BASE-VER ] \
225 || die "You must run this script in the top-level GCC source directory"
227 [ -d "${directory}" ] \
228 || die "No such directory: ${directory}"
230 for ar in $(echo_archives)
232 if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi
233 [ -e "${directory}/${ar}" ] \
234 || ( cd "${directory}" && ${fetch} --no-verbose "${base_url}${ar}" ) \
235 || die "Cannot download ${ar} from ${base_url}"
236 done
237 unset ar
239 if [ ${verify} -gt 0 ]
240 then
241 chksumfile="contrib/prerequisites.${chksum_extension}"
242 [ -r "${chksumfile}" ] || die "No checksums available"
243 for ar in $(echo_archives)
245 grep "${ar}" "${chksumfile}" \
246 | ( cd "${directory}" && ${chksum} ) \
247 || die "Cannot verify integrity of possibly corrupted file ${ar}"
248 done
249 unset chksumfile
251 unset ar
253 for ar in $(echo_archives)
255 package="${ar%.tar*}"
256 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
257 case $ar in
258 *.gz)
259 uncompress='gzip -d'
261 *.bz2)
262 uncompress='bzip2 -d'
265 uncompress='cat'
267 esac
268 [ -e "${directory}/${package}" ] \
269 || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \
270 || die "Cannot extract package from ${ar}"
271 unset package
272 done
273 unset ar
275 for ar in $(echo_archives)
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
284 done
285 unset ar
287 echo "All prerequisites downloaded successfully."