Update crt to latest.
[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 if test "$sigs" = "1"
39 then
40 echo "Downloading ${description} (signature) to ${dest_dir}..."
41 local curl_cmd="curl -L ${file_url}.sig -o ${dest_file}.sig --create-dirs -# ${extra_curl_opts}"
42 $curl_cmd || {
43 rm -f "${dest_file}.sig"
44 fail "ERROR: Download failed."
45 }
46 fi
47
48 if test "$verify" = "1"
49 then
50 echo "${file_md5} *${dest_file}" | md5sum --quiet -c - ||
51 fail "ERROR: ${description} appears to be corrupted, please delete it and try again."
52 fi
53 }
54
55 download_mingw() {
56 if test "$mingw_arch" = "sources"
57 then
58 local mingw_url=`echo "$1" | sed -e 's/-any\.pkg\.tar\.xz/\.src\.tar\.gz/' \
59 -e 's/-sources-/-/' \
60 -e 's/-libwinpthread-git-/-winpthreads-git-/' `
61 else
62 local mingw_url="$1"
63 fi
64 local file_md5sum_x86="$2"
65 local file_md5sum_x64="$3"
66
67 if ! test "$mingw_arch" = "sources"
68 then
69 if test "$mingw_arch" = "i686"
70 then
71 local file_md5sum="${file_md5sum_x86}"
72 else
73 local file_md5sum="${file_md5sum_x64}"
74 fi
75 fi
76
77 local mingw_toolchain="$(basename $mingw_url)"
78 local mingw_w64="${tarball_dir}/${tarball_dest_dir}/${mingw_toolchain}"
79
80 download_file "${mingw_url}" "${file_md5sum}" "${mingw_w64}" "${mingw_toolchain}"
81
82 # Mark the tree as needing updates by deleting the folder
83 if test -d inplace/mingw && test inplace/mingw -ot "$mingw_w64" ; then
84 echo "In-tree MinGW-w64 tree requires updates..."
85 rm -rf inplace/mingw
86 fi
87 }
88
89 download_tarballs() {
90 local mingw_base_url="http://repo.msys2.org/mingw"
91 local package_prefix="mingw-w64"
92 local format_url="${mingw_base_url}/${mingw_arch}/${package_prefix}-${mingw_arch}"
93
94 download_mingw "${format_url}-crt-git-5.0.0.4795.e3d96cb1-1-any.pkg.tar.xz" "534bb4756482f3271308576cdadfe5dc" "3780a25a6f20eef9b143f47f4b615e39"
95 download_mingw "${format_url}-winpthreads-git-5.0.0.4741.2c8939a-1-any.pkg.tar.xz" "155845f8c897f0c70adee83cfa9ec30c" "ba417ad9fb7cd3ee56e713b2b070adb9"
96 download_mingw "${format_url}-headers-git-5.0.0.4747.0f8f626-1-any.pkg.tar.xz" "b724d1aaae73c329022ad22374481817" "e8065928b81c9b379286515913eccd68"
97 download_mingw "${format_url}-libwinpthread-git-5.0.0.4741.2c8939a-1-any.pkg.tar.xz" "65b18b67eef3c3d5e5707577dfa8f831" "c280f60a4b80ed6722ce4d9b4f6c550e"
98 download_mingw "${format_url}-zlib-1.2.8-9-any.pkg.tar.xz" "87c65e9b2930436a75dfd7d459ae98cb" "60c3a388478f411b7a0908441ebeb537"
99 download_mingw "${format_url}-isl-0.17.1-1-any.pkg.tar.xz" "9fce16db004f00e967eb15efe0cdf86b" "39c8b3b8e56b3b0bdef86cf32f1e09ba"
100 download_mingw "${format_url}-mpc-1.0.3-2-any.pkg.tar.xz" "719e76fa7a54a8676d2e60af3bb13c45" "df1a7d4050568d83c265ae78c32ef30b"
101 download_mingw "${format_url}-mpfr-3.1.4.p3-4-any.pkg.tar.xz" "6fdad8f6a522c779932ca4e54e4d7977" "de629f78e908274086a272196c14d37c"
102 download_mingw "${format_url}-gmp-6.1.1-1-any.pkg.tar.xz" "e8cc05fc566ddc6c16266da9aec2ddd3" "0faa10641da9266ef4cb39a8f6a4fa19"
103 download_mingw "${format_url}-gcc-libs-6.2.0-2-any.pkg.tar.xz" "e6f74da9dcb856cfe9e1da0ed45732e0" "f523d52a6ad940e1cda2bf3065927bd4"
104 download_mingw "${format_url}-binutils-2.27-2-any.pkg.tar.xz" "d263d1362dee0c24df80b461eb2ec489" "b1f21340136b75f1660d6ad36bd0768a"
105 download_mingw "${format_url}-libidn-1.32-3-any.pkg.tar.xz" "9ecd264a3da0f0f6af8b392c1b183a7b" "6f68259e17b68bbf19efc7b4fb5c1968"
106 download_mingw "${format_url}-gcc-6.2.0-2-any.pkg.tar.xz" "095dc33fb7a1cab5dab982aa57713a96" "303bf95f8e6ac5bc068b2ab95749b8f3"
107
108 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"
109
110 if ! test "$missing_files" = "0"
111 then
112 exit 2
113 fi
114 }
115
116 download_i386() {
117 mingw_arch="i686"
118 tarball_dest_dir="mingw-w64/x86"
119 download_tarballs
120 }
121
122 download_x86_64() {
123 mingw_arch="x86_64"
124 tarball_dest_dir="mingw-w64/x86_64"
125 download_tarballs
126 }
127
128 download_sources() {
129 mingw_arch="sources"
130 tarball_dest_dir="mingw-w64/sources"
131 download_tarballs
132 }
133
134 usage() {
135 echo "$0 - Download GHC mingw toolchain tarballs"
136 echo
137 echo "Usage: $0 <action> <arch>"
138 echo
139 echo "Where <action> is one of,"
140 echo " download download the necessary tarballs for the given architecture"
141 echo " fetch download the necessary tarballs for the given architecture but doesn't verify their md5."d
142 echo " verify verify the existence and correctness of the necessary tarballs"
143 echo "and <arch> is one of i386, x86_64,all or mirror (which includes sources)"
144 }
145
146 case $1 in
147 download)
148 download=1
149 verify=1
150 sigs=0
151 ;;
152 fetch)
153 download=1
154 verify=0
155 ;;
156 verify)
157 download=0
158 verify=1
159 ;;
160 *)
161 usage
162 exit 1
163 ;;
164 esac
165
166 case $2 in
167 i386)
168 download_i386
169 ;;
170 x86_64)
171 download_x86_64
172 ;;
173 all)
174 download_i386
175 download_x86_64
176 ;;
177 mirror)
178 sigs=1
179 download_i386
180 download_x86_64
181 verify=0
182 download_sources
183 ;;
184 *)
185 usage
186 exit 1
187 ;;
188 esac