rs6000: Parsing built-in input file, part 3 of 3
[official-gcc.git] / contrib / download_prerequisites
blob51e715f69e1a674336bd8c7c76e5b8a3681b20c8
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 case $OS in
50 "Darwin"|"FreeBSD"|"DragonFly"|"AIX")
51 chksum='shasum -a 512 --check'
53 "OpenBSD")
54 chksum='sha512 -c'
57 chksum='sha512sum -c'
59 esac
61 if type wget > /dev/null ; then
62 fetch='wget'
63 else
64 fetch='curl -LO'
66 chksum_extension='sha512'
67 directory='.'
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."
96 die() {
97 echo "error: $@" >&2
98 exit 1
101 for arg in "$@"
103 case "${arg}" in
104 --help)
105 echo "${helptext}"
106 exit
108 --version)
109 echo "${versiontext}"
110 exit
112 esac
113 done
114 unset arg
116 # Emulate Linux's 'md5 --check' on macOS
117 md5_check() {
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"
134 argnext=
135 for arg in "$@"
137 if [ "x${argnext}" = x ]
138 then
139 case "${arg}" in
140 --directory)
141 argnext='directory'
143 --directory=*)
144 directory="${arg#--directory=}"
146 --force)
147 force=1
149 --no-force)
150 force=0
152 --isl|--graphite)
153 graphite=1
155 --no-isl|--no-graphite)
156 graphite=0
158 --verify)
159 verify=1
161 --no-verify)
162 verify=0
164 --sha512)
165 case $OS in
166 "Darwin")
167 chksum='shasum -a 512 --check'
170 chksum='sha512sum --check'
172 esac
173 chksum_extension='sha512'
174 verify=1
176 --md5)
177 case $OS in
178 "Darwin")
179 chksum='md5_check'
182 chksum='md5 --check'
184 esac
185 chksum_extension='md5'
186 verify=1
189 die "unknown option: ${arg}"
192 die "too many arguments"
194 esac
195 else
196 case "${arg}" in
198 die "Missing argument for option --${argnext}"
200 esac
201 case "${argnext}" in
202 directory)
203 directory="${arg}"
206 die "The impossible has happened"
208 esac
209 argnext=
211 done
212 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
213 unset arg 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}"
227 done
228 unset ar
230 if [ ${verify} -gt 0 ]
231 then
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}"
239 done
240 unset chksumfile
242 unset ar
244 for ar in $(echo_archives)
246 package="${ar%.tar*}"
247 if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
248 case $ar in
249 *.gz)
250 uncompress='gzip -d'
252 *.bz2)
253 uncompress='bzip2 -d'
256 uncompress='cat'
258 esac
259 [ -e "${directory}/${package}" ] \
260 || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \
261 || die "Cannot extract package from ${ar}"
262 unset package
263 done
264 unset ar
266 for ar in $(echo_archives)
268 target="${directory}/${ar%.tar*}/"
269 linkname="${ar%-*}"
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
275 done
276 unset ar
278 echo "All prerequisites downloaded successfully."