library_builders.sh 13.6 KB
Newer Older
1
2
3
#Functions and environment variables to build various
#native libraries commonly used as dependencies

4
MULTIBUILD_DIR=$(dirname "${BASH_SOURCE[0]}")
xoviat's avatar
xoviat committed
5
source $MULTIBUILD_DIR/_gfortran_utils.sh
6
source $MULTIBUILD_DIR/configure_build.sh
xoviat's avatar
xoviat committed
7
8
9

# For OpenBLAS
GF_LIB_URL="https://3f23b170c54c2533c070-1c8a9b3114517dc5fe17b7c3f8c63a43.ssl.cf2.rackcdn.com"
10

Andrew Murray's avatar
Andrew Murray committed
11
# Recipes for building some libraries
Matthew Brett's avatar
Matthew Brett committed
12
OPENBLAS_VERSION="${OPENBLAS_VERSION:-0.2.18}"
13
# We use system zlib by default - see build_new_zlib
Matthew Brett's avatar
Matthew Brett committed
14
ZLIB_VERSION="${ZLIB_VERSION:-1.2.10}"
15
16
17
LIBPNG_VERSION="${LIBPNG_VERSION:-1.6.21}"
BZIP2_VERSION="${BZIP2_VERSION:-1.0.6}"
FREETYPE_VERSION="${FREETYPE_VERSION:-2.6.3}"
18
TIFF_VERSION="${TIFF_VERSION:-4.1.0}"
19
JPEG_VERSION="${JPEG_VERSION:-9b}"
20
OPENJPEG_VERSION="${OPENJPEG_VERSION:-2.1}"
21
LCMS2_VERSION="${LCMS2_VERSION:-2.9}"
22
23
24
GIFLIB_VERSION="${GIFLIB_VERSION:-5.1.3}"
LIBWEBP_VERSION="${LIBWEBP_VERSION:-0.5.0}"
XZ_VERSION="${XZ_VERSION:-5.2.2}"
mattip's avatar
mattip committed
25
LIBYAML_VERSION="${LIBYAML_VERSION:-0.2.2}"
Matthew Brett's avatar
Matthew Brett committed
26
SZIP_VERSION="${SZIP_VERSION:-2.1.1}"
27
HDF5_VERSION="${HDF5_VERSION:-1.10.4}"
28
LIBAEC_VERSION="${LIBAEC_VERSION:-0.3.3}"
Matthew Brett's avatar
Matthew Brett committed
29
LZO_VERSION=${LZO_VERSION:-2.10}
Rolando Espinoza's avatar
Rolando Espinoza committed
30
LZF_VERSION="${LZF_VERSION:-3.6}"
31
BLOSC_VERSION=${BLOSC_VERSION:-1.10.2}
Rolando Espinoza's avatar
Rolando Espinoza committed
32
SNAPPY_VERSION="${SNAPPY_VERSION:-1.1.3}"
33
CURL_VERSION=${CURL_VERSION:-7.49.1}
34
NETCDF_VERSION=${NETCDF_VERSION:-4.4.1.1}
35
SWIG_VERSION=${SWIG_VERSION:-4.0.1}
36
PCRE_VERSION=${PCRE_VERSION:-8.38}
37
SUITESPARSE_VERSION=${SUITESPARSE_VERSION:-4.5.6}
38
39
40
41
LIBTOOL_VERSION=${LIBTOOL_VERSION:-2.4.6}
RAGEL_VERSION=${RAGEL_VERSION:-6.10}
FLEX_VERSION=${FLEX_VERSION:-2.6.4}
BISON_VERSION=${BISON_VERSION:-3.0.4}
Alex Rothberg's avatar
Alex Rothberg committed
42
FFTW_VERSION=${FFTW_VERSION:-3.3.7}
Simon Conseil's avatar
Simon Conseil committed
43
CFITSIO_VERSION=${CFITSIO_VERSION:-3370}
Andrew Murray's avatar
Andrew Murray committed
44
OPENSSL_ROOT=openssl-1.0.2t
Matthew Brett's avatar
Matthew Brett committed
45
# Hash from https://www.openssl.org/source/openssl-1.0.2?.tar.gz.sha256
Andrew Murray's avatar
Andrew Murray committed
46
OPENSSL_HASH=14cb464efe7ac6b54799b34456bd69558a749a4931ecfd9cf9f71d7881cac7bc
47
OPENSSL_DOWNLOAD_URL=https://www.openssl.org/source
48

