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.18.tar.bz2'
35 base_url
='ftp://gcc.gnu.org/pub/gcc/infrastructure/'
41 if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
50 "Darwin"|
"FreeBSD"|
"DragonFly")
51 chksum
='shasum -a 512 --check'
54 chksum
='sha512sum --check'
58 if type wget
> /dev
/null
; then
61 fetch
='curl -LO -u anonymous:'
63 chksum_extension
='sha512'
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."
106 echo "${versiontext}"
113 # Emulate Linux's 'md5 --check' on macOS
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"
134 if [ "x${argnext}" = x
]
141 directory
="${arg#--directory=}"
152 --no-isl|
--no-graphite)
164 chksum
='shasum -a 512 --check'
167 chksum
='sha512sum --check'
170 chksum_extension
='sha512'
182 chksum_extension
='md5'
186 die
"unknown option: ${arg}"
189 die
"too many arguments"
195 die
"Missing argument for option --${argnext}"
203 die
"The impossible has happened"
209 [ "x${argnext}" = x
] || die
"Missing argument for option --${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}"
227 if [ ${verify} -gt 0 ]
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}"
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}"
252 for ar in $(echo_archives)
254 target="${directory}/${ar%.tar*}/"
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
264 echo "All prerequisites downloaded successfully.
"