library_builders.sh 15.8 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

GF_LIB_URL="https://3f23b170c54c2533c070-1c8a9b3114517dc5fe17b7c3f8c63a43.ssl.cf2.rackcdn.com"
9
10
# For OpenBLAS
OPENBLAS_LIB_URL="https://anaconda.org/multibuild-wheels-staging/openblas-libs"
11

Andrew Murray's avatar
Andrew Murray committed
12
# Recipes for building some libraries
13
OPENBLAS_VERSION="${OPENBLAS_VERSION:-0.3.10}"
14
# We use system zlib by default - see build_new_zlib
Matthew Brett's avatar
Matthew Brett committed
15
ZLIB_VERSION="${ZLIB_VERSION:-1.2.10}"
16
LIBPNG_VERSION="${LIBPNG_VERSION:-1.6.21}"
mattip's avatar
mattip committed
17
BZIP2_VERSION="${BZIP2_VERSION:-1.0.7}"
18
FREETYPE_VERSION="${FREETYPE_VERSION:-2.6.3}"
19
TIFF_VERSION="${TIFF_VERSION:-4.1.0}"
20
JPEG_VERSION="${JPEG_VERSION:-9b}"
21
OPENJPEG_VERSION="${OPENJPEG_VERSION:-2.1}"
22
LCMS2_VERSION="${LCMS2_VERSION:-2.9}"
23
24
25
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
26
LIBYAML_VERSION="${LIBYAML_VERSION:-0.2.2}"
Matthew Brett's avatar
Matthew Brett committed
27
SZIP_VERSION="${SZIP_VERSION:-2.1.1}"
28
HDF5_VERSION="${HDF5_VERSION:-1.10.5}"
mattip's avatar
mattip committed
29
LIBAEC_VERSION="${LIBAEC_VERSION:-1.0.4}"
Matthew Brett's avatar
Matthew Brett committed
30
LZO_VERSION=${LZO_VERSION:-2.10}
Rolando Espinoza's avatar
Rolando Espinoza committed
31
LZF_VERSION="${LZF_VERSION:-3.6}"
32
BLOSC_VERSION=${BLOSC_VERSION:-1.10.2}
Rolando Espinoza's avatar
Rolando Espinoza committed
33
SNAPPY_VERSION="${SNAPPY_VERSION:-1.1.3}"
34
CURL_VERSION=${CURL_VERSION:-7.49.1}
35
NETCDF_VERSION=${NETCDF_VERSION:-4.4.1.1}
36
SWIG_VERSION=${SWIG_VERSION:-4.0.1}
37
PCRE_VERSION=${PCRE_VERSION:-8.38}
38
SUITESPARSE_VERSION=${SUITESPARSE_VERSION:-4.5.6}
39
40
41
42
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
43
FFTW_VERSION=${FFTW_VERSION:-3.3.7}
mattip's avatar
mattip committed
44
CFITSIO_VERSION=${CFITSIO_VERSION:-3450}
Andrew Murray's avatar
Andrew Murray committed
45
OPENSSL_ROOT=${OPENSSL_ROOT:-openssl-1.1.1l}
Andrew Murray's avatar
Andrew Murray committed
46
# Hash from https://www.openssl.org/source/openssl-1.1.1?.tar.gz.sha256
Andrew Murray's avatar
Andrew Murray committed
47
OPENSSL_HASH=${OPENSSL_HASH:-0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1}
48
OPENSSL_DOWNLOAD_URL=${OPENSSL_DOWNLOAD_URL:-https://www.openssl.org/source}
49

Rolando Espinoza's avatar
Rolando Espinoza committed
50

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


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

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

93
94
95
96
97
98
99
100
101
function openblas_get {
    # Get an openblas compiled library from
    # https://anaconda.org/multibuild-wheels-staging/openblas-libs
    # The general form of the link is (under the URL above)
    # URL/v0.3.10/downloads/openblas-v0.3.10-manylinux2010_x86_64.tar.gz
    local plat=${1:-$}
    # qual could be 64 to get a 64-bit version
    local qual=$2
    local prefix=openblas${qual}-v$OPENBLAS_VERSION
102
    local manylinux=manylinux${MB_ML_VER}
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    local fname="$prefix-${manylinux}_${plat}.tar.gz"
    local out_fname="${ARCHIVE_SDIR}/$fname"
    if [ ! -e "$out_fname" ]; then
        local webname=${OPENBLAS_LIB_URL}/v${OPENBLAS_VERSION}/download/${fname}
        curl -L "$webname" > $out_fname || exit 1
        # make sure it is not an HTML document of download failure
        local ok=$(file $out_fname | grep "HTML document")
        if [ -n "$ok" ]; then
            echo Fetching "${OPENBLAS_LIB_URL}/$fname" failed;
            exit 1;
        fi
    fi
    echo "$out_fname"
}

118
119
function build_openblas {
    if [ -e openblas-stamp ]; then return; fi
Andrew Murray's avatar
Andrew Murray committed
120
    if [ -n "$IS_MACOS" ]; then
121
122
        brew install openblas
        brew link --force openblas
123
    else
124
        mkdir -p $ARCHIVE_SDIR
Matthew Brett's avatar
Matthew Brett committed
125
        local plat=${1:-${PLAT:-x86_64}}
126
        local tar_path=$(abspath $(openblas_get $plat))
xoviat's avatar
xoviat committed
127
        (cd / && tar zxf $tar_path)
128
    fi
129
130
131
132
133
    touch openblas-stamp
}

function build_zlib {
    # Gives an old but safe version
Andrew Murray's avatar
Andrew Murray committed
134
    if [ -n "$IS_MACOS" ]; then return; fi  # OSX has zlib already
135
    if [ -e zlib-stamp ]; then return; fi
mattip's avatar
mattip committed
136
    if [[ $MB_ML_VER == "_2_24" ]]; then
mattip's avatar
mattip committed
137
        # debian:9 based distro
mattip's avatar
mattip committed
138
139
        apt-get install -y zlib1g-dev
    else
mattip's avatar
mattip committed
140
        #centos based distro
mattip's avatar
mattip committed
141
142
        yum_install zlib-devel
    fi
143
144
145
146
147
    touch zlib-stamp
}

function build_new_zlib {
    # Careful, this one may cause yum to segfault
148
    # Fossils directory should also contain latest
149
    build_simple zlib $ZLIB_VERSION https://zlib.net/fossils
150
151
152
153
}

function build_jpeg {
    if [ -e jpeg-stamp ]; then return; fi
154
155
    fetch_unpack http://ijg.org/files/jpegsrc.v${JPEG_VERSION}.tar.gz
    (cd jpeg-${JPEG_VERSION} \
Matthew Brett's avatar
Matthew Brett committed
156
        && ./configure --prefix=$BUILD_PREFIX \
157
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
158
        && make install)
159
160
161
162
163
    touch jpeg-stamp
}

function build_libpng {
    build_zlib
164
    build_simple libpng $LIBPNG_VERSION https://download.sourceforge.net/libpng
165
166
167
}

function build_bzip2 {
Andrew Murray's avatar
Andrew Murray committed
168
    if [ -n "$IS_MACOS" ]; then return; fi  # OSX has bzip2 libs already
169
    if [ -e bzip2-stamp ]; then return; fi
Andrew Murray's avatar
Andrew Murray committed
170
    fetch_unpack https://sourceware.org/pub/bzip2/bzip2-${BZIP2_VERSION}.tar.gz
Matthew Brett's avatar
Matthew Brett committed
171
172
173
    (cd bzip2-${BZIP2_VERSION} \
        && make -f Makefile-libbz2_so \
        && make install PREFIX=$BUILD_PREFIX)
174
175
176
177
178
179
    touch bzip2-stamp
}

function build_tiff {
    build_zlib
    build_jpeg
180
    ensure_xz
181
    build_simple tiff $TIFF_VERSION https://download.osgeo.org/libtiff
182
183
}

184
function get_modern_cmake {
Andrew Murray's avatar
Andrew Murray committed
185
    # Install cmake >= 2.8
Matthew Brett's avatar
Matthew Brett committed
186
    local cmake=cmake
Andrew Murray's avatar
Andrew Murray committed
187
    if [ -n "$IS_MACOS" ]; then
188
        brew install cmake > /dev/null
mattip's avatar
mattip committed
189
    elif [[ $MB_ML_VER == "_2_24" ]]; then
mattip's avatar
mattip committed
190
        # debian:9 based distro
mattip's avatar
mattip committed
191
        apt-get install -y cmake
192
    else
193
194
195
        if [ "`yum search cmake | grep ^cmake28\.`" ]; then
            cmake=cmake28
        fi
mattip's avatar
mattip committed
196
        # centos based distro
197
        yum_install $cmake > /dev/null
198
    fi
199
200
201
    echo $cmake
}

202
203
204
205
206
function get_cmake {
	>&2 echo "get_cmake has been deprecated. Please use get_modern_cmake instead."
	get_modern_cmake
}

207
208
function build_openjpeg {
    if [ -e openjpeg-stamp ]; then return; fi
Matthew Brett's avatar
Matthew Brett committed
209
210
211
212
    build_zlib
    build_libpng
    build_tiff
    build_lcms2
213
    local cmake=$(get_modern_cmake)
214
215
216
217
    local archive_prefix="v"
    if [ $(lex_ver $OPENJPEG_VERSION) -lt $(lex_ver 2.1.1) ]; then
        archive_prefix="version."
    fi
218
219
    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
220
221
        && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX . \
        && make install)
222
223
224
225
226
    touch openjpeg-stamp
}

