]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/download_prerequisites
RISC-V: Postpone full available optimization [VSETVL PASS]
[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() {
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
46graphite=1
47verify=1
48force=0
b1c0468f
DR
49OS=$(uname)
50
b1c0468f
DR
51if type wget > /dev/null ; then
52 fetch='wget'
53else
d51dd316 54 fetch='curl -LO'
b1c0468f
DR
55fi
56chksum_extension='sha512'
38000825
MK
57directory='.'
58
59helptext="usage: ${program} [OPTION...]
60
61Downloads some prerequisites needed by GCC. Run this from the top level of the
62GCC source tree and the GCC build will do the right thing.
63
64The 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 81versiontext="${program} ${version}
83ffe9cd 82Copyright (C) 2016-2023 Free Software Foundation, Inc.
38000825
MK
83This is free software; see the source for copying conditions. There is NO
84warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
85
86die() {
87 echo "error: $@" >&2
88 exit 1
89}
90
91for arg in "$@"
92do
93 case "${arg}" in
94 --help)
95 echo "${helptext}"
96 exit
97 ;;
98 --version)
99 echo "${versiontext}"
100 exit
101 ;;
102 esac
103done
104unset arg
105
0deabebe 106# Emulate Linux's 'md5sum --check' on macOS
b1c0468f
DR
107md5_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
124argnext=
125for arg in "$@"
126do
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
185done
186[ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
187unset arg argnext
188
0deabebe
AP
189case $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 ;;
216esac
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
224for ar in $(echo_archives)
225do
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}"
230done
231unset ar
232
233if [ ${verify} -gt 0 ]
234then
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 244fi
38000825
MK
245unset ar
246
247for ar in $(echo_archives)
248do
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
266done
267unset ar
268
269for ar in $(echo_archives)
270do
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
278done
279unset ar
280
281echo "All prerequisites downloaded successfully."