hppa: Fix g++.dg/modules/bad-mapper-1.C on hpux
[official-gcc.git] / contrib / download_prerequisites
blob9568091c0dbaced1be8874caa2e0c10657b8638b
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 "${gmp}"
40 echo "${mpfr}"
41 echo "${mpc}"
42 echo "${gettext}"
43 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
46 graphite=1
47 verify=1
48 force=0
49 OS=$(uname)
51 if type wget > /dev/null ; then
52 fetch='wget'
53 else
54 fetch='curl -LO'
56 chksum_extension='sha512'
57 directory='.'
59 helptext="usage: ${program} [OPTION...]
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.
64 The following options are available:
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
81 versiontext="${program} ${version}
82 Copyright (C) 2016-2023 Free Software Foundation, Inc.
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."
86 die() {
87 echo "error: $@" >&2
88 exit 1
91 for arg in "$@"
93 case "${arg}" in
94 --help)
95 echo "${helptext}"
96 exit
98 --version)
99 echo "${versiontext}"
100 exit
102 esac
103 done
104 unset arg
106 # Emulate Linux's 'md5sum --check' on macOS
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%% *}"
118 [ "${md5_checksum_expected}" = "${md5_checksum_detected}" ] \
119 || die "Cannot verify integrity of possibly corrupted file ${file_to_check}"
120 echo "${file_to_check}: OK"
124 argnext=
125 for arg in "$@"
127 if [ "x${argnext}" = x ]
128 then
129 case "${arg}" in
130 --directory)
131 argnext='directory'
133 --directory=*)
134 directory="${arg#--directory=}"
136 --force)
137 force=1
139 --no-force)
140 force=0
142 --isl|--graphite)
143 graphite=1
145 --no-isl|--no-graphite)
146 graphite=0
148 --verify)
149 verify=1
151 --no-verify)
152 verify=0
154 --sha512)
155 chksum_extension='sha512'
156 verify=1
158 --md5)
159 chksum_extension='md5'
160 verify=1
163 die "unknown option: ${arg}"
166 die "too many arguments"
168 esac
169 else
170 case "${arg}" in
172 die "Missing argument for option --${argnext}"
174 esac
175 case "${argnext}" in
176 directory)
177 directory="${arg}"
180 die "The impossible has happened"
182 esac
183 argnext=
185 done
186 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
187 unset arg argnext
189 case $chksum_extension in
190 sha512)
191 case $OS in
192 "Darwin"|"FreeBSD"|"DragonFly"|"AIX")
193 chksum='shasum -a 512 --check'
195 "OpenBSD")
196 chksum='sha512 -c'
199 chksum='sha512sum -c'
201 esac
203 md5)
204 case $OS in
205 "Darwin")
206 chksum='md5_check'
209 chksum='md5sum -c'
211 esac
214 die "Unkown checksum $chksum_extension"
216 esac
218 [ -e ./gcc/BASE-VER ] \
219 || die "You must run this script in the top-level GCC source directory"
221 [ -d "${directory}" ] \
222 || die "No such directory: ${directory}"
224 for ar in $(echo_archives)
226 if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi
227 [ -e "${directory}/${ar}" ] \
228 || ( cd "${directory}" && ${fetch} --no-verbose "${base_url}${ar}" ) \
229 || die "Cannot download ${ar} from ${base_url}"
230 done
231 unset ar
233 if [ ${verify} -gt 0 ]
234 then
235 chksumfile="contrib/prerequisites.${chksum_extension}"
236 [ -r "${chksumfile}" ] || die "No checksums available"
237 for ar in $(echo_archives)
239 grep "${ar}" "${chksumfile}" \
240 | ( cd "${directory}" && ${chksum} ) \
241 || die "Cannot verify integrity of possibly corrupted file ${ar}"
242 done
243 unset chksumfile
245 unset ar
247 for ar in $(echo_archives)
249 package="${ar%.tar*}"
250 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
251 case $ar in
252 *.gz)
253 uncompress='gzip -d'
255 *.bz2)
256 uncompress='bzip2 -d'
259 uncompress='cat'
261 esac
262 [ -e "${directory}/${package}" ] \
263 || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \
264 || die "Cannot extract package from ${ar}"
265 unset package
266 done
267 unset ar
269 for ar in $(echo_archives)
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
281 echo "All prerequisites downloaded successfully."