function build_lcms2 {
    build_tiff
227
    build_simple lcms2 $LCMS2_VERSION https://downloads.sourceforge.net/project/lcms/lcms/$LCMS2_VERSION
228
229
230
}

function build_giflib {
231
    build_simple giflib $GIFLIB_VERSION https://downloads.sourceforge.net/project/giflib
232
233
234
}

function build_xz {
235
    build_simple xz $XZ_VERSION https://tukaani.org/xz
236
237
}

238
239
function ensure_xz {
	if [[ ! $(type -P "xz") ]]; then
Andrew Murray's avatar
Andrew Murray committed
240
241
242
243
244
	    if [ -n "$IS_MACOS" ]; then
	        brew install xz
	    else
	        build_xz
	    fi
245
246
247
	fi
}

248
249
250
251
function build_libwebp {
    build_libpng
    build_tiff
    build_giflib
252
    build_simple libwebp $LIBWEBP_VERSION \
253
        https://storage.googleapis.com/downloads.webmproject.org/releases/webp tar.gz \
Thomas A Caswell's avatar
Thomas A Caswell committed
254
        --enable-libwebpmux --enable-libwebpdemux
255
256
257
258
259
}

function build_freetype {
    build_libpng
    build_bzip2
260
    build_simple freetype $FREETYPE_VERSION https://download.savannah.gnu.org/releases/freetype
261
262
263
}

