]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/download_prerequisites
c++/modules: Improve diagnostic when redeclaring builtin in module [PR102345]
[thirdparty/gcc.git] / contrib / download_prerequisites
1 #! /bin/sh
2 #! -*- coding:utf-8; mode:shell-script; -*-
3
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.
7 #
8 # (C) 2010-2021 Free Software Foundation
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
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
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'
35
36 base_url='http://gcc.gnu.org/pub/gcc/infrastructure/'
37
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
45 }
46
47 graphite=1
48 verify=1
49 force=0
50 only_gettext=false
51 OS=$(uname)
52
53 if type wget > /dev/null ; then
54 fetch='wget'
55 else
56 fetch='curl -LO'
57 fi
58 chksum_extension='sha512'
59 directory='.'
60
61 helptext="usage: ${program} [OPTION...]
62
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.
65
66 The 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
79 --only-gettext inhibit downloading any package but gettext
80 --help show this text and exit
81 --version show version information and exit
82 "
83
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."
88
89 die() {
90 echo "error: $@" >&2
91 exit 1
92 }
93
94 for arg in "$@"
95 do
96 case "${arg}" in
97 --help)
98 echo "${helptext}"
99 exit
100 ;;
101 --version)
102 echo "${versiontext}"
103 exit
104 ;;
105 esac
106 done
107 unset arg
108
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"
124 }
125
126
127 argnext=
128 for arg in "$@"
129 do
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)
158 chksum_extension='sha512'
159 verify=1
160 ;;
161 --md5)
162 chksum_extension='md5'
163 verify=1
164 ;;
165 --only-gettext)
166 only_gettext=true
167 ;;
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
191 done
192 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
193 unset arg argnext
194
195 case $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 ;;
222 esac
223
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
230 for ar in $(echo_archives)
231 do
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
238
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)
244 do
245 grep "${ar}" "${chksumfile}" \
246 | ( cd "${directory}" && ${chksum} ) \
247 || die "Cannot verify integrity of possibly corrupted file ${ar}"
248 done
249 unset chksumfile
250 fi
251 unset ar
252
253 for ar in $(echo_archives)
254 do
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'
260 ;;
261 *.bz2)
262 uncompress='bzip2 -d'
263 ;;
264 *)
265 uncompress='cat'
266 ;;
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
274
275 for ar in $(echo_archives)
276 do
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
286
287 echo "All prerequisites downloaded successfully."