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-2016 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.1.0.tar.bz2'
31 mpfr
='mpfr-3.1.6.tar.bz2'
32 mpc
='mpc-1.0.3.tar.gz'
33 isl
='isl-0.18.tar.bz2'
35 base_url
='http://gcc.gnu.org/pub/gcc/infrastructure/'
41 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
50 "Darwin"|
"FreeBSD"|
"DragonFly"|
"AIX")
51 chksum
='shasum -a 512 --check'
61 if type wget
> /dev
/null
; then
66 chksum_extension
='sha512'
69 helptext
="usage: ${program} [OPTION...]
71 Downloads some prerequisites needed by GCC. Run this from the top level of the
72 GCC source tree and the GCC build will do the right thing.
74 The following options are available:
76 --directory=DIR download and unpack packages into DIR instead of '.'
77 --force download again overwriting existing packages
78 --no-force do not download existing packages again (default)
79 --isl download ISL, needed for Graphite loop optimizations (default)
80 --graphite same as --isl
81 --no-isl don't download ISL
82 --no-graphite same as --no-isl
83 --verify verify package integrity after download (default)
84 --no-verify don't verify package integrity
85 --sha512 use SHA512 checksum to verify package integrity (default)
86 --md5 use MD5 checksum to verify package integrity
87 --help show this text and exit
88 --version show version information and exit
91 versiontext
="${program} ${version}
92 Copyright (C) 2016 Free Software Foundation, Inc.
93 This is free software; see the source for copying conditions. There is NO
94 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
109 echo "${versiontext}"
116 # Emulate Linux's 'md5 --check' on macOS
118 # Store the standard input: a line from contrib/prerequisites.md5:
119 md5_checksum_line
=$
(cat -)
120 # Grab the text before the first space
121 md5_checksum_expected
="${md5_checksum_line%% *}"
122 # Grab the text after the first space
123 file_to_check
="${md5_checksum_line##* }"
124 # Calculate the md5 checksum for the downloaded file
125 md5_checksum_output
=$
(md5
-r "${file_to_check}")
126 # Grab the text before the first space
127 md5_checksum_detected
="${md5_checksum_output%% *}"
128 [ "${md5_checksum_expected}" == "${md5_checksum_detected}" ] \
129 || die
"Cannot verify integrity of possibly corrupted file ${file_to_check}"
130 echo "${file_to_check}: OK"
137 if [ "x${argnext}" = x
]
144 directory
="${arg#--directory=}"
155 --no-isl|
--no-graphite)
167 chksum
='shasum -a 512 --check'
170 chksum
='sha512sum --check'
173 chksum_extension
='sha512'
185 chksum_extension
='md5'
189 die
"unknown option: ${arg}"
192 die
"too many arguments"
198 die
"Missing argument for option --${argnext}"
206 die
"The impossible has happened"
212 [ "x${argnext}" = x
] || die
"Missing argument for option --${argnext}"
215 [ -e .
/gcc
/BASE-VER
] \
216 || die
"You must run this script in the top-level GCC source directory"
218 [ -d "${directory}" ] \
219 || die
"No such directory: ${directory}"
221 for ar in $
(echo_archives
)
223 if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi
224 [ -e "${directory}/${ar}" ] \
225 || ( cd "${directory}" && ${fetch} --no-verbose "${base_url}${ar}" ) \
226 || die "Cannot download
${ar} from
${base_url}"
230 if [ ${verify} -gt 0 ]
232 chksumfile="contrib
/prerequisites.
${chksum_extension}"
233 [ -r "${chksumfile}" ] || die "No checksums available
"
234 for ar in $(echo_archives)
236 grep "${ar}" "${chksumfile}" \
237 | ( cd "${directory}" && ${chksum} ) \
238 || die "Cannot verify integrity of possibly corrupted
file ${ar}"
244 for ar in $(echo_archives)
246 package="${ar%.tar*}"
247 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
253 uncompress='bzip2 -d'
259 [ -e "${directory}/${package}" ] \
260 ||
( cd "${directory}" && $uncompress <"${ar}" |
tar -xf - ) \
261 || die
"Cannot extract package from ${ar}"
266 for ar in $
(echo_archives
)
268 target
="${directory}/${ar%.tar*}/"
270 if [ ${force} -gt 0 ]; then rm -f "${linkname}"; fi
271 [ -e "${linkname}" ] \
272 ||
ln -s "${target}" "${linkname}" \
273 || die
"Cannot create symbolic link ${linkname} --> ${target}"
274 unset target linkname
278 echo "All prerequisites downloaded successfully."