###########################################
## Python
###########################################

# It is best to unset these environment variables, as they might confuse
# the Python installer.
unset PYTHONHOME
unset PYTHONPATH

# Prevent use of the system hg and svn as it might make the installation fail
export HAS_HG=no
export SVNVERSION=no

cd src

# Running 'make install' in parallel is a bad idea, so we use
# only 1 job.
# The "-i" option to ignore errors is crucial, especially in the
# case of upgrades.
sdh_make_install -i -j1

echo "Installing valgrind suppression file..."
SUPP_FILENAME="python3.supp"
sdh_install -T Misc/valgrind-python.supp "$SAGE_LOCAL/lib/valgrind/$SUPP_FILENAME"

if [ "$UNAME" = "Linux" ]; then
    export LD_LIBRARY_PATH="."
elif [ "$UNAME" = "Darwin" ]; then
    export DYLD_LIBRARY_PATH="."
fi

# When building on a case-insensitive filesystem (on any OS, not just Windows)
# the Python executable is output to the build directory as 'python.exe'
if [ -f "python.exe" ]; then
    PYTHON="./python.exe"
else
    PYTHON="./python"
fi

PYTHON_VERSION=$($PYTHON -c 'import sys; print("%d.%d" % sys.version_info[:2])')
PYTHON_ABIFLAGS=$($PYTHON -c 'import sys; print(sys.abiflags)')
PYTHON_LDVERSION="$PYTHON_VERSION$PYTHON_ABIFLAGS"
PYTHON_CONFIG_DIR="$SAGE_LOCAL/lib/python${PYTHON_VERSION}/config-${PYTHON_LDVERSION}"

# On OS X with XCode 4, the presence of
# $SAGE_LOCAL/lib/python3.x/config/libpython3.x.a causes problems with
# GiNaC -- see #11967.  It is easiest to test the version of OS X; we
# delete this file if using OS X 10.6 or later (so `uname -r` returns
# x.y.z with x >= 10).
if [ "$UNAME" = "Darwin" ] && \
    [ `uname -r | cut '-d.' -f1` -gt 9 ]; then
    rm -f "${SAGE_DESTDIR}${PYTHON_CONFIG_DIR}/libpython${PYTHON_LDVERSION}.a"
fi
