download_prerequisites 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #! /bin/sh
  2. #! -*- coding:utf-8; mode:shell-script; -*-
  3. # Download some prerequisites needed by GCC.
  4. # Run this from the top level of the GCC source tree and the GCC build will do
  5. # the right thing. Run it with the `--help` option for more information.
  6. #
  7. # (C) 2010-2021 Free Software Foundation
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful, but
  15. # WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. # General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see http://www.gnu.org/licenses/.
  21. program='download_prerequisites'
  22. version='(unversioned)'
  23. # MAINTAINERS: If you update the package versions below, please
  24. # remember to also update the files `contrib/prerequisites.sha512` and
  25. # `contrib/prerequisites.md5` with the new checksums.
  26. gmp='gmp-6.2.1.tar.bz2'
  27. mpfr='mpfr-4.1.0.tar.bz2'
  28. mpc='mpc-1.2.1.tar.gz'
  29. isl='isl-0.24.tar.bz2'
  30. base_url='http://gcc.gnu.org/pub/gcc/infrastructure/'
  31. echo_archives() {
  32. echo "${gmp}"
  33. echo "${mpfr}"
  34. echo "${mpc}"
  35. if [ ${graphite} -gt 0 ]; then echo "${isl}"; fi
  36. }
  37. graphite=1
  38. verify=1
  39. force=0
  40. OS=$(uname)
  41. if type wget > /dev/null ; then
  42. fetch='wget'
  43. else
  44. fetch='curl -LO'
  45. fi
  46. chksum_extension='sha512'
  47. directory='.'
  48. helptext="usage: ${program} [OPTION...]
  49. Downloads some prerequisites needed by GCC. Run this from the top level of the
  50. GCC source tree and the GCC build will do the right thing.
  51. The following options are available:
  52. --directory=DIR download and unpack packages into DIR instead of '.'
  53. --force download again overwriting existing packages
  54. --no-force do not download existing packages again (default)
  55. --isl download ISL, needed for Graphite loop optimizations (default)
  56. --graphite same as --isl
  57. --no-isl don't download ISL
  58. --no-graphite same as --no-isl
  59. --verify verify package integrity after download (default)
  60. --no-verify don't verify package integrity
  61. --sha512 use SHA512 checksum to verify package integrity (default)
  62. --md5 use MD5 checksum to verify package integrity
  63. --help show this text and exit
  64. --version show version information and exit
  65. "
  66. versiontext="${program} ${version}
  67. Copyright (C) 2016-2021 Free Software Foundation, Inc.
  68. This is free software; see the source for copying conditions. There is NO
  69. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
  70. die() {
  71. echo "error: $@" >&2
  72. exit 1
  73. }
  74. for arg in "$@"
  75. do
  76. case "${arg}" in
  77. --help)
  78. echo "${helptext}"
  79. exit
  80. ;;
  81. --version)
  82. echo "${versiontext}"
  83. exit
  84. ;;
  85. esac
  86. done
  87. unset arg
  88. # Emulate Linux's 'md5sum --check' on macOS
  89. md5_check() {
  90. # Store the standard input: a line from contrib/prerequisites.md5:
  91. md5_checksum_line=$(cat -)
  92. # Grab the text before the first space
  93. md5_checksum_expected="${md5_checksum_line%% *}"
  94. # Grab the text after the first space
  95. file_to_check="${md5_checksum_line##* }"
  96. # Calculate the md5 checksum for the downloaded file
  97. md5_checksum_output=$(md5 -r "${file_to_check}")
  98. # Grab the text before the first space
  99. md5_checksum_detected="${md5_checksum_output%% *}"
  100. [ "${md5_checksum_expected}" = "${md5_checksum_detected}" ] \
  101. || die "Cannot verify integrity of possibly corrupted file ${file_to_check}"
  102. echo "${file_to_check}: OK"
  103. }
  104. argnext=
  105. for arg in "$@"
  106. do
  107. if [ "x${argnext}" = x ]
  108. then
  109. case "${arg}" in
  110. --directory)
  111. argnext='directory'
  112. ;;
  113. --directory=*)
  114. directory="${arg#--directory=}"
  115. ;;
  116. --force)
  117. force=1
  118. ;;
  119. --no-force)
  120. force=0
  121. ;;
  122. --isl|--graphite)
  123. graphite=1
  124. ;;
  125. --no-isl|--no-graphite)
  126. graphite=0
  127. ;;
  128. --verify)
  129. verify=1
  130. ;;
  131. --no-verify)
  132. verify=0
  133. ;;
  134. --sha512)
  135. chksum_extension='sha512'
  136. verify=1
  137. ;;
  138. --md5)
  139. chksum_extension='md5'
  140. verify=1
  141. ;;
  142. -*)
  143. die "unknown option: ${arg}"
  144. ;;
  145. *)
  146. die "too many arguments"
  147. ;;
  148. esac
  149. else
  150. case "${arg}" in
  151. -*)
  152. die "Missing argument for option --${argnext}"
  153. ;;
  154. esac
  155. case "${argnext}" in
  156. directory)
  157. directory="${arg}"
  158. ;;
  159. *)
  160. die "The impossible has happened"
  161. ;;
  162. esac
  163. argnext=
  164. fi
  165. done
  166. [ "x${argnext}" = x ] || die "Missing argument for option --${argnext}"
  167. unset arg argnext
  168. case $chksum_extension in
  169. sha512)
  170. case $OS in
  171. "Darwin"|"FreeBSD"|"DragonFly"|"AIX")
  172. chksum='shasum -a 512 --check'
  173. ;;
  174. "OpenBSD")
  175. chksum='sha512 -c'
  176. ;;
  177. *)
  178. chksum='sha512sum -c'
  179. ;;
  180. esac
  181. ;;
  182. md5)
  183. case $OS in
  184. "Darwin")
  185. chksum='md5_check'
  186. ;;
  187. *)
  188. chksum='md5sum -c'
  189. ;;
  190. esac
  191. ;;
  192. *)
  193. die "Unkown checksum $chksum_extension"
  194. ;;
  195. esac
  196. [ -e ./gcc/BASE-VER ] \
  197. || die "You must run this script in the top-level GCC source directory"
  198. [ -d "${directory}" ] \
  199. || die "No such directory: ${directory}"
  200. for ar in $(echo_archives)
  201. do
  202. if [ ${force} -gt 0 ]; then rm -f "${directory}/${ar}"; fi
  203. [ -e "${directory}/${ar}" ] \
  204. || ( cd "${directory}" && ${fetch} --no-verbose "${base_url}${ar}" ) \
  205. || die "Cannot download ${ar} from ${base_url}"
  206. done
  207. unset ar
  208. if [ ${verify} -gt 0 ]
  209. then
  210. chksumfile="contrib/prerequisites.${chksum_extension}"
  211. [ -r "${chksumfile}" ] || die "No checksums available"
  212. for ar in $(echo_archives)
  213. do
  214. grep "${ar}" "${chksumfile}" \
  215. | ( cd "${directory}" && ${chksum} ) \
  216. || die "Cannot verify integrity of possibly corrupted file ${ar}"
  217. done
  218. unset chksumfile
  219. fi
  220. unset ar
  221. for ar in $(echo_archives)
  222. do
  223. package="${ar%.tar*}"
  224. if [ ${force} -gt 0 ]; then rm -rf "${directory}/${package}"; fi
  225. case $ar in
  226. *.gz)
  227. uncompress='gzip -d'
  228. ;;
  229. *.bz2)
  230. uncompress='bzip2 -d'
  231. ;;
  232. *)
  233. uncompress='cat'
  234. ;;
  235. esac
  236. [ -e "${directory}/${package}" ] \
  237. || ( cd "${directory}" && $uncompress <"${ar}" | tar -xf - ) \
  238. || die "Cannot extract package from ${ar}"
  239. unset package
  240. done
  241. unset ar
  242. for ar in $(echo_archives)
  243. do
  244. target="${directory}/${ar%.tar*}/"
  245. linkname="${ar%-*}"
  246. if [ ${force} -gt 0 ]; then rm -f "${linkname}"; fi
  247. [ -e "${linkname}" ] \
  248. || ln -s "${target}" "${linkname}" \
  249. || die "Cannot create symbolic link ${linkname} --> ${target}"
  250. unset target linkname
  251. done
  252. unset ar
  253. echo "All prerequisites downloaded successfully."