get-win32-tarballs: More reworking of tarball maintenance
[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 dest_file="$2"
15 local description="$3"
16 local extra_curl_opts="$4"
17 local dest_dir="$(dirname $dest_file)"
18
19 if ! test -f "${dest_file}"
20 then
21 local curl_cmd="curl -L ${file_url} -o ${dest_file} --create-dirs -# ${extra_curl_opts}"
22 if test "$download" = "0"
23 then
24 echo "ERROR: Missing ${description}" >&2
25 echo "${file_url}"
26 missing_files=1
27 return
28 else
29 echo "Downloading ${description} to ${dest_dir}..."
30 $curl_cmd || {
31 rm -f "${dest_file}"
32 fail "ERROR: Download failed."
33 }
34 fi
35 fi
36
37 local sig_file="${dest_file}.sig"
38 if test "$sigs" = "1" -a ! -f "$sig_file"
39 then
40 echo "Downloading ${description} (signature) to ${dest_dir}..."
41 local curl_cmd="curl -L ${file_url}.sig -o ${sig_file} --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 grep "${dest_file}$" mk/win32-tarballs.md5sum | 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
65 local mingw_toolchain="$(basename $mingw_url)"
66 local mingw_w64="${tarball_dir}/${tarball_dest_dir}/${mingw_toolchain}"
67
68 download_file "${mingw_url}" "${mingw_w64}" "${mingw_toolchain}"
69
70 # Mark the tree as needing updates by deleting the folder
71 if test -d inplace/mingw && test inplace/mingw -ot "$mingw_w64" ; then
72 echo "In-tree MinGW-w64 tree requires updates..."
73 rm -rf inplace/mingw
74 fi
75 }
76
77 download_tarballs() {
78 #local mingw_base_url="http://repo.msys2.org/mingw"
79 local mingw_base_url="https://downloads.haskell.org/~ghc/mingw"
80 local package_prefix="mingw-w64"
81 local format_url="${mingw_base_url}/${mingw_arch}/${package_prefix}-${mingw_arch}"
82
83 download_mingw "${format_url}-crt-git-5.0.0.4795.e3d96cb1-1-any.pkg.tar.xz"
84 download_mingw "${format_url}-winpthreads-git-5.0.0.4741.2c8939a-1-any.pkg.tar.xz"
85 download_mingw "${format_url}-headers-git-5.0.0.4747.0f8f626-1-any.pkg.tar.xz"
86 download_mingw "${format_url}-libwinpthread-git-5.0.0.4741.2c8939a-1-any.pkg.tar.xz"
87 download_mingw "${format_url}-zlib-1.2.8-9-any.pkg.tar.xz"
88 download_mingw "${format_url}-isl-0.17.1-1-any.pkg.tar.xz"
89 download_mingw "${format_url}-mpfr-3.1.4.p3-4-any.pkg.tar.xz"
90 download_mingw "${format_url}-gmp-6.1.1-1-any.pkg.tar.xz"
91 download_mingw "${format_url}-binutils-2.27-2-any.pkg.tar.xz"
92 download_mingw "${format_url}-libidn-1.32-3-any.pkg.tar.xz"
93 download_mingw "${format_url}-gcc-6.2.0-2-any.pkg.tar.xz"
94
95 # Upstream is unfortunately quite inconsistent in naming
96 if test "$mingw_arch" != "sources"; then
97 download_mingw "${format_url}-mpc-1.0.3-2-any.pkg.tar.xz"
98 download_mingw "${format_url}-gcc-libs-6.2.0-2-any.pkg.tar.xz"
99 else
100 local format_url="${mingw_base_url}/${mingw_arch}/${package_prefix}"
101 download_mingw "${format_url}-i686-mpc-1.0.3-2.src.tar.gz"
102 download_mingw "${format_url}-x86_64-mpc-1.0.3-2.src.tar.gz"
103 fi
104
105 download_file "https://github.com/ghc/ghc-tarballs/blob/master/perl/ghc-perl-1.tar.gz?raw=true" "ghc-tarballs/perl/ghc-perl-1.tar.gz" "Windows Perl binary distributions" "--insecure"
106
107 if ! test "$missing_files" = "0"
108 then
109 exit 2
110 fi
111 }
112
113 download_i386() {
114 mingw_arch="i686"
115 tarball_dest_dir="mingw-w64/x86"
116 download_tarballs
117 }
118
119 download_x86_64() {
120 mingw_arch="x86_64"
121 tarball_dest_dir="mingw-w64/x86_64"
122 download_tarballs
123 }
124
125 download_sources() {
126 mingw_arch="sources"
127 tarball_dest_dir="mingw-w64/sources"
128 download_tarballs
129 }
130
131 usage() {
132 echo "$0 - Download GHC mingw toolchain tarballs"
133 echo
134 echo "Usage: $0 <action> <arch>"
135 echo
136 echo "Where <action> is one of,"
137 echo " download download the necessary tarballs for the given architecture"
138 echo " fetch download the necessary tarballs for the given architecture but doesn't verify their md5."d
139 echo " verify verify the existence and correctness of the necessary tarballs"
140 echo "and <arch> is one of i386, x86_64,all or mirror (which includes sources)"
141 }
142
143 case $1 in
144 download)
145 download=1
146 verify=1
147 sigs=0
148 ;;
149 fetch)
150 download=1
151 verify=0
152 ;;
153 verify)
154 download=0
155 verify=1
156 ;;
157 *)
158 usage
159 exit 1
160 ;;
161 esac
162
163 case $2 in
164 i386)
165 download_i386
166 ;;
167 x86_64)
168 download_x86_64
169 ;;
170 all)
171 download_i386
172 download_x86_64
173 ;;
174 mirror)
175 sigs=1
176 download_i386
177 download_x86_64
178 verify=0
179 download_sources
180 ;;
181 *)
182 usage
183 exit 1
184 ;;
185 esac