# @configure_input@

abs_builddir = @abs_builddir@
srcdir = @srcdir@
abs_top_srcdir = @abs_top_srcdir@

.PHONY: all sage clean

all: sage

## 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 ."
## BECAUSE OF THIS, DON'T ADD ADDITIONAL STEPS TO THIS MAKEFILE.

## We poison all environment variables that have paths to the sage source and build directories,
## but keep the directories below SAGE_LOCAL intact.
## 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.  This is needed by src/sage_setup/optional_extension.py
## via src/sage/misc/package.py.  Hoping that #20382 will make this unnecessary.
##
## TODO: Do also something about the SAGE_LOCAL stuff:
##  - some of it (our install) should be communicated only through --install-base;
##  - others (installed packages that we pull in) through some configuration mechanism.
##
## TODO: Currently providing --install-base=$(SAGE_LOCAL) leads to this error:
## [sagelib-7.4.beta4] running install
## [sagelib-7.4.beta4] error: install-base or install-platbase supplied, but installation scheme is incomplete
sage:
	cd $(srcdir) && export                                    \
	    SAGE_ROOT=/doesnotexist                               \
	    SAGE_SRC=/doesnotexist                                \
	    SAGE_SRC_ROOT=/doesnotexist                           \
	    SAGE_DOC_SRC=/doesnotexist                            \
	    SAGE_BUILD_DIR=/doesnotexist                          \
	    SAGE_PKGS=$(abs_top_srcdir)/build/pkgs                \
	&& sage-python23 -u setup.py --no-user-cfg build install
	if [ "$$UNAME" = "CYGWIN" ]; then                         \
	    sage-rebase.sh "$$SAGE_LOCAL" 2>/dev/null;            \
	fi

clean:
	@echo "Deleting Sage library build artifacts..."
	rm -rf c_lib .cython_version # from old sage versions
	rm -rf build
	find . -name '*.pyc' | xargs rm -f
	rm -rf sage/ext/interpreters
