]>
Commit | Line | Data |
---|---|---|
69baf0a3 | 1 | #! /bin/sh |
38000825 | 2 | #! -*- coding:utf-8; mode:shell-script; -*- |
69baf0a3 | 3 | |
38000825 MK |
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. | |
69baf0a3 | 7 | # |
00f35794 | 8 | # (C) 2010-2016 Free Software Foundation |
69baf0a3 AH |
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 | ||
38000825 MK |
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' | |
37026b57 | 33 | isl='isl-0.18.tar.bz2' |
38000825 | 34 | |
d51dd316 | 35 | base_url='http://gcc.gnu.org/pub/gcc/infrastructure/' |
38000825 MK |
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 | |
b1c0468f DR |
47 | OS=$(uname) |
48 | ||
49 | case $OS in | |
796190e5 | 50 | "Darwin"|"FreeBSD"|"DragonFly"|"AIX") |
b1c0468f DR |
51 | chksum='shasum -a 512 --check' |
52 | ;; | |
796190e5 IL |
53 | "OpenBSD") |
54 | chksum='sha512 -c' | |
55 | ;; | |
b1c0468f | 56 | *) |
6f8fc6f9 | 57 | chksum='sha512sum -c' |
b1c0468f DR |
58 | ;; |
59 | esac | |
60 | ||
61 | if type wget > /dev/null ; then | |
62 | fetch='wget' | |
63 | else | |
d51dd316 | 64 | fetch='curl -LO' |
b1c0468f DR |
65 | fi |
66 | chksum_extension='sha512' | |
38000825 MK |
67 | directory='.' |
68 | ||
69 | helptext="usage: ${program} [OPTION...] | |
70 | ||
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. | |
73 | ||
74 | The following options are available: | |
75 | ||
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 | |
89 | " | |
78c56a5a | 90 | |
38000825 MK |
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." | |
95 | ||
96 | die() { | |
97 | echo "error: $@" >&2 | |
98 | exit 1 | |
99 | } | |
100 | ||
101 | for arg in "$@" | |
102 | do | |
103 | case "${arg}" in | |
104 | --help) | |
105 | echo "${helptext}" | |
106 | exit | |
107 | ;; | |
108 | --version) | |
109 | echo "${versiontext}" | |
110 | exit | |
111 | ;; | |
112 | esac | |
113 | done | |
114 | unset arg | |
115 | ||
b1c0468f DR |
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" | |
131 | } | |
132 | ||
133 | ||
38000825 MK |
134 | argnext= |
135 | for arg in "$@" | |
136 | do | |
137 | if [ "x${argnext}" = x ] | |
138 | then | |
139 | case "${arg}" in | |
140 | --directory) | |
141 | argnext='directory' | |
142 | ;; | |
143 | --directory=*) | |
144 | directory="${arg#--directory=}" | |
145 | ;; | |
146 | --force) | |
147 | force=1 | |
148 | ;; | |
149 | --no-force) | |
150 | force=0 | |
151 | ;; | |
152 | --isl|--graphite) | |
153 | graphite=1 | |
154 | ;; | |
155 | --no-isl|--no-graphite) | |
156 | graphite=0 | |
157 | ;; | |
158 | --verify) | |
159 | verify=1 | |
160 | ;; | |
161 | --no-verify) | |
162 | verify=0 | |
163 | ;; | |
164 | --sha512) | |
b1c0468f DR |
165 | case $OS in |
166 | "Darwin") | |
167 | chksum='shasum -a 512 --check' | |
168 | ;; | |
169 | *) | |
170 | chksum='sha512sum --check' | |
171 | ;; | |
172 | esac | |
173 | chksum_extension='sha512' | |
38000825 MK |
174 | verify=1 |
175 | ;; | |
176 | --md5) | |
b1c0468f DR |
177 | case $OS in |
178 | "Darwin") | |
179 | chksum='md5_check' | |
180 | ;; | |
181 | *) | |
182 | chksum='md5 --check' | |
183 | ;; | |
184 | esac | |
185 | chksum_extension='md5' | |
38000825 MK |
186 | verify=1 |
187 | ;; | |
188 | -*) | |
189 | die "unknown option: ${arg}" | |
190 | ;; | |
191 | *) | |
192 | die "too many arguments" | |
193 | ;; | |
194 | esac | |
195 | else | |
196 | case "${arg}" in | |
197 | -*) | |
198 | die "Missing argument for option --${argnext}" | |
199 | ;; | |
200 | esac | |
201 | case "${argnext}" in | |
202 | directory) | |
203 | directory="${arg}" | |
204 | ;; | |
205 | *) | |
206 | die "The impossible has happened" | |
207 | ;; | |
208 | esac | |
209 | argnext= | |
210 | fi | |
211 | done | |
212 | [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}" | |
213 | unset arg argnext | |
214 | ||
215 | [ -e ./gcc/BASE-VER ] \ | |
216 | || die "You must run this script in the top-level GCC source directory" | |
217 | ||
218 | [ -d "${directory}" ] \ | |
219 | || die "No such directory: ${directory}" | |
220 | ||
221 | for ar in $(echo_archives) | |
222 | do | |
223 | if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi | |
224 | [ -e "${directory}/${ar}" ] \ | |
b1c0468f | 225 | || ${fetch} --no-verbose -O "${directory}/${ar}" "${base_url}${ar}" \ |
38000825 MK |
226 | || die "Cannot download ${ar} from ${base_url}" |
227 | done | |
228 | unset ar | |
229 | ||
230 | if [ ${verify} -gt 0 ] | |
231 | then | |
b1c0468f | 232 | chksumfile="contrib/prerequisites.${chksum_extension}" |
38000825 MK |
233 | [ -r "${chksumfile}" ] || die "No checksums available" |
234 | for ar in $(echo_archives) | |
235 | do | |
236 | grep "${ar}" "${chksumfile}" \ | |
b1c0468f | 237 | | ( cd "${directory}" && ${chksum} ) \ |
38000825 MK |
238 | || die "Cannot verify integrity of possibly corrupted file ${ar}" |
239 | done | |
240 | unset chksumfile | |
a8db5990 | 241 | fi |
38000825 MK |
242 | unset ar |
243 | ||
244 | for ar in $(echo_archives) | |
245 | do | |
246 | package="${ar%.tar*}" | |
247 | if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi | |
796190e5 IL |
248 | case $ar in |
249 | *.gz) | |
250 | uncompress='gzip -d' | |
251 | ;; | |
252 | *.bz2) | |
253 | uncompress='bzip2 -d' | |
254 | ;; | |
255 | *) | |
256 | uncompress='cat' | |
257 | ;; | |
258 | esac | |
38000825 | 259 | [ -e "${directory}/${package}" ] \ |
796190e5 | 260 | || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \ |
38000825 MK |
261 | || die "Cannot extract package from ${ar}" |
262 | unset package | |
263 | done | |
264 | unset ar | |
265 | ||
266 | for ar in $(echo_archives) | |
267 | do | |
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 | |
277 | ||
278 | echo "All prerequisites downloaded successfully." |