Rolando Espinoza's avatar
Rolando Espinoza committed
49

50
ARCHIVE_SDIR=${ARCHIVE_DIR:-archives}
51
52
53


function build_simple {
xoviat's avatar
xoviat committed
54
    # Example: build_simple libpng $LIBPNG_VERSION \
55
    #               https://download.sourceforge.net/libpng tar.gz \
xoviat's avatar
xoviat committed
56
    #               --additional --configure --arguments
57
58
59
    local name=$1
    local version=$2
    local url=$3
60
    local ext=${4:-tar.gz}
61
    local configure_args=${@:5}
62
63
64
65
    if [ -e "${name}-stamp" ]; then
        return
    fi
    local name_version="${name}-${version}"
66
67
    local archive=${name_version}.${ext}
    fetch_unpack $url/$archive
Matthew Brett's avatar
Matthew Brett committed
68
    (cd $name_version \
69
        && ./configure --prefix=$BUILD_PREFIX $configure_args \
70
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
71
        && make install)
72
73
74
    touch "${name}-stamp"
}

75
76
77
function build_github {
    # Example: build_github fredrik-johansson/arb 2.11.1
    local path=$1
Matthew Brett's avatar
Matthew Brett committed
78
    local tag_name=$2
79
80
81
82
83
    local configure_args=${@:3}
    local name=`basename "$path"`
    if [ -e "${name}-stamp" ]; then
        return
    fi
84
85
    local out_dir=$(fetch_unpack "https://github.com/${path}/archive/${tag_name}.tar.gz")
    (cd $out_dir \
86
        && ./configure --prefix=$BUILD_PREFIX $configure_args \
87
        && make -j4 \
88
89
90
91
        && make install)
    touch "${name}-stamp"
}

92
93
function build_openblas {
    if [ -e openblas-stamp ]; then return; fi
94
95
96
    if [ -n "$IS_OSX" ]; then
        brew install openblas
        brew link --force openblas
97
    elif [ ! -v IS_X86 ]; then
98
		# Skip this for now until we can build a suitable tar.gz
mattip's avatar
mattip committed
99
        return;
100
    else
101
        mkdir -p $ARCHIVE_SDIR
Matthew Brett's avatar
Matthew Brett committed
102
        local plat=${1:-${PLAT:-x86_64}}
xoviat's avatar
xoviat committed
103
104
        local tar_path=$(abspath $(_mb_get_gf_lib "openblas-${OPENBLAS_VERSION}" "$plat"))
        (cd / && tar zxf $tar_path)
105
    fi
106
107
108
109
110
    touch openblas-stamp
}

function build_zlib {
    # Gives an old but safe version
111
    if [ -n "$IS_OSX" ]; then return; fi  # OSX has zlib already
112
    if [ -e zlib-stamp ]; then return; fi
113
    yum install -y zlib-devel
114
115
116
117
118
    touch zlib-stamp
}

function build_new_zlib {
    # Careful, this one may cause yum to segfault
119
    # Fossils directory should also contain latest
120
    build_simple zlib $ZLIB_VERSION https://zlib.net/fossils
121
122
123
124
}

function build_jpeg {
    if [ -e jpeg-stamp ]; then return; fi
125
126
    fetch_unpack http://ijg.org/files/jpegsrc.v${JPEG_VERSION}.tar.gz
    (cd jpeg-${JPEG_VERSION} \
Matthew Brett's avatar
Matthew Brett committed
127
        && ./configure --prefix=$BUILD_PREFIX \
128
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
129
        && make install)
130
131
132
133
134
    touch jpeg-stamp
}

