if [ -z "$SAGE_LOCAL" ]; then
    echo >&2 "SAGE_LOCAL undefined ... exiting"
    echo >&2 "Maybe run 'sage --sh'?"
    exit 1
fi

cd src

# Use newer version of config.guess and config.sub (see Trac #19714)
cp "$SAGE_ROOT"/config/config.* config

# The following prevents autotools to regenerate its files.
touch aclocal.m4 configure Makefile.in config.h.in
touch src/platform.hpp.in

# Do not treat warnings as errors, see
# https://github.com/zeromq/libzmq/issues/2818
# We put this in CPPFLAGS such that it does not override the default
# CXXFLAGS of zeromq.
export CPPFLAGS="$CPPFLAGS -Wno-error"

./configure --prefix="$SAGE_LOCAL" --libdir="$SAGE_LOCAL"/lib
if [ $? -ne 0 ]; then
    echo >&2 "Failed to configure zeromq"
    exit 1
fi

$MAKE
if [ $? -ne 0 ]; then
    echo >&2 "Failed to build zeromq"
    exit 1
fi

$MAKE -j1 install
if [ $? -ne 0 ]; then
    echo >&2 "Failed to install zeromq"
    exit 1
fi
