Daily bump.
[official-gcc.git] / contrib / download_prerequisites
blob11c283ecb1aab88958915cff65109ddd5801a9e1
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-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/'
37 echo_archives() {
38 echo "${gmp}"
39 echo "${mpfr}"
40 echo "${mpc}"
41 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
44 graphite=1
45 verify=1
46 force=0
47 OS=$(uname)
49 if type wget > /dev/null ; then
50 fetch='wget'
51 else
52 fetch='curl -LO'
54 chksum_extension='sha512'
55 directory='.'
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 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."
84 die() {
85 echo "error: $@" >&2
86 exit 1
89 for arg in "$@"
91 case "${arg}" in
92 --help)
93 echo "${helptext}"
94 exit
96 --version)
97 echo "${versiontext}"
98 exit
100 esac
101 done
102 unset arg
104 # Emulate Linux's 'md5sum --check' on macOS
105 md5_check() {
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"
122 argnext=
123 for arg in "$@"
125 if [ "x${argnext}" = x ]
126 then
127 case "${arg}" in
128 --directory)
129 argnext='directory'
131 --directory=*)
132 directory="${arg#--directory=}"
134 --force)
135 force=1
137 --no-force)
138 force=0
140 --isl|--graphite)
141 graphite=1
143 --no-isl|--no-graphite)
144 graphite=0
146 --verify)
147 verify=1
149 --no-verify)
150 verify=0
152 --sha512)
153 chksum_extension='sha512'
154 verify=1
156 --md5)
157 chksum_extension='md5'
158 verify=1
161 die "unknown option: ${arg}"
164 die "too many arguments"
166 esac
167 else
168 case "${arg}" in
170 die "Missing argument for option --${argnext}"
172 esac
173 case "${argnext}" in
174 directory)
175 directory="${arg}"
178 die "The impossible has happened"
180 esac
181 argnext=
183 done
184 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
185 unset arg argnext
187 case $chksum_extension in
188 sha512)
189 case $OS in
190 "Darwin"|"FreeBSD"|"DragonFly"|"AIX")
191 chksum='shasum -a 512 --check'
193 "OpenBSD")
194 chksum='sha512 -c'
197 chksum='sha512sum -c'
199 esac
201 md5)
202 case $OS in
203 "Darwin")
204 chksum='md5_check'
207 chksum='md5sum -c'
209 esac
212 die "Unkown checksum $chksum_extension"
214 esac
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}"
228 done
229 unset ar
231 if [ ${verify} -gt 0 ]
232 then
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}"
240 done
241 unset chksumfile
243 unset ar
245 for ar in $(echo_archives)
247 package="${ar%.tar*}"
248 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
249 case $ar in
250 *.gz)
251 uncompress='gzip -d'
253 *.bz2)
254 uncompress='bzip2 -d'
257 uncompress='cat'
259 esac
260 [ -e "${directory}/${package}" ] \
261 || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \
262 || die "Cannot extract package from ${ar}"
263 unset package
264 done
265 unset ar
267 for ar in $(echo_archives)
269 target="${directory}/${ar%.tar*}/"
270 linkname="${ar%-*}"
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
276 done
277 unset ar
279 echo "All prerequisites downloaded successfully."