forked from flintlib/python-flint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_dependencies_unix.sh
More file actions
executable file
·437 lines (391 loc) · 13.8 KB
/
build_dependencies_unix.sh
File metadata and controls
executable file
·437 lines (391 loc) · 13.8 KB
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#!/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
PATCH_GMP_C23=no
PATCH_LDD=no
PATCH_IMMINTRIN=no
GMP_FAT_ARG="--enable-fat"
GMP_ASSEMBLY_ARG=
HOST_ARG=
USE_GMP=gmp
PATCH_GMP_ARM64=no
BUILD_ARB=no
USE_GMP_GITHUB_MIRROR=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 " --disable-assembly - disable GMP assembly routines"
echo " --patch-ldd - patch flint shared linking for mingw on arm64"
echo " --patch-immintrin - patch flint arm64 msvc header to avoid immintrin.h"
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 " --patch-C23 - apply patch to GMP 6.3.0 for C23 compatibility"
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
;;
--disable-assembly)
# GMP does not allow --enable-fat together with --disable-assembly.
GMP_FAT_ARG=
GMP_ASSEMBLY_ARG="--disable-assembly"
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
;;
--patch-C23)
# Patch GMP 6.3.0 for newer gcc versions
PATCH_GMP_C23=yes
shift
;;
--patch-ldd)
# Needed only for the FLINT shared build on mingw arm64.
PATCH_LDD=yes
shift
;;
--patch-immintrin)
# Needed only for the FLINT headers consumed by MSVC on Windows arm64.
PATCH_IMMINTRIN=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
mkdir -p "$PREFIX"
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
#
# https://github.com/msys2/MSYS2-packages/issues/5499
#
# This patch needed for GMP 6.3.0 building with msys2 or probably just
# newer gcc versions.
#
if [ $PATCH_GMP_C23 = "yes" ]; then
echo
echo --------------------------------------------
echo " patching GMP"
echo --------------------------------------------
patch -N -Z < ../../../bin/patch-C23.diff
autoreconf -fi
fi
# Show the output of configfsf.guess
chmod +x configfsf.guess
./configfsf.guess
./configure --prefix=$PREFIX\
$GMP_FAT_ARG\
$GMP_ASSEMBLY_ARG\
--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
if [ $USE_GMP_GITHUB_MIRROR = "yes" ]; then
if [ ! -d "gmp_mirror" ] ; then
git clone https://github.com/oscarbenjamin/gmp_mirror.git
fi
cp gmp_mirror/mpfr-$MPFRVER.tar.gz .
else
curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz
fi
tar xf mpfr-$MPFRVER.tar.gz
cd mpfr-$MPFRVER
./configure --prefix=$PREFIX\
--host=$HOST_ARG\
--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
if [ "$PATCH_LDD" = "yes" ]; then
echo
echo --------------------------------------------
echo " patching FLINT"
echo --------------------------------------------
patch -N -Z -p1 < ../../../bin/patch-flint-windows-arm64-link-$FLINTVER.diff
fi
if [ "$PATCH_IMMINTRIN" = "yes" ]; then
echo
echo --------------------------------------------
echo " patching FLINT"
echo --------------------------------------------
patch -N -Z -p1 < ../../../bin/patch-flint-windows-arm64-immintrin.diff
fi
./bootstrap.sh
./configure --prefix=$PREFIX\
--host=$HOST_ARG\
$FLINTARB_WITHGMP\
--with-mpfr=$PREFIX\
--disable-static\
--disable-debug
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