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/'
43 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
51 if type wget
> /dev
/null
; then
56 chksum_extension
='sha512'
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."
106 # Emulate Linux's 'md5sum --check' on macOS
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"
127 if [ "x${argnext}" = x
]
134 directory
="${arg#--directory=}"
145 --no-isl|
--no-graphite)
155 chksum_extension
='sha512'
159 chksum_extension
='md5'
163 die
"unknown option: ${arg}"
166 die
"too many arguments"
172 die
"Missing argument for option --${argnext}"
180 die
"The impossible has happened"
186 [ "x${argnext}" = x
] || die
"Missing argument for option --${argnext}"
189 case $chksum_extension in
192 "Darwin"|
"FreeBSD"|
"DragonFly"|
"AIX")
193 chksum
='shasum -a 512 --check'
199 chksum
='sha512sum -c'
214 die
"Unkown checksum $chksum_extension"
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}"
233 if [ ${verify} -gt 0 ]
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}"
247 for ar in $(echo_archives)
249 package="${ar%.tar*}"
250 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
256 uncompress='bzip2 -d'
262 [ -e "${directory}/${package}" ] \
263 ||
( cd "${directory}" && $uncompress <"${ar}" |
tar -xf - ) \
264 || die
"Cannot extract package from ${ar}"
269 for ar in $
(echo_archives
)
271 target
="${directory}/${ar%.tar*}/"
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
281 echo "All prerequisites downloaded successfully."