-
Notifications
You must be signed in to change notification settings - Fork 27
/
build_dependencies_unix.sh
executable file
·364 lines (319 loc) · 11.5 KB
/
build_dependencies_unix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/usr/bin/env bash
#
# Build local installs of python-flint's dependencies. This should be run
# before attempting to build python-flint itself.
set -o errexit
# ------------------------------------------------------------------------- #
# #
# Supported options: #
# #
# --gmp gmp - build based on GMP (default) #
# --gmp mpir - build based on MPIR (no longer works) #
# --host <HOST> - set the host (target) for GMP build #
# --patch-gmp-arm64 - apply patch to GMP for OSX arm64 #
# #
# ------------------------------------------------------------------------- #
SKIP_GMP=no
SKIP_MPFR=no
USE_GMP=gmp
PATCH_GMP_ARM64=no
BUILD_ARB=no
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
echo "bin/download_dependencies.sh [options]"
echo
echo "Build local installs of python-flint's dependencies."
echo
echo "Supported options:"
echo " --help - show this help message"
echo " --host <HOST> - set the host (target) for GMP build"
echo " --skip-gmp - skip building GMP"
echo " --skip-mpfr - skip building MPFR"
echo
echo "Legacy options:"
echo " --gmp gmp - build based on GMP (default)"
echo " --gmp mpir - build based on MPIR (no longer works)"
echo " --patch-gmp-arm64 - apply patch to GMP 6.2.1 for OSX arm64"
echo " --arb - build Arb (only needed for flint < 3.0.0)"
echo
exit
;;
--host)
# e.g. --host x86_64-unknown-linux-gnu
# or --host x86_64-apple-darwin
HOST_ARG="$2"
shift
shift
;;
--gmp)
# e.g. --gmp gmp or --gmp mpir
# The mpir build no longer works because the download fails.
USE_GMP="$2"
if [[ "$USE_GMP" != "gmp" && "$USE_GMP" != "mpir" ]]; then
echo "--gmp option should be gmp or mpir"
exit 1
fi
shift
shift
;;
--arb)
# With flint >= 3.0.0 Arb is included so we do not need to build it
# separately. Pass --arb if building for older versions of flint.
BUILD_ARB=yes
shift
;;
--skip-gmp)
# If you already have a local install of GMP you can pass --skip-gmp
# to skip building it.
SKIP_GMP=yes
shift
;;
--skip-mpfr)
# If you already have a local install of MPFR you can pass --skip-mpfr
# to skip building it.
SKIP_MPFR=yes
shift
;;
--patch-gmp-arm64)
# Needed only for GMP 6.2.1 on OSX arm64 (Apple M1) hardware
# As of GMP 6.3.0 this patch is no longer needed
PATCH_GMP_ARM64=yes
shift
;;
--use-gmp-github-mirror)
USE_GMP_GITHUB_MIRROR=yes
shift
;;
*)
2>&1 echo "unrecognised argument:" $key
exit 1
;;
esac
done
# ------------------------------------------------------------------------- #
# #
# The build_variables.sh script sets variables specifying the versions to #
# use for all dependencies and also the PREFIX variable. #
# #
# ------------------------------------------------------------------------- #
source bin/build_variables.sh
cd $PREFIX
mkdir -p src
cd src
# ------------------------------------------------------------------------- #
# #
# Now build all dependencies. #
# #
# ------------------------------------------------------------------------- #
if [ $USE_GMP = "gmp" ]; then
# ----------------------------------------------------------------------- #
# #
# GMP #
# #
# ----------------------------------------------------------------------- #
if [ $SKIP_GMP = "yes" ]; then
echo
echo --------------------------------------------
echo " skipping GMP"
echo --------------------------------------------
echo
else
echo
echo --------------------------------------------
echo " building GMP"
echo --------------------------------------------
echo
if [ $USE_GMP_GITHUB_MIRROR = "yes" ]; then
# Needed in GitHub Actions because it is blocked from gmplib.org
git clone https://github.com/oscarbenjamin/gmp_mirror.git
cp gmp_mirror/gmp-$GMPVER.tar.xz .
else
curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz
fi
tar xf gmp-$GMPVER.tar.xz
cd gmp-$GMPVER
#
# See https://github.com/aleaxit/gmpy/issues/350
#
# We need to patch GMP for OSX arm64 (Apple M1) hardware. This patch is
# from the GMP repo but was applied after the release of GMP 6.2.1.
# This patch is no longer needed for GMP 6.3.0.
#
if [ $PATCH_GMP_ARM64 = "yes" ]; then
echo
echo --------------------------------------------
echo " patching GMP"
echo --------------------------------------------
patch -N -Z -p0 < ../../../bin/patch-arm64.diff
fi
# Show the output of configfsf.guess
chmod +x configfsf.guess
./configfsf.guess
./configure --prefix=$PREFIX\
--enable-fat\
--enable-shared=yes\
--enable-static=no\
--host=$HOST_ARG
make -j6
make install
cd ..
fi
FLINTARB_WITHGMP="--with-gmp=$PREFIX"
else
# ----------------------------------------------------------------------- #
# #
# YASM (needed to build MPIR) #
# #
# ----------------------------------------------------------------------- #
curl -O http://www.tortall.net/projects/yasm/releases/yasm-$YASMVER.tar.gz
tar xf yasm-$YASMVER.tar.gz
cd yasm-$YASMVER
./configure --prefix=$PREFIX
make -j6
make install
cd ..
# ----------------------------------------------------------------------- #
# #
# MPIR #
# #
# ----------------------------------------------------------------------- #
#
# The mpir.org domain has expired and no longer hosts the source code so the
# call to curl below will fail.
# We could try to download from https://github.com/wbhart/mpir/releases.
#
# Ultimately it seems that MPIR is no longer maintained though so for now
# this remains unfixed.
#
>&2 echo "MPIR build of python_flint is no longer supported"
exit 1
curl -O http://mpir.org/mpir-$MPIRVER.tar.bz2
tar xf mpir-$MPIRVER.tar.bz2
cd mpir-$MPIRVER
./configure --prefix=$PREFIX\
--with-yasm=$PREFIX/bin/yasm\
--enable-fat\
--enable-shared=yes\
--enable-static=no\
--enable-gmpcompat
make -j6
make install
cd ..
FLINTARB_WITHGMP="--with-mpir=$PREFIX"
fi
# ------------------------------------------------------------------------- #
# #
# MPFR #
# #
# ------------------------------------------------------------------------- #
if [ $SKIP_MPFR = "yes" ]; then
echo
echo --------------------------------------------
echo " skipping MPFR"
echo --------------------------------------------
echo
else
echo
echo --------------------------------------------
echo " building MPFR"
echo --------------------------------------------
echo
curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz
tar xf mpfr-$MPFRVER.tar.gz
cd mpfr-$MPFRVER
./configure --prefix=$PREFIX\
--with-gmp=$PREFIX\
--enable-shared=yes\
--enable-static=no
make -j6
make install
cd ..
fi
# ------------------------------------------------------------------------- #
# #
# FLINT #
# #
# ------------------------------------------------------------------------- #
echo
echo --------------------------------------------
echo " building Flint"
echo --------------------------------------------
echo
curl -O -L https://github.com/flintlib/flint/releases/download/v$FLINTVER/flint-$FLINTVER.tar.gz
tar xf flint-$FLINTVER.tar.gz
cd flint-$FLINTVER
./bootstrap.sh
./configure --prefix=$PREFIX\
$FLINTARB_WITHGMP\
--with-mpfr=$PREFIX\
--disable-static
make -j6
make install
cd ..
# ------------------------------------------------------------------------- #
# #
# ARB #
# #
# ------------------------------------------------------------------------- #
if [ $BUILD_ARB = "yes" ]; then
echo
echo --------------------------------------------
echo " building Arb"
echo --------------------------------------------
echo
curl -O -L https://github.com/fredrik-johansson/arb/archive/refs/tags/$ARBVER.tar.gz
mv $ARBVER.tar.gz arb-$ARBVER.tar.gz
tar xf arb-$ARBVER.tar.gz
cd arb-$ARBVER
./configure --prefix=$PREFIX\
--with-flint=$PREFIX\
$FLINTARB_WITHGMP\
--with-mpfr=$PREFIX\
--disable-static
make -j6
make install
#
# Set PATH so that DLLs are picked up on Windows.
#
PATH=$PATH:$PREFIX/lib:$PREFIX/bin \
ARB_TEST_MULTIPLIER=0.1 \
# Skip Arb tests now because they are slow.
# make check
cd ..
fi
# ------------------------------------------------------------------------- #
# #
# Done! #
# #
# ------------------------------------------------------------------------- #
echo
echo -----------------------------------------------------------------------
echo
echo Build dependencies for python-flint compiled as shared libraries in:
echo $PREFIX
echo
echo Versions:
if [ $SKIP_GMP = "yes" ]; then
echo GMP: skipped
else
if [[ $USE_GMP = "gmp" ]]; then
echo GMP: $GMPVER
else
echo MPIR: $MPIRVER
fi
fi
if [ $SKIP_MPFR = "yes" ]; then
echo MPFR: skipped
else
echo MPFR: $MPFRVER
fi
echo Flint: $FLINTVER
if [ $BUILD_ARB = "yes" ]; then
echo Arb: $ARBVER
fi
echo
echo -----------------------------------------------------------------------
echo