function build_libyaml {
264
    build_simple yaml $LIBYAML_VERSION https://pyyaml.org/download/libyaml
265
}
Matthew Brett's avatar
Matthew Brett committed
266
267
268
269

function build_szip {
    # Build szip without encoding (patent restrictions)
    build_zlib
270
    build_simple szip $SZIP_VERSION \
Matthew Brett's avatar
Matthew Brett committed
271
        https://support.hdfgroup.org/ftp/lib-external/szip/$SZIP_VERSION/src tar.gz \
272
        --enable-encoding=no
Matthew Brett's avatar
Matthew Brett committed
273
274
275
276
}

function build_hdf5 {
    if [ -e hdf5-stamp ]; then return; fi
Matthew Brett's avatar
Matthew Brett committed
277
    build_zlib
278
279
    # libaec is a drop-in replacement for szip
    build_libaec
Andrew Murray's avatar
Andrew Murray committed
280
    local hdf5_url=https://support.hdfgroup.org/ftp/HDF5/releases
281
282
    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
283
    (cd hdf5-$HDF5_VERSION \
284
        && export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BUILD_PREFIX/lib \
Matthew Brett's avatar
Matthew Brett committed
285
        && ./configure --with-szlib=$BUILD_PREFIX --prefix=$BUILD_PREFIX \
Tom Kooij's avatar
Tom Kooij committed
286
        --enable-threadsafe --enable-unsupported --with-pthread=yes \
287
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
288
289
290
        && make install)
    touch hdf5-stamp
}
291
292
293

