#!/usr/bin/env bash
if [ "$SAGE_LOCAL" = "" ]; then
echo "SAGE_LOCAL undefined ... exiting";
echo "Maybe run 'sage -sh'?"
exit 1
fi
if [ $UNAME = "CYGWIN" ]; then
cp patches/expr "$SAGE_LOCAL/bin"
fi
if [ $UNAME = "Darwin" ]; then
# OSX does not have fontconfig, often causes problems with 3rd party distributions
LIBGD_CONFIGURE="--without-fontconfig $LIBGD_CONFIGURE"
fi
# Critical to get rid of old versions, since they will break the install, since
# at some point one of the libraries accidently links against what's in SAGE_LOCAL,
# instead of what is in the build directory!
rm "$SAGE_LOCAL"/lib/libgd.*
cd src
# Needed to correctly pickup libiconv on FreeBSD
if [ `uname` = "FreeBSD" ] ; then
LDFLAGS="-L/usr/local/lib"; export LDFLAGS
fi
# needed to pick up zlib.h
if [ "x$SAGE64" = xyes ]; then
CFLAGS=" -m64 $CFLAGS -fPIC -g -I\"$SAGE_LOCAL/include\" -I$SAGE_LOCAL/include/freetype2/"
LDFLAGS="-m64 -L$SAGE_LOCAL/lib"; export LDFLAGS
else
CFLAGS="$CFLAGS -fPIC -g -I\"$SAGE_LOCAL/include\" -I$SAGE_LOCAL/include/freetype2/"
fi
export CFLAGS
# We explicitly disable X support, since (1) X is not a SAGE dependency,
# and (2) the gd build fails on a lot of OS X PPC machines when X is enabled.
./configure --prefix="$SAGE_LOCAL" --libdir="$SAGE_LOCAL/lib" --without-jpeg --without-x --with-zlib="$SAGE_LOCAL" --with-freetype="$SAGE_LOCAL" --without-xpm $LIBGD_CONFIGURE
if [ $? -ne 0 ]; then
echo "Error configuring gd."
exit 1
fi
$MAKE
if [ $? -ne 0 ]; then
echo "Error building gd."
exit 1
fi
$MAKE install
if [ $? -ne 0 ]; then
echo "Error installing gd."
exit 1
fi