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/'
40 if "${only_gettext}"; then return; fi
44 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
53 if type wget
> /dev
/null
; then
58 chksum_extension
='sha512'
61 helptext
="usage: ${program} [OPTION...]
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.
66 The following options are available:
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
84 versiontext
="${program} ${version}
85 Copyright (C) 2016-2023 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."
102 echo "${versiontext}"
109 # Emulate Linux's 'md5sum --check' on macOS
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"
130 if [ "x${argnext}" = x
]
137 directory
="${arg#--directory=}"
148 --no-isl|
--no-graphite)
158 chksum_extension
='sha512'
162 chksum_extension
='md5'
169 die
"unknown option: ${arg}"
172 die
"too many arguments"
178 die
"Missing argument for option --${argnext}"
186 die
"The impossible has happened"
192 [ "x${argnext}" = x
] || die
"Missing argument for option --${argnext}"
195 case $chksum_extension in
198 "Darwin"|
"FreeBSD"|
"DragonFly"|
"AIX")
199 chksum
='shasum -a 512 --check'
205 chksum
='sha512sum -c'
220 die
"Unkown checksum $chksum_extension"
224 [ -e .
/gcc
/BASE-VER
] \
225 || die
"You must run this script in the top-level GCC source directory"
227 [ -d "${directory}" ] \
228 || die
"No such directory: ${directory}"
230 for ar in $
(echo_archives
)
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}"
239 if [ ${verify} -gt 0 ]
241 chksumfile="contrib
/prerequisites.
${chksum_extension}"
242 [ -r "${chksumfile}" ] || die "No checksums available
"
243 for ar in $(echo_archives)
245 grep "${ar}" "${chksumfile}" \
246 | ( cd "${directory}" && ${chksum} ) \
247 || die "Cannot verify integrity of possibly corrupted
file ${ar}"
253 for ar in $(echo_archives)
255 package="${ar%.tar*}"
256 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
262 uncompress='bzip2 -d'
268 [ -e "${directory}/${package}" ] \
269 ||
( cd "${directory}" && $uncompress <"${ar}" |
tar -xf - ) \
270 || die
"Cannot extract package from ${ar}"
275 for ar in $
(echo_archives
)
277 target
="${directory}/${ar%.tar*}/"
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
287 echo "All prerequisites downloaded successfully."