Fix std::wbuffer_convert::sync()
[official-gcc.git] / contrib / download_prerequisites
blob3430ce1f19e3235b4dc98960b858238bc754ad53
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.4.tar.bz2'
32 mpc='mpc-1.0.3.tar.gz'
33 isl='isl-0.16.1.tar.bz2'
35 base_url='ftp://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 case $OS in
50 "Darwin")
51 chksum='shasum -a 512 --check'
54 chksum='sha512sum --check'
56 esac
58 if type wget > /dev/null ; then
59 fetch='wget'
60 else
61 fetch='curl -LO -u anonymous:'
63 chksum_extension='sha512'
64 directory='.'
66 helptext="usage: ${program} [OPTION...]
68 Downloads some prerequisites needed by GCC. Run this from the top level of the
69 GCC source tree and the GCC build will do the right thing.
71 The following options are available:
73 --directory=DIR download and unpack packages into DIR instead of '.'
74 --force download again overwriting existing packages
75 --no-force do not download existing packages again (default)
76 --isl download ISL, needed for Graphite loop optimizations (default)
77 --graphite same as --isl
78 --no-isl don't download ISL
79 --no-graphite same as --no-isl
80 --verify verify package integrity after download (default)
81 --no-verify don't verify package integrity
82 --sha512 use SHA512 checksum to verify package integrity (default)
83 --md5 use MD5 checksum to verify package integrity
84 --help show this text and exit
85 --version show version information and exit
88 versiontext="${program} ${version}
89 Copyright (C) 2016 Free Software Foundation, Inc.
90 This is free software; see the source for copying conditions. There is NO
91 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
93 die() {
94 echo "error: $@" >&2
95 exit 1
98 for arg in "$@"
100 case "${arg}" in
101 --help)
102 echo "${helptext}"
103 exit
105 --version)
106 echo "${versiontext}"
107 exit
109 esac
110 done
111 unset arg
113 # Emulate Linux's 'md5 --check' on macOS
114 md5_check() {
115 # Store the standard input: a line from contrib/prerequisites.md5:
116 md5_checksum_line=$(cat -)
117 # Grab the text before the first space
118 md5_checksum_expected="${md5_checksum_line%% *}"
119 # Grab the text after the first space
120 file_to_check="${md5_checksum_line##* }"
121 # Calculate the md5 checksum for the downloaded file
122 md5_checksum_output=$(md5 -r "${file_to_check}")
123 # Grab the text before the first space
124 md5_checksum_detected="${md5_checksum_output%% *}"
125 [ "${md5_checksum_expected}" == "${md5_checksum_detected}" ] \
126 || die "Cannot verify integrity of possibly corrupted file ${file_to_check}"
127 echo "${file_to_check}: OK"
131 argnext=
132 for arg in "$@"
134 if [ "x${argnext}" = x ]
135 then
136 case "${arg}" in
137 --directory)
138 argnext='directory'
140 --directory=*)
141 directory="${arg#--directory=}"
143 --force)
144 force=1
146 --no-force)
147 force=0
149 --isl|--graphite)
150 graphite=1
152 --no-isl|--no-graphite)
153 graphite=0
155 --verify)
156 verify=1
158 --no-verify)
159 verify=0
161 --sha512)
162 case $OS in
163 "Darwin")
164 chksum='shasum -a 512 --check'
167 chksum='sha512sum --check'
169 esac
170 chksum_extension='sha512'
171 verify=1
173 --md5)
174 case $OS in
175 "Darwin")
176 chksum='md5_check'
179 chksum='md5 --check'
181 esac
182 chksum_extension='md5'
183 verify=1
186 die "unknown option: ${arg}"
189 die "too many arguments"
191 esac
192 else
193 case "${arg}" in
195 die "Missing argument for option --${argnext}"
197 esac
198 case "${argnext}" in
199 directory)
200 directory="${arg}"
203 die "The impossible has happened"
205 esac
206 argnext=
208 done
209 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
210 unset arg argnext
212 [ -e ./gcc/BASE-VER ] \
213 || die "You must run this script in the top-level GCC source directory"
215 [ -d "${directory}" ] \
216 || die "No such directory: ${directory}"
218 for ar in $(echo_archives)
220 if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi
221 [ -e "${directory}/${ar}" ] \
222 || ${fetch} --no-verbose -O "${directory}/${ar}" "${base_url}${ar}" \
223 || die "Cannot download ${ar} from ${base_url}"
224 done
225 unset ar
227 if [ ${verify} -gt 0 ]
228 then
229 chksumfile="contrib/prerequisites.${chksum_extension}"
230 [ -r "${chksumfile}" ] || die "No checksums available"
231 for ar in $(echo_archives)
233 grep "${ar}" "${chksumfile}" \
234 | ( cd "${directory}" && ${chksum} ) \
235 || die "Cannot verify integrity of possibly corrupted file ${ar}"
236 done
237 unset chksumfile
239 unset ar
241 for ar in $(echo_archives)
243 package="${ar%.tar*}"
244 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
245 [ -e "${directory}/${package}" ] \
246 || ( cd "${directory}" && tar -xf "${ar}" ) \
247 || die "Cannot extract package from ${ar}"
248 unset package
249 done
250 unset ar
252 for ar in $(echo_archives)
254 target="${directory}/${ar%.tar*}/"
255 linkname="${ar%-*}"
256 if [ ${force} -gt 0 ]; then rm -f "${linkname}"; fi
257 [ -e "${linkname}" ] \
258 || ln -s "${target}" "${linkname}" \
259 || die "Cannot create symbolic link ${linkname} --> ${target}"
260 unset target linkname
261 done
262 unset ar
264 echo "All prerequisites downloaded successfully."