#!/usr/bin/env bash
if [ "$SAGE_LOCAL" = "" ]; then
echo "SAGE_LOCAL undefined ... exiting";
echo "Maybe run 'sage -sh'?"
exit 1
fi
cd src
echo "Applying patches to upstream sources..."
for patch in ../patches/*.patch; do
[ -r "$patch" ] || continue # Skip non-existing or non-readable patches
patch -p1 <"$patch"
if [ $? -ne 0 ]; then
echo >&2 "Error: '$patch' failed to apply."
exit 1
fi
done
INCLUDES="-I$SAGE_LOCAL/include/"
CFLAGS="$CFLAGS -fPIC $INCLUDES -L$SAGE_LOCAL/lib"
CXXFLAGS="$CXXFLAGS -fPIC $INCLUDES -L$SAGE_LOCAL/lib"
CPPFLAGS="$INCLUDES"
# Allow the user to specify a compiler flag for 64-bit builds.
# This will be -m64 with both Sun Studio and gcc, but other compilers
# such as those from IBM on AIX and HP on HP-UX use different flags.
if [ -z $CFLAG64 ] ; then
CFLAG64=-m64
fi
if [ -z $CXXFLAG64 ] ; then
CXXFLAG64=-m64
fi
if [ "x$SAGE64" = xyes ]; then
echo "Building a 64-bit version of libfplll"
CFLAGS="$CFLAGS $CFLAG64"
CXXFLAGS="$CXXFLAGS $CXXFLAG64"
CPPFLAGS="$CPPFLAGS $CFLAG64"
CC="$CC $CFLAG64"
CXX="$CXX $CXXFLAG64"
fi
if [ "$UNAME" = "CYGWIN" ]; then
echo "Disable parallel building on Cygwin"
MAKE="$MAKE -j1"
export MAKE
fi
export CFLAGS
export CXXFLAGS
export CPPFLAGS
export CC
export CXX
echo "Now configuring libfplll..."
./configure --prefix="$SAGE_LOCAL" --libdir="$SAGE_LOCAL/lib" --includedir="$SAGE_LOCAL/include/fplll"
if [ $? -ne 0 ]; then
echo "Error configuring libfplll"
exit 1
fi
echo "Now building libfplll..."
$MAKE
if [ $? -ne 0 ]; then
echo "Error building libfplll"
exit 1
fi
echo "Now installing libfplll..."
$MAKE install
if [ $? -ne 0 ]; then
echo "Error installing libfplll"
exit 1
fi