build_libs - UK-FVCOM-Usergroup/uk-fvcom GitHub Wiki

#!/usr/bin/env bash

set -eu

# Build the libraries needed for WRF. Omit the MPI one as we will need to use
# the cluster one instead.

# Set up the environment
module load mpi/mpich-x86_64                   # for parallel runs

GET=${GET:-yes} # set to no to skip download and extraction of the archives

if [ $GET == 'yes' ]; then
    wget \
        --header='Host: www2.mmm.ucar.edu' \
        --header='User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0' \
        --header='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
        --header='Accept-Language: en-GB,en;q=0.5' \
        --header='DNT: 1' \
        --header='Content-Type: application/x-www-form-urlencoded' \
        'http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/netcdf-4.1.3.tar.gz' \
        -c
    wget \
        --header='Host: www2.mmm.ucar.edu' \
        --header='User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0' \
        --header='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
        --header='Accept-Language: en-GB,en;q=0.5' \
        --header='DNT: 1' \
        --header='Content-Type: application/x-www-form-urlencoded' \
        'http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz' \
        -c
    wget \
        --header='Host: www2.mmm.ucar.edu' \
        --header='User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0' \
        --header='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
        --header='Accept-Language: en-GB,en;q=0.5' \
        --header='DNT: 1' \
        --header='Content-Type: application/x-www-form-urlencoded' \
        'http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz' \
        -c
    wget \
        --header='Host: www2.mmm.ucar.edu' \
        --header='User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0' \
        --header='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
        --header='Accept-Language: en-GB,en;q=0.5' \
        --header='DNT: 1' \
        --header='Content-Type: application/x-www-form-urlencoded' \
        'http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.7.tar.gz' \
        -c

    # Extract if we haven't already.
    if [ ! -d netcdf-4.1.3 ]; then
        tar xvf netcdf-4.1.3.tar.gz
    fi
    if [ ! -d jasper-1.900.1 ]; then
        tar xvf jasper-1.900.1.tar.gz
    fi
    if [ ! -d libpng-1.2.50 ]; then
        tar xvf libpng-1.2.50.tar.gz
    fi
    if [ ! -d zlib-1.2.7 ]; then
        tar xvf zlib-1.2.7.tar.gz
    fi
fi

# Do the builds. Largely lifted from:
# http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php

# netCDF
export DIR=$(readlink -f $(pwd))
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64

cd netcdf-4.1.3
./configure --prefix=$DIR/netcdf --disable-dap \
     --disable-netcdf-4 --disable-shared
make -j 16
make install
export PATH=$DIR/netcdf/bin:$PATH
export NETCDF=$DIR/netcdf
cd ~-

# zlib
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include

cd zlib-1.2.7
./configure --prefix=$DIR/grib2
make -j 16
make install
cd ~-

# libpng
cd libpng-1.2.50
./configure --prefix=$DIR/grib2
make -j 16
make install
cd ~-

# JasPer
cd jasper-1.900.1
./configure --prefix=$DIR/grib2
make -j 16
make install
cd ~-