function build_libpng {
    build_zlib
135
    build_simple libpng $LIBPNG_VERSION https://download.sourceforge.net/libpng
136
137
138
}

function build_bzip2 {
139
    if [ -n "$IS_OSX" ]; then return; fi  # OSX has bzip2 libs already
140
    if [ -e bzip2-stamp ]; then return; fi
Andrew Murray's avatar
Andrew Murray committed
141
    fetch_unpack https://download.sourceforge.net/bzip2/bzip2-${BZIP2_VERSION}.tar.gz
Matthew Brett's avatar
Matthew Brett committed
142
143
144
    (cd bzip2-${BZIP2_VERSION} \
        && make -f Makefile-libbz2_so \
        && make install PREFIX=$BUILD_PREFIX)
145
146
147
148
149
150
151
    touch bzip2-stamp
}

function build_tiff {
    build_zlib
    build_jpeg
    build_xz
152
    build_simple tiff $TIFF_VERSION https://download.osgeo.org/libtiff
153
154
}

155
function get_cmake {
Matthew Brett's avatar
Matthew Brett committed
156
    local cmake=cmake
157
    if [ -n "$IS_OSX" ]; then
158
        brew install cmake > /dev/null
159
    else
160
        yum install -y cmake28 > /dev/null
Matthew Brett's avatar
Matthew Brett committed
161
        cmake=cmake28
162
    fi
163
164
165
166
167
    echo $cmake
}

