Fix lld detection if both gold and lld are found
[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 backup_url="$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 -n "${backup_url}"; then
24 local curl_cmd_bnk="curl -L ${backup_url} -o ${dest_file} --create-dirs -# ${extra_curl_opts}"
25 else
26 local curl_cmd_bnk="echo 1"
27 fi
28
29 if test "$download" = "0"
30 then
31 echo "ERROR: Missing ${description}" >&2
32 echo "${file_url}"
33 missing_files=1
34 return
35 else
36 echo "Downloading ${description} to ${dest_dir}..."
37 $curl_cmd || $curl_cmd_bnk || {
38 rm -f "${dest_file}"
39 fail "ERROR: Download failed."
40 }
41 fi
42 fi
43
44 local sig_file="${dest_file}.sig"
45 if test "$sigs" = "1" -a ! -f "$sig_file"
46 then
47 echo "Downloading ${description} (signature) to ${dest_dir}..."
48 local curl_cmd="curl -L ${file_url}.sig -o ${sig_file} --create-dirs -# ${extra_curl_opts}"
49 $curl_cmd || {
50 rm -f "${dest_file}.sig"
51 fail "ERROR: Download failed."
52 }
53 fi
54
55 if test "$verify" = "1"
56 then
57 grep "${dest_file}$" mk/win32-tarballs.md5sum | md5sum --quiet -c - ||
58 fail "ERROR: ${description} appears to be corrupted, please delete it and try again."
59 fi
60 }
61
62 download_mingw() {
63 local mingw_base_url_primary="https://downloads.haskell.org/~ghc/mingw"
64 local mingw_base_url_secondary="http://repo.msys2.org/mingw"
65
66 if test "$mingw_arch" = "sources"
67 then
68 mingw_url_tmp=`echo "$1" | sed -e 's/-any\.pkg\.tar\.xz/\.src\.tar\.gz/' \
69 -e 's/-sources-/-/' \
70 -e 's/-libwinpthread-git-/-winpthreads-git-/' `
71 local mingw_url="${mingw_base_url_primary}/${mingw_url_tmp}"
72 else
73 local mingw_url="${mingw_base_url_primary}/$1"
74 local mingw_url_backup="${mingw_base_url_secondary}/$1"
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}" "${mingw_w64}" "${mingw_toolchain}" "" "${mingw_url_backup}"
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 package_prefix="mingw-w64"
91 local format_url="/${mingw_arch}/${package_prefix}-${mingw_arch}"
92
93 download_mingw "${format_url}-crt-git-5.0.0.4795.e3d96cb1-1-any.pkg.tar.xz"
94 download_mingw "${format_url}-winpthreads-git-5.0.0.4761.02bea78-1-any.pkg.tar.xz"
95 download_mingw "${format_url}-headers-git-5.0.0.4797.31e66d7e-1-any.pkg.tar.xz"
96 download_mingw "${format_url}-libwinpthread-git-5.0.0.4761.02bea78-1-any.pkg.tar.xz"
97 download_mingw "${format_url}-zlib-1.2.11-1-any.pkg.tar.xz"
98 download_mingw "${format_url}-isl-0.17.1-1-any.pkg.tar.xz"
99 download_mingw "${format_url}-mpfr-3.1.5.p1-1-any.pkg.tar.xz"
100 download_mingw "${format_url}-gmp-6.1.2-1-any.pkg.tar.xz"
101 download_mingw "${format_url}-binutils-2.28-1-any.pkg.tar.xz"
102 download_mingw "${format_url}-libidn-1.33-1-any.pkg.tar.xz"
103 download_mingw "${format_url}-gcc-6.3.0-2-any.pkg.tar.xz"
104
105 # Upstream is unfortunately quite inconsistent in naming
106 if test "$mingw_arch" != "sources"; then
107 download_mingw "${format_url}-mpc-1.0.3-2-any.pkg.tar.xz"
108 download_mingw "${format_url}-gcc-libs-6.3.0-2-any.pkg.tar.xz"
109 else
110 local format_url="${mingw_base_url}/${mingw_arch}/${package_prefix}"
111 download_mingw "${format_url}-i686-mpc-1.0.3-2.src.tar.gz"
112 download_mingw "${format_url}-x86_64-mpc-1.0.3-2.src.tar.gz"
113 fi
114
115 download_file "https://downloads.haskell.org/~ghc/mingw/ghc-perl-1.tar.gz" "ghc-tarballs/perl/ghc-perl-1.tar.gz" "Windows Perl binary distributions"
116
117 if ! test "$missing_files" = "0"
118 then
119 exit 2
120 fi
121 }
122
123 download_i386() {
124 mingw_arch="i686"
125 tarball_dest_dir="mingw-w64/x86"
126 download_tarballs
127 }
128
129 download_x86_64() {
130 mingw_arch="x86_64"
131 tarball_dest_dir="mingw-w64/x86_64"
132 download_tarballs
133 }
134
135 download_sources() {
136 mingw_arch="sources"
137 tarball_dest_dir="mingw-w64/sources"
138 download_tarballs
139 }
140
141 sync_binaries_and_sources() {
142 gpg --recv-key 5F92EFC1A47D45A1
143
144 # ensure sources are downloaded
145 sigs=1
146 download_i386
147 download_x86_64
148 verify=0
149 download_sources
150
151 for f in $(find ghc-tarballs/mingw-w64 -iname '*.sig'); do
152 echo "Verifying $f"
153 gpg --verify $f
154 done
155
156 md5sum `find ghc-tarballs -type f -a -not -iname '*.sig'` >| mk/win32-tarballs.md5sum
157 chmod -R ugo+rX ghc-tarballs
158
159 rsync -av ghc-tarballs/mingw-w64/* downloads.haskell.org:public_html/mingw
160 for f in $(find ghc-tarballs/mingw-w64); do
161 curl -XPURGE http://downloads.haskell.org/~ghc/mingw/$f
162 done
163 }
164
165 usage() {
166 echo "$0 - Download GHC mingw toolchain tarballs"
167 echo
168 echo "Usage: $0 <action> [<arch>]"
169 echo
170 echo "Where <action> is one of,"
171 echo ""
172 echo " download download the necessary tarballs for the given architecture"
173 echo " fetch download the necessary tarballs for the given architecture but doesn't verify their md5."
174 echo " verify verify the existence and correctness of the necessary tarballs"
175 echo " sync upload packages downloaded with 'fetch mirror' to haskell.org"
176 echo ""
177 echo "and <arch> is one of i386, x86_64,all or mirror (which includes sources)"
178 }
179
180 case $1 in
181 download)
182 download=1
183 verify=1
184 sigs=0
185 ;;
186 fetch)
187 download=1
188 verify=0
189 ;;
190 verify)
191 download=0
192 verify=1
193 ;;
194 sync)
195 download=1
196 verify=0
197 sync=1
198 ;;
199 *)
200 usage
201 exit 1
202 ;;
203 esac
204
205 case $2 in
206 i386)
207 download_i386
208 ;;
209 x86_64)
210 download_x86_64
211 ;;
212 all)
213 download_i386
214 download_x86_64
215 ;;
216 mirror)
217 sigs=1
218 download_i386
219 download_x86_64
220 verify=0
221 download_sources
222 ;;
223 *)
224 if test "$sync" = "1"; then
225 sync_binaries_and_sources
226 else
227 usage
228 exit 1
229 fi
230 ;;
231 esac