#!/usr/bin/env bash

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

export LDFLAGS="$LDFLAGS -lz -lbz2"
#export CPPFLAGS="-DHAVE_CLOCK_GETTIME=0"

# See discussion on #12220
#
#-> Mac and Linux behave differently according to the presence of librt, and a
#   good way around if to make the computer believe that it does not exist
#   locally, or more precisely that it does not contain the clock_gettime
#   function. Cbc uses an alternative method to do the job, and it looks like
#   all this is required when Cbc solves LP with several threads.
#
cd src &&
sed -i -e "s/clock\_gettime ()/Grrrrrrrrrrrr\ ()/g" Cbc/configure &&
./configure --prefix="$SAGE_LOCAL" "${args[@]}" --enable-cbc-parallel --enable-parallel --enable-gnu-packages --enable-static &&
make &&
make install
