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