Check for empty entity string in "prim" foreign imports
[ghc.git] / mk / get-win32-tarballs.sh
1 #!/usr/bin/env sh
2
3 tarball_dir='ghc-tarballs'
4 missing_files=0
5
6 fail() {
7 echo >&2
8 echo "$1" >&2
9 exit 1
10 }
11
12 download_file() {
13 local file_url="$1"
14 local file_md5="$2"
15 local dest_file="$3"
16 local description="$4"
17 local extra_curl_opts="$5"
18 local dest_dir="$(dirname $dest_file)"
19
20 if ! test -f "${dest_file}"
21 then
22 local curl_cmd="curl -L ${file_url} -o ${dest_file} --create-dirs -# ${extra_curl_opts}"
23 if test "$download" = "0"
24 then
25 echo "ERROR: Missing ${description}" >&2
26 echo "${file_url}"
27 missing_files=1
28 return
29 else
30 echo "Downloading ${description} to ${dest_dir}..."
31 $curl_cmd || {
32 rm -f "${dest_file}"
33 fail "ERROR: Download failed."
34 }
35 fi
36 fi
37
38 echo "${file_md5} *${dest_file}" | md5sum --quiet -c - ||
39 fail "ERROR: ${description} appears to be corrupted, please delete it and try again."
40 }
41
42 download_mingw() {
43 local mingw_url="$1"
44 local file_md5sum_x86="$2"
45 local file_md5sum_x64="$3"
46
47 if test "$mingw_arch" = "i686"
48 then
49 local file_md5sum="${file_md5sum_x86}"
50 else
51 local file_md5sum="${file_md5sum_x64}"
52 fi
53
54 local mingw_toolchain="$(basename $mingw_url)"
55 local mingw_w64="${tarball_dir}/${tarball_dest_dir}/${mingw_toolchain}"
56
57 download_file "${mingw_url}" "${file_md5sum}" "${mingw_w64}" "${mingw_toolchain}"
58
59 # Mark the tree as needing updates by deleting the folder
60 if test -d inplace/mingw && test inplace/mingw -ot "$mingw_w64" ; then
61 echo "In-tree MinGW-w64 tree requires updates..."
62 rm -rf inplace/mingw
63 fi
64 }
65
66 download_tarballs() {
67 local mingw_base_url="https://downloads.haskell.org/~ghc/mingw"
68 local package_prefix="mingw-w64"
69 local format_url="${mingw_base_url}/${mingw_arch}/${package_prefix}-${mingw_arch}"
70
71 download_mingw "${format_url}-crt-git-5.0.0.4531.49c7046-1-any.pkg.tar.xz" "dd39323140c0c1b3e065e9edb1a66779" "ac22cedd38229bcd57f5999e4734054f"
72 download_mingw "${format_url}-winpthreads-git-5.0.0.4538.78dca70-1-any.pkg.tar.xz" "0b14fe27790e94db454fbb3564e79a73" "65cf07b6f42a1a62d1844e08190cab0d"
73 download_mingw "${format_url}-headers-git-5.0.0.4531.49c7046-1-any.pkg.tar.xz" "6ee9e3c2f9d3e507f60ee33d19417dc2" "f49a19cdea93998c33ac90ceb9570350"
74 download_mingw "${format_url}-libwinpthread-git-5.0.0.4538.78dca70-1-any.pkg.tar.xz" "fbb2114aa7fbb5507e21d8a2ea265cfd" "31ed10e2d8891f6251d968f81bfdd274"
75 download_mingw "${format_url}-zlib-1.2.8-8-any.pkg.tar.xz" "7f519cb6defa27a90c5353160cf088d4" "6a2f4a70ccb24acca70a01da331699a6"
76 download_mingw "${format_url}-isl-0.14.1-2-any.pkg.tar.xz" "4cd20fe75ed9ef03e260d529042cb742" "dc0e0a7fd23a8193cccb0bf8d7267685"
77 download_mingw "${format_url}-mpc-1.0.3-2-any.pkg.tar.xz" "719e76fa7a54a8676d2e60af3bb13c45" "df1a7d4050568d83c265ae78c32ef30b"
78 download_mingw "${format_url}-mpfr-3.1.3.p0-2-any.pkg.tar.xz" "e9cbd2402ac1afe6e86c102223b90dcb" "6e3b9ec27edab394aa41536839afdafe"
79 download_mingw "${format_url}-gmp-6.0.0-3-any.pkg.tar.xz" "c02f9759cd0140a6d8ea69ef5a88e167" "2970d4d8b176f8f36ae2d39269b25cce"
80 download_mingw "${format_url}-gcc-libs-5.2.0-3-any.pkg.tar.xz" "a9bd2e65cb350cc8f8a6deb6d3b346a8" "9c2ed24989e14fdf0c548a5215374660"
81 download_mingw "${format_url}-binutils-2.25.1-1-any.pkg.tar.xz" "997e9c2166fb851916cd8ac1bc9c6180" "7cb9f5f50a7103da41f7ec7547c09707"
82 download_mingw "${format_url}-libiconv-1.14-5-any.pkg.tar.xz" "2c99a163689ba8257627bb07274b3f86" "37418c6be92ef20be17cdc9fe844af35"
83 download_mingw "${format_url}-gcc-5.2.0-3-any.pkg.tar.xz" "efe6d6afc18aab89dc01e7ddcd2523a6" "0b697ce61112ba6e5a3c4d565957ea4e"
84
85 download_file "https://github.com/ghc/ghc-tarballs/blob/master/perl/ghc-perl-1.tar.gz?raw=true" "b21d1681b61cf7a024e854096285b02e" "ghc-tarballs/perl/ghc-perl-1.tar.gz" "Windows Perl binary distributions" "--insecure"
86
87 if ! test "$missing_files" = "0"
88 then
89 exit 2
90 fi
91 }
92
93 download_i386() {
94 mingw_arch="i686"
95 tarball_dest_dir="mingw-w64/x86"
96 download_tarballs
97 }
98
99 download_x86_64() {
100 mingw_arch="x86_64"
101 tarball_dest_dir="mingw-w64/x86_64"
102 download_tarballs
103 }
104
105 usage() {
106 echo "$0 - Download GHC mingw toolchain tarballs"
107 echo
108 echo "Usage: $0 <action> <arch>"
109 echo
110 echo "Where <action> is one of,"
111 echo " download download the necessary tarballs for the given architecture"
112 echo " verify verify the existance and correctness of the necessary tarballs"
113 echo "and <arch> is one of i386, x86_64, or all"
114 }
115
116 case $1 in
117 download)
118 download=1
119 ;;
120 verify)
121 download=0
122 ;;
123 *)
124 usage
125 exit 1
126 ;;
127 esac
128
129 case $2 in
130 i386)
131 download_i386
132 ;;
133 x86_64)
134 download_x86_64
135 ;;
136 all)
137 download_i386
138 download_x86_64
139 ;;
140 *)
141 usage
142 exit 1
143 ;;
144 esac