Ok.
Voici la partie qui semble concernée et la totalité du fichier.
# Check that $HOME exists
if [ "$HOME" = "" ]; then
echo >&2 'Error: environment variable $HOME is not set.'
return 1
fi
if ! [ -d "$HOME" ]; then
echo >&2 "Error: HOME directory '$HOME' does not exist."
return 1
fi
# -*- shell-script -*-
###########################################################################
#
# Set environment variables for building and/or running Sage.
# You must *source* this instead of executing; see below!
#
# IMPORTANT: use "return" instead of "exit" to signal a failure when
# sourcing this script. An "exit" here will actually exit
# spkg/bin/sage, which is probably not intented.
#
# AUTHORS: William Stein 2005-12
# David Kirkby <david.kirkby@onetel.net> 2005-12-17
#
###########################################################################
##########################################################################
#
# If you want to set all environment variables for your shell like
# they are during the build of Sage packages, type
#
# source spkg/bin/sage-env
#
# from the SAGE_ROOT directory. To do the same from a /bin/bash
# script use ". spkg/bin/sage-env".
#
##########################################################################
# Resolve all symbolic links in a filename. This more or less behaves
# like "readlink -f" except that it does not convert the filename to an
# absolute path (a relative path remains relative), nor does it treat
# "." or ".." specially.
#
# AUTHOR: Jeroen Demeyer (2011-08-23): Trac tickets #5852 and #11704
#
resolvelinks() {
# $in is what still needs to be converted (normally has no starting slash)
in="$1"
# $out is the part which is converted (normally ends with trailing slash)
out="./"
# Move stuff from $in to $out
while [ -n "$in" ]; do
# Normalize $in by replacing consecutive slashes by one slash
while { in_single_slash=${in//\/\//\/}; [ "$in" != "$in_single_slash" ]; }; do
in=$in_single_slash
done
# If $in starts with a slash, remove it and set $out to the root
in_without_slash=${in/#\//}
if [ "$in" != "$in_without_slash" ]; then
in=$in_without_slash
out="/"
continue
fi
# Check that the directory $out exists by trying to cd to it.
# If this fails, then cd will show an error message (unlike
# test -d "$out"), so no need to be more verbose.
( cd "$out" ) || return $?
# Get the first component of $in
f=${in%%/*}
# If it is not a symbolic link, simply move it to $out
if [ ! -L "$out$f" ]; then
in=${in#"$f"}
out="$out$f"
# If the new $in starts with a slash, move it to $out
in_without_slash=${in/#\//}
if [ "$in" != "$in_without_slash" ]; then
in=$in_without_slash
out="$out/"
fi
continue
fi
# Now resolve the symbolic link "$f"
f_resolved=`readlink -n "$out$f" 2>/dev/null`
status=$?
# status 127 means readlink could not be found.
if [ $status -eq 127 ]; then
# We don't have "readlink", try a stupid "ls" hack instead.
# This will fail if we have filenames like "a -> b".
fls=`ls -l "$out$f" 2>/dev/null`
status=$?
f_resolved=${fls##*-> }
# If $fls equals $f_resolved, then certainly
# something is wrong
if [ $status -eq 0 -a "$fls" = "$f_resolved" ]; then
echo >&2 "Cannot parse output from ls -l '$out$f'"
return 1
fi
fi
if [ $status -ne 0 ]; then
echo >&2 "Cannot read symbolic link '$out$f'"
return $status
fi
# In $in, replace $f by $f_resolved (leave $out alone)
in=${in/#"$f"/"$f_resolved"}
done
# Return $out
echo "$out"
}
# New value for SAGE_ROOT: either SAGE_ROOT (if given)
# or a guessed value based on pwd.
if [ -n "$SAGE_ROOT" ]; then
NEW_SAGE_ROOT="$SAGE_ROOT"
elif [ -f sage -a -d spkg ]; then
NEW_SAGE_ROOT="."
elif [ -f ../../sage -a -d ../../spkg ]; then
NEW_SAGE_ROOT="../.."
else
# No idea what SAGE_ROOT should be...
echo >&2 "Error: You must set the SAGE_ROOT environment variable or run this"
echo >&2 "script from the SAGE_ROOT or SAGE_ROOT/local/bin/ directory."
return 1
fi
# Make NEW_SAGE_ROOT absolute
NEW_SAGE_ROOT=`cd "$NEW_SAGE_ROOT" && pwd -P`
# Sanity check NEW_SAGE_ROOT
if [ -f "$NEW_SAGE_ROOT/sage" -a -d "$NEW_SAGE_ROOT/spkg" ]; then
:
else
echo >&2 "Error: SAGE_ROOT is set to a bad value:"
echo >&2 "SAGE_ROOT=$SAGE_ROOT"
echo >&2 "You must correct it or erase it and run this script from the SAGE_ROOT"
echo >&2 "or SAGE_ROOT/local/bin/ directory."
return 1
fi
# Warn if NEW_SAGE_ROOT does not equal the old SAGE_ROOT
if [ "$SAGE_ROOT" != "$NEW_SAGE_ROOT" -a -n "$SAGE_ROOT" ]; then
echo >&2 "Warning: overwriting SAGE_ROOT environment variable:"
echo >&2 "Old SAGE_ROOT=$SAGE_ROOT"
echo >&2 "New SAGE_ROOT=$NEW_SAGE_ROOT"
fi
# Don't execute the commands more than once. Check this after
# checking the validity of SAGE_ROOT, but before modifying its value.
#
# NOTE: This requires all environment variables to be exported, otherwise
# they won't be available / set in subshells which do not (fully)
# source sage-env themselves.
if [ "x$SAGE_ENV_SOURCED" = "x" ]; then
SAGE_ENV_SOURCED=1
export SAGE_ENV_SOURCED
else
# Already sourced, nothing to do.
return 0
fi
SAGE_ROOT="$NEW_SAGE_ROOT"
export SAGE_ROOT
# Call with: contains_spaces X${VAR}X
# i.e., WITHOUT quotes but some character(s) around the environment variable to test.
# (This function does return false for empty/unset variables.)
contains_spaces()
{
if [ $# -ne 1 ]; then
return 0 # true
else
return 1 # false
fi
}
if contains_spaces X${SAGE_ROOT}X ; then
echo "Error: The path to the Sage directory (\$SAGE_ROOT) MUST NOT contain spaces."
echo "It is currently \"$SAGE_ROOT\"."
echo "Please correct this by moving Sage (or renaming one or more directories) first."
echo "Exiting now..."
return 1
fi
if [ 1 = 2 ]; then
echo "The following enviroment variables can be set by the user"
echo "AR The archiver (e.g. ar, /usr/ccs/bin/ar or /usr/bin/ar)"
echo "AS The assembler (e.g. as, /usr/ccs/bin/as or /usr/bin/as)"
echo "CC The C compiler (e.g cc, /opt/SUNWspro/bin/cc or /usr/bin/gcc)"
echo "CFLAGS Flag(s) for the C compiler (e.g. -g -Wall -O2)"
echo " (You are advised to a some optimisation flag(s), such as -O2 or -xO2 to CFLAGS)"
echo "CXX The C++ compiler (e.g g++, /opt/SUNWspro/bin/CC or /usr/local/bin/g++)"
echo "CXXFLAGS Flag(s) for the C++ compiler (e.g. -fast -fsimple=1 -x04)"
echo "LD The linker (e.g. ld, /usr/ccs/bin/ld or /usr/bin/ld)"
echo "LDFLAGS Linker flag(s) (e.g. -D token)"
echo "LN Used to make links (e.g. ln, /usr/xpg4/bin/ln or /usr/bin/ln)"
echo "MAKE The make program (e.g. make, /usr/bin/make or /usr/local/bin/gmake)"
echo "MAKEFLAGS Flag(s) to make (e.g. -j4)."
echo "RANLIB Archiver ranlib (e.g. ranlib, /usr/ccs/bin/ranlib etc)"
echo "SAGE64 Set to \"yes\" to build a 64-bit binary (Solaris SPARC or Solaris x86 only)"
echo "SHAREDFLAGS Flag(s) necessary for building a shared library (e.g. -fPIC or -xcode=pic32)"
echo "We attempt to set this to sensible values, but check below to"
echo "ensure they are OK. If you wish to override any then please use:"
echo "setenv NAME_OF_ENVIROMENT_VARIABLE value_of_enviroment_variable"
echo "(if you use tcsh, csh or a similar shell) or"
echo "NAME_OF_ENVIROMENT_VARIABLE value_of_enviroment_variable"
echo "export NAME_OF_ENVIROMENT_VARIABLE"
echo "if you use sh, bash or a similar shell"
fi
# Setting Sage-related location environment variables.
export SAGE_LOCAL="$SAGE_ROOT/local"
export SAGE_DATA="$SAGE_ROOT/data"
export SAGE_PACKAGES="$SAGE_ROOT/spkg"
export SAGE_LOGS="$SAGE_ROOT/spkg/logs"
export SAGE_DOC="$SAGE_ROOT/devel/sage/doc"
export PATH="$SAGE_PACKAGES/bin:$SAGE_LOCAL/bin:$PATH"
# We offer a toolchain option, so if $SAGE_LOCAL/toolchain/toolchain-env exists source it.
# Since the user might do something crazy we do not do any checks, but hope for the best.
if [ -f $SAGE_LOCAL/toolchain/toolchain-env ]; then
source $SAGE_LOCAL/toolchain/toolchain-env
fi
# Mac OS X-specific setup
if [ `uname` = "Darwin" ]; then
# For a framework Python build on OS X, Python's bin directory is not local/bin
PATH="$SAGE_LOCAL/Frameworks/Python.framework/Versions/2.5/bin:$PATH" && export PATH
# set MACOSX_DEPLOYMENT_TARGET -- if set incorrectly, this can
# cause lots of random "Abort trap" issues on OSX. see trac
# #7095 for an example.
MACOSX_VERSION=`uname -r | awk -F. '{print $1}'`
MACOSX_DEPLOYMENT_TARGET=10.$[$MACOSX_VERSION-4]
export MACOSX_DEPLOYMENT_TARGET
fi
if [ "$LIBRARY_PATH" != "" ]; then
LIBRARY_PATH="$SAGE_LOCAL/lib/:$LIBRARY_PATH"
else
LIBRARY_PATH="$SAGE_LOCAL/lib/"
fi
export LIBRARY_PATH
GP_DATA_DIR="$SAGE_LOCAL/share/pari" && export GP_DATA_DIR
GPHELP="$SAGE_LOCAL/bin/gphelp" && export GPHELP
GPDOCDIR="$SAGE_LOCAL/share/pari/doc" && export GPDOCDIR
# Make Mercurial always use utf-8 for usernames,...
# See Trac Ticket #11830
HGENCODING="utf8" && export HGENCODING
# Make Mercurial not use any user defaults (like enabling the pager extension)
# This is needed in order to use mercurial in scripts. When running hg
# directly through "sage -hg", we will disable HGPLAIN in spkg/bin/sage.
# See Trac Ticket #12058
HGPLAIN="yes" && export HGPLAIN
SINGULARPATH="$SAGE_LOCAL/share/singular" && export SINGULARPATH
SINGULAR_EXECUTABLE="$SAGE_LOCAL/bin/Singular" && export SINGULAR_EXECUTABLE
if [ "$SAGE_SERVER" = "" ]; then
SAGE_SERVER="http://www.sagemath.org/"
export SAGE_SERVER
fi
# Check that $HOME exists
if [ "$HOME" = "" ]; then
echo >&2 'Error: environment variable $HOME is not set.'
return 1
fi
if ! [ -d "$HOME" ]; then
echo >&2 "Error: HOME directory '$HOME' does not exist."
return 1
fi
if [ "$DOT_SAGE" = "" ]; then
# It is *not* an error if this directory does not exist, it will
# be created in spkg/bin/sage. This also works if $HOME/.sage is a
# symbolic link to a non-existing directory.
DOT_SAGE=`resolvelinks "$HOME/.sage"`
# In theory, DOT_SAGE is not required to have a trailing slash.
# But since there are some issues (#11924, maybe #12221),
# we add a slash for safety.
DOT_SAGE="${DOT_SAGE}/"
export DOT_SAGE
fi
if [ "$SAGE_STARTUP_FILE" = "" ]; then
SAGE_STARTUP_FILE="$DOT_SAGE/init.sage"
export SAGE_STARTUP_FILE
fi
if [ -d "$SAGE_ROOT/local/lib/python" ]; then
PYTHONPATH="$SAGE_ROOT/local/lib/python"
if [ -n "$SAGE_PATH" ]; then
PYTHONPATH="$SAGE_PATH:$PYTHONPATH"
fi
PYTHONHOME="$SAGE_ROOT/local"
export PYTHONPATH
export PYTHONHOME
fi
if [ -z "${SAGE_ORIG_LD_LIBRARY_PATH_SET}" ]; then
SAGE_ORIG_LD_LIBRARY_PATH=$LD_LIBRARY_PATH && export SAGE_ORIG_LD_LIBRARY_PATH
SAGE_ORIG_LD_LIBRARY_PATH_SET=True && export SAGE_ORIG_LD_LIBRARY_PATH_SET
fi
# Should this be a temporary directory instead? Since sage-ptest and
# sage-test are written in Python, we can set it to
# tempfile.gettempdir() there.
if [ -z "$SAGE_TESTDIR" ]; then
SAGE_TESTDIR="$DOT_SAGE"/tmp && export SAGE_TESTDIR
fi
# Use a matplotlib config directory specific to Sage and specific to
# the version number of matplotlib, by setting the environment
# variable MPLCONFIGDIR. See
# http://trac.sagemath.org/sage_trac/ticket/6235 and
# http://trac.sagemath.org/sage_trac/ticket/9221. Find the version
# number for matplotlib by reading the file
# SAGE_LOCAL/lib/python/site-packages/matplotlib/__init__.py, and use
# the version number in the name of the directory. If that file
# doesn't exist, matplotlib hasn't been installed yet, so don't set
# MPLCONFIGDIR.
MPLINITFILE="$SAGE_LOCAL/lib/python/site-packages/matplotlib/__init__.py"
if [ -f "$MPLINITFILE" ]; then
MPLVERSION=`sed -n "/^__version__[ ]*=/s/[^']*'\([^']*\)'.*$/\1/p" "$MPLINITFILE"`
if [ "$MPLVERSION" != "" ]; then
MPLCONFIGDIR="$DOT_SAGE/matplotlib-$MPLVERSION"
else
# MPLVERSION is empty, so no version found.
MPLCONFIGDIR="$DOT_SAGE/matplotlib"
fi
export MPLCONFIGDIR
# Create the directory, because matplotlib doesn't seem to be happy otherwise.
mkdir -p "$MPLCONFIGDIR"
fi
# Add some directories to $LD_LIBRARY_PATH:
# * lib/openmpi is needed for openmpi.
# * lib/R/lib is needed for R in case the Sage install is moved.
# * lib32 and lib64 are needed for GCC, see #12405.
for d in lib/openmpi lib/R/lib lib32 lib64 lib; do
libdir="$SAGE_LOCAL/$d"
# Add only existing directories
if [ -d "$libdir" ]; then
LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
fi
done
export LD_LIBRARY_PATH
# The following is needed for OS X (especially for the
# Singular install).
if [ `uname` = "Darwin" ]; then
if [ -z "${SAGE_ORIG_DYLD_LIBRARY_PATH_SET}" ]; then
SAGE_ORIG_DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH && export SAGE_ORIG_DYLD_LIBRARY_PATH
SAGE_ORIG_DYLD_LIBRARY_PATH_SET=True && export SAGE_ORIG_DYLD_LIBRARY_PATH_SET
fi
DYLD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH:$SAGE_LOCAL/lib/R/lib" && export DYLD_LIBRARY_PATH
fi
if [ "$1" = "-short" ]; then
return 0
fi
if [ -z "$RHOME" ]; then
RHOME="$SAGE_LOCAL/lib/R" && export RHOME
fi
MAXIMA_PREFIX="$SAGE_ROOT/local" && export MAXIMA_PREFIX
# PKG_CONFIG_PATH is used by 'pkg-config' on Solaris and Linux,
# but at least some versions of OS X do not have the pkg-config
# command, so relying on this is not wise on OS X.
if [ -z "$PKG_CONFIG_PATH" ]; then
PKG_CONFIG_PATH="$SAGE_LOCAL/lib/pkgconfig"
else
PKG_CONFIG_PATH="$SAGE_LOCAL/lib/pkgconfig:$PKG_CONFIG_PATH"
fi
export PKG_CONFIG_PATH
############ compilation flags
UNAME=`uname`
if [ `uname | sed -e 's/WIN.\+/WIN/'` = "CYGWIN" ]; then
UNAME="CYGWIN"
fi
export UNAME
# Setting Sage-related compilation flags.
# This could be used in code to make special changes only when
# code is being built as part of Sage.
export __sage__=""
# Set the C and C++ compilers
if [ -z "$CC" ]; then
# On OS X 10.7 (Lion) or later when building GCC, use clang as
# default C compiler as some older versions of XCode 4 ship broken
# versions of GCC which fail to bootstrap GCC-4.6.3.
# See http://trac.sagemath.org/sage_trac/ticket/12820
if [ "$SAGE_BUILD_TOOLCHAIN" = yes ] && [ "$UNAME" = Darwin ] && [ `uname -r | cut -d. -f1` -ge 11 ]; then
CC=`which clang 2>/dev/null`
fi
fi
if [ -z "$CC" ]; then
CC=gcc
fi
if [ -z "$CXX" ]; then
CXX=g++
fi
# An Objective-C compiler is needed for R on Darwin.
# On Darwin, /usr/bin/cc supports Objective-C. The gcc shipped with
# Sage doesn't.
if [ "$UNAME" = "Darwin" ]; then
if [ -z "$OBJC" -a -x "/usr/bin/cc" ]; then
export OBJC=/usr/bin/cc
fi
if [ -z "$OBJCXX" -a -x "/usr/bin/c++" ]; then
export OBJCXX=/usr/bin/c++
fi
fi
# Override CC and CXX if the gcc spkg was installed.
if [ -x "$SAGE_LOCAL/bin/gcc" ]; then
CC=gcc
fi
if [ -x "$SAGE_LOCAL/bin/g++" ]; then
CXX=g++
fi
export CC CXX
if [ "$LD" = "" ]; then
LD="ld" && export LD
fi
if [ "$AR" = "" ]; then
AR="ar" && export AR
fi
if [ "$AS" = "" ]; then
AS="as" && export AS
fi
if [ "$LDFLAGS" = "" ]; then
LDFLAGS="" && export LDFLAGS
fi
if [ "$SAGE64" = "" ]; then
SAGE64="no"
fi
if [ "$SAGE64" != "yes" -a "$SAGE64" != "no" ]; then
echo "The environment variable SAGE64 (=$SAGE64) must be either unset, yes or no."
return 1
fi
# In case SAGE64 has been set to yes before re-inject it into the environment
# This is only done on OSX and Solaris since those are the only real multi lib
# arches we support. Eventually Linux PPC on the PS3 might need to be added here
source "$SAGE_LOCAL/bin/sage-check-64" 1> /dev/null 2> /dev/null
export SAGE64
if [ "$CXXFLAGS" = "" ]; then
export CXXFLAGS="$CFLAGS"
fi
if [ "$CP" = "" ]; then
CP="cp" && export CP
fi
if [ "$MV" = "" ]; then
MV="mv" && export MV
fi
if [ "$RANLIB" = "" ]; then
RANLIB="ranlib" && export RANLIB
fi
if [ "$LN" = "" ]; then
LN="ln" && export LN
fi
if [ "$MKDIR" = "" ]; then
MKDIR="mkdir" && export MKDIR
fi
if [ "$CHMOD" = "" ]; then
CHMOD="chmod" && export CHMOD
fi
if [ "$TOUCH" = "" ]; then
TOUCH="touch" && export TOUCH
fi
if [ "$UNAME" = "CYGWIN" ]; then
PATH="$PATH:$SAGE_LOCAL/lib" && export PATH
fi
# See trac 7186 -- this is needed if ecl is moved
ECLDIR="$SAGE_LOCAL/lib/ecl/" && export ECLDIR
# Handle parallel building/testing/...
# See Trac Ticket #12016
# First, figure out the right values for SAGE_NUM_THREADS (default
# number of threads) and SAGE_NUM_THREADS_PARALLEL (default number of
# threads when parallel execution is asked explicitly).
sage_num_threads_array=(`sage-num-threads.py 2>/dev/null || echo 1 2 1`)
SAGE_NUM_THREADS=${sage_num_threads_array[0]}
SAGE_NUM_THREADS_PARALLEL=${sage_num_threads_array[1]}
export SAGE_NUM_THREADS
export SAGE_NUM_THREADS_PARALLEL
if [ "$MAKE" = "" ]; then
MAKE="make"
fi
# If MAKEFLAGS exists, assume it got set by make.
# Therefore, remove all flags from $MAKE
if [ "${MAKEFLAGS-__unset__}" != "__unset__" ]; then
MAKE=`echo "$MAKE" | sed 's/ .*//'`
fi
export MAKE
# You can set environment variables in $SAGE_RC_FILE
# (by default, this is the file $DOT_SAGE/sagerc). For example,
# setting PS1 there will set your prompt when you run "sage --sh".
if [ -z "$SAGE_RC_FILE" ]; then
SAGE_RC_FILE="$DOT_SAGE/sagerc"
fi
if [ -r "$SAGE_RC_FILE" ]; then
source "$SAGE_RC_FILE"
if [ $? -ne 0 ]; then
echo >&2 "Error sourcing $SAGE_RC_FILE"
exit 1
fi
fi