#!/usr/bin/env bash
cd src
## All sagelib-building is done by setup.py.
## This is so that sagelib can be installed by standard Python procedures,
## such as "./setup.py install" or "pip install ."
##
## We poison all environment variables that have paths to the sage source and build directories.
## In this way we make sure that all of the sagelib build's source paths are communicated through
## the current directory (for the source tree).
## Building takes places in the build/ subdirectory.
##
## As a special exception, we feed SAGE_PKGS and SAGE_SPKG_INST.
## They are needed by src/sage_setup/optional_extension.py
## via src/sage/misc/package.py.  See meta-ticket #28815 for planned changes to this.

export SAGE_PKGS="$SAGE_ROOT"/build/pkgs
export SAGE_ROOT=/doesnotexist
export SAGE_SRC=/doesnotexist
export SAGE_SRC_ROOT=/doesnotexist
export SAGE_DOC_SRC=/doesnotexist
export SAGE_BUILD_DIR=/doesnotexist

export PYTHON="$SAGE_LOCAL/bin/python3"

# We also poison all directories below SAGE_LOCAL.

export SAGE_ETC=/doesnotexist
export SAGE_PKGCONFIG=/doesnotexist
export SAGE_PKG_CONFIG_PATH=/doesnotexist
export SAGE_SPKG_SCRIPTS=/doesnotexist
export SAGE_DOC=/doesnotexist
export SAGE_SHARE=/doesnotexist

# Trac #29411: We cannot poison SAGE_LOCAL because the pkg-config script
# installed by the pkgconf spkg, generated from build/pkgs/pkgconf/patches/pkg-config.in,
# uses this variable.
# export SAGE_LOCAL=/doesnotexist

time "$PYTHON" -u setup.py --no-user-cfg build install || exit 1
if [ "$UNAME" = "CYGWIN" ]; then
    sage-rebase.sh "$SAGE_LOCAL" 2>/dev/null;
fi
