]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/download_prerequisites
Simple patch only add assumed-rank to the list of possible attributes.
[thirdparty/gcc.git] / contrib / download_prerequisites
1 #! /bin/sh
2 #! -*- coding:utf-8; mode:shell-script; -*-
3
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.
7 #
8 # (C) 2010-2016 Free Software Foundation
9 #
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.
14 #
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.
19 #
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/.
22
23 program='download_prerequisites'
24 version='(unversioned)'
25
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.
29
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.18.tar.bz2'
34
35 base_url='http://gcc.gnu.org/pub/gcc/infrastructure/'
36
37 echo_archives() {
38 echo "${gmp}"
39 echo "${mpfr}"
40 echo "${mpc}"
41 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
42 }
43
44 graphite=1
45 verify=1
46 force=0
47 OS=$(uname)
48
49 case $OS in
50 "Darwin"|"FreeBSD"|"DragonFly")
51 chksum='shasum -a 512 --check'
52 ;;
53 *)
54 chksum='sha512sum -c'
55 ;;
56 esac
57
58 if type wget > /dev/null ; then
59 fetch='wget'
60 else
61 fetch='curl -LO'
62 fi
63 chksum_extension='sha512'
64 directory='.'
65
66 helptext="usage: ${program} [OPTION...]
67
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.
70
71 The following options are available:
72
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
86 "
87
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."
92
93 die() {
94 echo "error: $@" >&2
95 exit 1
96 }
97
98 for arg in "$@"
99 do
100 case "${arg}" in
101 --help)
102 echo "${helptext}"
103 exit
104 ;;
105 --version)
106 echo "${versiontext}"
107 exit
108 ;;
109 esac
110 done
111 unset arg
112
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"
128 }
129
130
131 argnext=
132 for arg in "$@"
133 do
134 if [ "x${argnext}" = x ]
135 then
136 case "${arg}" in
137 --directory)
138 argnext='directory'
139 ;;
140 --directory=*)
141 directory="${arg#--directory=}"
142 ;;
143 --force)
144 force=1
145 ;;
146 --no-force)
147 force=0
148 ;;
149 --isl|--graphite)
150 graphite=1
151 ;;
152 --no-isl|--no-graphite)
153 graphite=0
154 ;;
155 --verify)
156 verify=1
157 ;;
158 --no-verify)
159 verify=0
160 ;;
161 --sha512)
162 case $OS in
163 "Darwin")
164 chksum='shasum -a 512 --check'
165 ;;
166 *)
167 chksum='sha512sum --check'
168 ;;
169 esac
170 chksum_extension='sha512'
171 verify=1
172 ;;
173 --md5)
174 case $OS in
175 "Darwin")
176 chksum='md5_check'
177 ;;
178 *)
179 chksum='md5 --check'
180 ;;
181 esac
182 chksum_extension='md5'
183 verify=1
184 ;;
185 -*)
186 die "unknown option: ${arg}"
187 ;;
188 *)
189 die "too many arguments"
190 ;;
191 esac
192 else
193 case "${arg}" in
194 -*)
195 die "Missing argument for option --${argnext}"
196 ;;
197 esac
198 case "${argnext}" in
199 directory)
200 directory="${arg}"
201 ;;
202 *)
203 die "The impossible has happened"
204 ;;
205 esac
206 argnext=
207 fi
208 done
209 [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
210 unset arg argnext
211
212 [ -e ./gcc/BASE-VER ] \
213 || die "You must run this script in the top-level GCC source directory"
214
215 [ -d "${directory}" ] \
216 || die "No such directory: ${directory}"
217
218 for ar in $(echo_archives)
219 do
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
226
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)
232 do
233 grep "${ar}" "${chksumfile}" \
234 | ( cd "${directory}" && ${chksum} ) \
235 || die "Cannot verify integrity of possibly corrupted file ${ar}"
236 done
237 unset chksumfile
238 fi
239 unset ar
240
241 for ar in $(echo_archives)
242 do
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
251
252 for ar in $(echo_archives)
253 do
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
263
264 echo "All prerequisites downloaded successfully."