function build_libaec {
    if [ -e libaec-stamp ]; then return; fi
mattip's avatar
mattip committed
294
    local root_name=libaec-1.0.4
295
296
    local tar_name=${root_name}.tar.gz
    # Note URL will change for each version
mattip's avatar
mattip committed
297
    fetch_unpack https://gitlab.dkrz.de/k202009/libaec/uploads/ea0b7d197a950b0c110da8dfdecbb71f/${tar_name}
298
    (cd $root_name \
Matthew Brett's avatar
Matthew Brett committed
299
        && ./configure --prefix=$BUILD_PREFIX \
300
301
302
303
        && make \
        && make install)
    touch libaec-stamp
}
304
305
306

function build_blosc {
    if [ -e blosc-stamp ]; then return; fi
307
    local cmake=$(get_modern_cmake)
308
309
310
311
    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)
Andrew Murray's avatar
Andrew Murray committed
312
    if [ -n "$IS_MACOS" ]; then
313
314
315
316
317
318
319
320
        # 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
321
322
323
324
function build_snappy {
    build_simple snappy $SNAPPY_VERSION https://github.com/google/snappy/releases/download/$SNAPPY_VERSION
}

325
326
function build_lzo {
    if [ -e lzo-stamp ]; then return; fi
327
    fetch_unpack https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz
328
329
330
331
332
333
    (cd lzo-${LZO_VERSION} \
        && ./configure --prefix=$BUILD_PREFIX --enable-shared \
        && make \
        && make install)
    touch lzo-stamp
}
334

Rolando Espinoza's avatar
Rolando Espinoza committed
335
336
337
338
function build_lzf {
    build_simple liblzf $LZF_VERSION http://dist.schmorp.de/liblzf
}

339
340
function build_curl {
    if [ -e curl-stamp ]; then return; fi
Matthew Brett's avatar
Matthew Brett committed
341
    local flags="--prefix=$BUILD_PREFIX"
Andrew Murray's avatar
Andrew Murray committed
342
    if [ -n "$IS_MACOS" ]; then
343
        flags="$flags --with-darwinssl"
344
    else  # manylinux
345
        flags="$flags --with-ssl"
Matthew Brett's avatar
Matthew Brett committed
346
347
        build_openssl
    fi
348
349
    fetch_unpack https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz
    (cd curl-${CURL_VERSION} \
Andrew Murray's avatar
Andrew Murray committed
350
        && if [ -z "$IS_MACOS" ]; then \
351
352
        LIBS=-ldl ./configure $flags; else \
        ./configure $flags; fi\
353
        && make -j4 \
354
355
356
357
        && make install)
    touch curl-stamp
}

Matthew Brett's avatar
Matthew Brett committed
358
359
360
361
362
363
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
Andrew Murray's avatar
Andrew Murray committed
364
    if [ -n "$IS_MACOS" ]; then
Matthew Brett's avatar
Matthew Brett committed
365
366
367
368
369
370
371
372
373
374
375
376
377
        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 \
378
        && make -j4 \
Matthew Brett's avatar
Matthew Brett committed
379
380
381
382
        && make install)
    touch openssl-stamp
}

383
384
385
386
387
388
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
389
        && ./configure --prefix=$BUILD_PREFIX --enable-dap \
390
        && make -j4 \
391
392
393
        && make install)
    touch netcdf-stamp
}
xoviat's avatar
xoviat committed
394

395
function build_pcre {
396
    build_simple pcre $PCRE_VERSION https://ftp.pcre.org/pub/pcre
xoviat's avatar
xoviat committed
397
398
}

xoviat's avatar
xoviat committed
399
function build_swig {
Andrew Murray's avatar
Andrew Murray committed
400
    if [ -e swig-stamp ]; then return; fi
Andrew Murray's avatar
Andrew Murray committed
401
    if [ -n "$IS_MACOS" ]; then
xoviat's avatar
xoviat committed
402
403
        brew install swig > /dev/null
    else
404
        build_pcre
405
        build_simple swig $SWIG_VERSION https://prdownloads.sourceforge.net/swig
xoviat's avatar
xoviat committed
406
    fi
Andrew Murray's avatar
Andrew Murray committed
407
    touch swig-stamp
xoviat's avatar
xoviat committed
408
409
}