function build_openjpeg {
    if [ -e openjpeg-stamp ]; then return; fi
Matthew Brett's avatar
Matthew Brett committed
168
169
170
171
    build_zlib
    build_libpng
    build_tiff
    build_lcms2
172
    local cmake=$(get_cmake)
173
174
175
176
    local archive_prefix="v"
    if [ $(lex_ver $OPENJPEG_VERSION) -lt $(lex_ver 2.1.1) ]; then
        archive_prefix="version."
    fi
177
178
    local out_dir=$(fetch_unpack https://github.com/uclouvain/openjpeg/archive/${archive_prefix}${OPENJPEG_VERSION}.tar.gz)
    (cd $out_dir \
Matthew Brett's avatar
Matthew Brett committed
179
180
        && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX . \
        && make install)
181
182
183
184
185
    touch openjpeg-stamp
}

function build_lcms2 {
    build_tiff
186
    build_simple lcms2 $LCMS2_VERSION https://downloads.sourceforge.net/project/lcms/lcms/$LCMS2_VERSION
187
188
189
}

function build_giflib {
190
    build_simple giflib $GIFLIB_VERSION https://downloads.sourceforge.net/project/giflib
191
192
193
}

function build_xz {
194
    build_simple xz $XZ_VERSION https://tukaani.org/xz
195
196
197
198
199
200
}

function build_libwebp {
    build_libpng
    build_tiff
    build_giflib
201
    build_simple libwebp $LIBWEBP_VERSION \
202
        https://storage.googleapis.com/downloads.webmproject.org/releases/webp tar.gz \
Thomas A Caswell's avatar
Thomas A Caswell committed
203
        --enable-libwebpmux --enable-libwebpdemux
204
205
206
207
208
}

function build_freetype {
    build_libpng
    build_bzip2
209
    build_simple freetype $FREETYPE_VERSION https://download.savannah.gnu.org/releases/freetype
210
211
212
}

function build_libyaml {
213
    build_simple yaml $LIBYAML_VERSION https://pyyaml.org/download/libyaml
214
}
Matthew Brett's avatar
Matthew Brett committed
215
216
217
218

function build_szip {
    # Build szip without encoding (patent restrictions)
    build_zlib
219
    build_simple szip $SZIP_VERSION \
Matthew Brett's avatar
Matthew Brett committed
220
        https://support.hdfgroup.org/ftp/lib-external/szip/$SZIP_VERSION/src tar.gz \
221
        --enable-encoding=no
Matthew Brett's avatar
Matthew Brett committed
222
223
224
225
}

function build_hdf5 {
    if [ -e hdf5-stamp ]; then return; fi
Matthew Brett's avatar
Matthew Brett committed
226
    build_zlib
227
228
    # libaec is a drop-in replacement for szip
    build_libaec
Andrew Murray's avatar
Andrew Murray committed
229
    local hdf5_url=https://support.hdfgroup.org/ftp/HDF5/releases
230
231
    local short=$(echo $HDF5_VERSION | awk -F "." '{printf "%d.%d", $1, $2}')
    fetch_unpack $hdf5_url/hdf5-$short/hdf5-$HDF5_VERSION/src/hdf5-$HDF5_VERSION.tar.gz
Matthew Brett's avatar
Matthew Brett committed
232
    (cd hdf5-$HDF5_VERSION \
Tom Kooij's avatar
Tom Kooij committed
233
234
        && ./configure --with-szlib=$BUILD_PREFIX --prefix=$BUILD_PREFIX \
        --enable-threadsafe --enable-unsupported --with-pthread=yes \
235
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
236
237
238
        && make install)
    touch hdf5-stamp
}
239
240
241
242
243
244

function build_libaec {
    if [ -e libaec-stamp ]; then return; fi
    local root_name=libaec-0.3.3
    local tar_name=${root_name}.tar.gz
    # Note URL will change for each version
245
    fetch_unpack https://gitlab.dkrz.de/k202009/libaec/uploads/48398bd5b7bc05a3edb3325abfeac864/${tar_name}
246
    (cd $root_name \
Matthew Brett's avatar
Matthew Brett committed
247
        && ./configure --prefix=$BUILD_PREFIX \
248
249
250
251
        && make \
        && make install)
    touch libaec-stamp
}
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

function build_blosc {
    if [ -e blosc-stamp ]; then return; fi
    local cmake=$(get_cmake)
    fetch_unpack https://github.com/Blosc/c-blosc/archive/v${BLOSC_VERSION}.tar.gz
    (cd c-blosc-${BLOSC_VERSION} \
        && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX . \
        && make install)
    if [ -n "$IS_OSX" ]; then
        # Fix blosc library id bug
        for lib in $(ls ${BUILD_PREFIX}/lib/libblosc*.dylib); do
            install_name_tool -id $lib $lib
        done
    fi
    touch blosc-stamp
}

Rolando Espinoza's avatar
Rolando Espinoza committed
269
270
271
272
function build_snappy {
    build_simple snappy $SNAPPY_VERSION https://github.com/google/snappy/releases/download/$SNAPPY_VERSION
}

273
274
function build_lzo {
    if [ -e lzo-stamp ]; then return; fi
275
    fetch_unpack https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz
276
277
278
279
280
281
    (cd lzo-${LZO_VERSION} \
        && ./configure --prefix=$BUILD_PREFIX --enable-shared \
        && make \
        && make install)
    touch lzo-stamp
}
282

Rolando Espinoza's avatar
Rolando Espinoza committed
283
284
285
286
function build_lzf {
    build_simple liblzf $LZF_VERSION http://dist.schmorp.de/liblzf
}

287
288
function build_curl {
    if [ -e curl-stamp ]; then return; fi
Matthew Brett's avatar
Matthew Brett committed
289
    local flags="--prefix=$BUILD_PREFIX"
Matthew Brett's avatar
Matthew Brett committed
290
    if [ -n "$IS_OSX" ]; then
291
        flags="$flags --with-darwinssl"
292
    else  # manylinux
293
        flags="$flags --with-ssl"
Matthew Brett's avatar
Matthew Brett committed
294
295
        build_openssl
    fi
296
297
    fetch_unpack https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz
    (cd curl-${CURL_VERSION} \
298
299
300
        && if [ -z "$IS_OSX" ]; then \
        LIBS=-ldl ./configure $flags; else \
        ./configure $flags; fi\
301
        && make -j4 \
302
303
304
305
        && make install)
    touch curl-stamp
}

Matthew Brett's avatar
Matthew Brett committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
function check_sha256sum {
    local fname=$1
    if [ -z "$fname" ]; then echo "Need path"; exit 1; fi
    local sha256=$2
    if [ -z "$sha256" ]; then echo "Need SHA256 hash"; exit 1; fi
    echo "${sha256}  ${fname}" > ${fname}.sha256
    if [ -n "$IS_OSX" ]; then
        shasum -a 256 -c ${fname}.sha256
    else
        sha256sum -c ${fname}.sha256
    fi
    rm ${fname}.sha256
}

function build_openssl {
    if [ -e openssl-stamp ]; then return; fi
    fetch_unpack ${OPENSSL_DOWNLOAD_URL}/${OPENSSL_ROOT}.tar.gz
    check_sha256sum $ARCHIVE_SDIR/${OPENSSL_ROOT}.tar.gz ${OPENSSL_HASH}
    (cd ${OPENSSL_ROOT} \
        && ./config no-ssl2 no-shared -fPIC --prefix=$BUILD_PREFIX \
326
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
327
328
329
330
        && make install)
    touch openssl-stamp
}

331
332
333
334
335
336
function build_netcdf {
    if [ -e netcdf-stamp ]; then return; fi
    build_hdf5
    build_curl
    fetch_unpack https://github.com/Unidata/netcdf-c/archive/v${NETCDF_VERSION}.tar.gz
    (cd netcdf-c-${NETCDF_VERSION} \
Matthew Brett's avatar
Matthew Brett committed
337
        && ./configure --prefix=$BUILD_PREFIX --enable-dap \
338
        && make -j4 \
339
340
341
        && make install)
    touch netcdf-stamp
}
xoviat's avatar
xoviat committed
342

343
function build_pcre {
344
    build_simple pcre $PCRE_VERSION https://ftp.pcre.org/pub/pcre
xoviat's avatar
xoviat committed
345
346
}

xoviat's avatar
xoviat committed
347
function build_swig {
Andrew Murray's avatar
Andrew Murray committed
348
    if [ -e swig-stamp ]; then return; fi
xoviat's avatar
xoviat committed
349
350
351
    if [ -n "$IS_OSX" ]; then
        brew install swig > /dev/null
    else
352
        build_pcre
353
        build_simple swig $SWIG_VERSION https://prdownloads.sourceforge.net/swig
xoviat's avatar
xoviat committed
354
    fi
Andrew Murray's avatar
Andrew Murray committed
355
    touch swig-stamp
xoviat's avatar
xoviat committed
356
357
}

xoviat's avatar
xoviat committed
358
function build_suitesparse {
Andrew Murray's avatar
Andrew Murray committed
359
    if [ -e suitesparse-stamp ]; then return; fi
xoviat's avatar
xoviat committed
360
    if [ -n "$IS_OSX" ]; then
xoviat's avatar
xoviat committed
361
        brew install suite-sparse > /dev/null
xoviat's avatar
xoviat committed
362
    else
xoviat's avatar
xoviat committed
363
        yum install -y suitesparse-devel > /dev/null
xoviat's avatar
xoviat committed
364
    fi
Andrew Murray's avatar
Andrew Murray committed
365
    touch suitesparse-stamp
xoviat's avatar
xoviat committed
366
}
367
368

function build_libtool {
369
    build_simple libtool $LIBTOOL_VERSION https://ftp.gnu.org/gnu/libtool
370
371
372
}

function build_ragel {
373
    build_simple ragel $RAGEL_VERSION https://www.colm.net/files/ragel
374
375
376
}

function build_bison {
377
    build_simple bison $BISON_VERSION https://ftp.gnu.org/gnu/bison
378
379
380
381
382
383
384
}

function build_flex {
    # the flex repository's git tags have a 'v' prefix
    build_simple flex $FLEX_VERSION \
        https://github.com/westes/flex/releases/download/v$FLEX_VERSION
}
Alex Rothberg's avatar
Alex Rothberg committed
385

Alex Rothberg's avatar
Alex Rothberg committed
386
387
388
389
function build_fftw_case {
    local configure_args=${@:0}

    build_simple fftw $FFTW_VERSION \
390
        http://www.fftw.org tar.gz \
Alex Rothberg's avatar
Alex Rothberg committed
391
392
393
394
395
        --with-pic --enable-shared --enable-threads --disable-fortran \
        $configure_args
    # eval cd fftw-$FFTW_VERSION/tests && make check-local && cd -
}

Alex Rothberg's avatar
Alex Rothberg committed
396
397
function build_fftw {
    echo 'Building fftw'
Alex Rothberg's avatar
Alex Rothberg committed
398
399
400
401

    # Save off current CFLAGS
    local old_cflags=$CFLAGS

Alex Rothberg's avatar
Alex Rothberg committed
402
403
404
405
406
    # Taken from: https://github.com/conda-forge/fftw-feedstock/blob/master/recipe/build.sh
    export CFLAGS="-O3 -fomit-frame-pointer -fstrict-aliasing -ffast-math"

    # single
    echo 'Building fftw: single'
Alex Rothberg's avatar
Alex Rothberg committed
407
    build_fftw_case --enable-float --enable-sse --enable-sse2 --enable-avx
Alex Rothberg's avatar
Alex Rothberg committed
408
409
410
411
412
413

    # Clear stamp file which prevents subsequent builds
    rm fftw-stamp

    # double
    echo 'Building fftw: double'
Alex Rothberg's avatar
Alex Rothberg committed
414
    build_fftw_case --enable-sse2 --enable-avx
Alex Rothberg's avatar
Alex Rothberg committed
415
416
417
418
419
420

    # Clear stamp file which prevents subsequent builds
    rm fftw-stamp

    # long double (SSE2 and AVX not supported)
    echo 'Building fftw: long double'
Alex Rothberg's avatar
Alex Rothberg committed
421
    build_fftw_case --enable-long-double
Alex Rothberg's avatar
Alex Rothberg committed
422
423
424
425
426
427
428
429
430
431
432
433

    # Taken from: https://github.com/conda-forge/pyfftw-feedstock/blob/master/recipe/build.sh
    export C_INCLUDE_PATH=$BUILD_PREFIX/include  # required as fftw3.h installed here

    # define STATIC_FFTW_DIR so the patched setup.py will statically link FFTW
    export STATIC_FFTW_DIR=$BUILD_PREFIX/lib

    # TODO: These can be made into asserts per:
    # https://github.com/conda-forge/fftw-feedstock/blob/8eaa8a1c63e7fcb97c63c1ee8e33c62ef3afa9c7/recipe/meta.yaml#L29-L52
    ls -l $C_INCLUDE_PATH/fftw3*
    ls -l $STATIC_FFTW_DIR/libfftw3*

Alex Rothberg's avatar
Alex Rothberg committed
434
435
    # restore CFLAGS
    export CFLAGS=$old_cflags
Alex Rothberg's avatar
Alex Rothberg committed
436
}
Simon Conseil's avatar
Simon Conseil committed
437
438

function build_cfitsio {
Simon Conseil's avatar
Simon Conseil committed
439
    if [ -e cfitsio-stamp ]; then return; fi
Simon Conseil's avatar
Simon Conseil committed
440
441
442
443
444
445
446
447
448
449
    if [ -n "$IS_OSX" ]; then
        brew install cfitsio
    else
        # cannot use build_simple because cfitsio has no dash between name and version
        local cfitsio_name_ver=cfitsio${CFITSIO_VERSION}
        fetch_unpack https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/${cfitsio_name_ver}.tar.gz
        (cd cfitsio \
            && ./configure --prefix=$BUILD_PREFIX \
            && make shared && make install)
    fi
Simon Conseil's avatar
Simon Conseil committed
450
    touch cfitsio-stamp
Simon Conseil's avatar
Simon Conseil committed
451
}