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'
35 base_url
='http://gcc.gnu.org/pub/gcc/infrastructure/'
41 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
49 if type wget
> /dev
/null
; then
54 chksum_extension
='sha512'
57 helptext
="usage: ${program} [OPTION...]
59 Downloads some prerequisites needed by GCC. Run this from the top level of the
60 GCC source tree and the GCC build will do the right thing.
62 The following options are available:
64 --directory=DIR download and unpack packages into DIR instead of '.'
65 --force download again overwriting existing packages
66 --no-force do not download existing packages again (default)
67 --isl download ISL, needed for Graphite loop optimizations (default)
68 --graphite same as --isl
69 --no-isl don't download ISL
70 --no-graphite same as --no-isl
71 --verify verify package integrity after download (default)
72 --no-verify don't verify package integrity
73 --sha512 use SHA512 checksum to verify package integrity (default)
74 --md5 use MD5 checksum to verify package integrity
75 --help show this text and exit
76 --version show version information and exit
79 versiontext
="${program} ${version}
80 Copyright (C) 2016-2021 Free Software Foundation, Inc.
81 This is free software; see the source for copying conditions. There is NO
82 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
104 # Emulate Linux's 'md5sum --check' on macOS
106 # Store the standard input: a line from contrib/prerequisites.md5:
107 md5_checksum_line
=$
(cat -)
108 # Grab the text before the first space
109 md5_checksum_expected
="${md5_checksum_line%% *}"
110 # Grab the text after the first space
111 file_to_check
="${md5_checksum_line##* }"
112 # Calculate the md5 checksum for the downloaded file
113 md5_checksum_output
=$
(md5
-r "${file_to_check}")
114 # Grab the text before the first space
115 md5_checksum_detected
="${md5_checksum_output%% *}"
116 [ "${md5_checksum_expected}" = "${md5_checksum_detected}" ] \
117 || die
"Cannot verify integrity of possibly corrupted file ${file_to_check}"
118 echo "${file_to_check}: OK"
125 if [ "x${argnext}" = x
]
132 directory
="${arg#--directory=}"
143 --no-isl|
--no-graphite)
153 chksum_extension
='sha512'
157 chksum_extension
='md5'
161 die
"unknown option: ${arg}"
164 die
"too many arguments"
170 die
"Missing argument for option --${argnext}"
178 die
"The impossible has happened"
184 [ "x${argnext}" = x
] || die
"Missing argument for option --${argnext}"
187 case $chksum_extension in
190 "Darwin"|
"FreeBSD"|
"DragonFly"|
"AIX")
191 chksum
='shasum -a 512 --check'
197 chksum
='sha512sum -c'
212 die
"Unkown checksum $chksum_extension"
216 [ -e .
/gcc
/BASE-VER
] \
217 || die
"You must run this script in the top-level GCC source directory"
219 [ -d "${directory}" ] \
220 || die
"No such directory: ${directory}"
222 for ar in $
(echo_archives
)
224 if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi
225 [ -e "${directory}/${ar}" ] \
226 || ( cd "${directory}" && ${fetch} --no-verbose "${base_url}${ar}" ) \
227 || die "Cannot download
${ar} from
${base_url}"
231 if [ ${verify} -gt 0 ]
233 chksumfile="contrib
/prerequisites.
${chksum_extension}"
234 [ -r "${chksumfile}" ] || die "No checksums available
"
235 for ar in $(echo_archives)
237 grep "${ar}" "${chksumfile}" \
238 | ( cd "${directory}" && ${chksum} ) \
239 || die "Cannot verify integrity of possibly corrupted
file ${ar}"
245 for ar in $(echo_archives)
247 package="${ar%.tar*}"
248 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
254 uncompress='bzip2 -d'
260 [ -e "${directory}/${package}" ] \
261 ||
( cd "${directory}" && $uncompress <"${ar}" |
tar -xf - ) \
262 || die
"Cannot extract package from ${ar}"
267 for ar in $
(echo_archives
)
269 target
="${directory}/${ar%.tar*}/"
271 if [ ${force} -gt 0 ]; then rm -f "${linkname}"; fi
272 [ -e "${linkname}" ] \
273 ||
ln -s "${target}" "${linkname}" \
274 || die
"Cannot create symbolic link ${linkname} --> ${target}"
275 unset target linkname
279 echo "All prerequisites downloaded successfully."