xoviat's avatar
xoviat committed
410
function build_suitesparse {
Andrew Murray's avatar
Andrew Murray committed
411
    if [ -e suitesparse-stamp ]; then return; fi
Andrew Murray's avatar
Andrew Murray committed
412
    if [ -n "$IS_MACOS" ]; then
xoviat's avatar
xoviat committed
413
        brew install suite-sparse > /dev/null
mattip's avatar
mattip committed
414
    elif [[ $MB_ML_VER == "_2_24" ]]; then
mattip's avatar
mattip committed
415
        # debian:9 based distro
mattip's avatar
mattip committed
416
        apt-get install -y libsuitesparse-dev > /dev/null
xoviat's avatar
xoviat committed
417
    else
mattip's avatar
mattip committed
418
        # centos based distro
419
        yum_install suitesparse-devel > /dev/null
xoviat's avatar
xoviat committed
420
    fi
Andrew Murray's avatar
Andrew Murray committed
421
    touch suitesparse-stamp
xoviat's avatar
xoviat committed
422
}
423
424

function build_libtool {
425
    build_simple libtool $LIBTOOL_VERSION https://ftp.gnu.org/gnu/libtool
426
427
428
}

function build_ragel {
Matthew Brett's avatar
Matthew Brett committed
429
    local htprefix=https
Andrew Murray's avatar
Andrew Murray committed
430
    if [ -n "$IS_MACOS" ]; then
Matthew Brett's avatar
Matthew Brett committed
431
432
433
434
435
436
        # Invalid certificate, when using macOS curl.
        # https://security.stackexchange.com/questions/232445/https-connection-to-specific-sites-fail-with-curl-on-macos
        # Cert will likely be removed by Safari update in due course.
        htprefix=http
    fi
    build_simple ragel $RAGEL_VERSION ${htprefix}://www.colm.net/files/ragel
437
438
439
}

function build_bison {
440
    build_simple bison $BISON_VERSION https://ftp.gnu.org/gnu/bison
441
442
443
444
445
446
447
}

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
448

Alex Rothberg's avatar
Alex Rothberg committed
449
450
451
452
function build_fftw_case {
    local configure_args=${@:0}

    build_simple fftw $FFTW_VERSION \
453
        http://www.fftw.org tar.gz \
Alex Rothberg's avatar
Alex Rothberg committed
454
455
456
457
458
        --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
459
460
function build_fftw {
    echo 'Building fftw'
Alex Rothberg's avatar
Alex Rothberg committed
461
462
463
464

    # Save off current CFLAGS
    local old_cflags=$CFLAGS

Alex Rothberg's avatar
Alex Rothberg committed
465
466
467
468
469
    # 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
470
    build_fftw_case --enable-float --enable-sse --enable-sse2 --enable-avx
Alex Rothberg's avatar
Alex Rothberg committed
471
472
473
474
475
476

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

    # double
    echo 'Building fftw: double'
Alex Rothberg's avatar
Alex Rothberg committed
477
    build_fftw_case --enable-sse2 --enable-avx
Alex Rothberg's avatar
Alex Rothberg committed
478
479
480
481
482
483

    # 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
484
    build_fftw_case --enable-long-double
Alex Rothberg's avatar
Alex Rothberg committed
485
486
487
488
489
490
491
492
493
494
495
496

    # 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
497
498
    # restore CFLAGS
    export CFLAGS=$old_cflags
Alex Rothberg's avatar
Alex Rothberg committed
499
}
Simon Conseil's avatar
Simon Conseil committed
500
501

function build_cfitsio {
Simon Conseil's avatar
Simon Conseil committed
502
    if [ -e cfitsio-stamp ]; then return; fi
Andrew Murray's avatar
Andrew Murray committed
503
    if [ -n "$IS_MACOS" ]; then
Simon Conseil's avatar
Simon Conseil committed
504
505
506
507
508
509
510
511
512
        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
513
    touch cfitsio-stamp
Simon Conseil's avatar
Simon Conseil committed
514
}