#!/usr/bin/env bash ######################################################################## # Set various environment variables ######################################################################## # Assume current directory is SAGE_ROOT/build SAGE_ROOT=`cd .. && pwd -P` SAGE_SRC="$SAGE_ROOT/src" SAGE_LOCAL="$SAGE_ROOT/local" SAGE_SHARE="$SAGE_LOCAL/share" SAGE_EXTCODE="$SAGE_SHARE/sage/ext" SAGE_LOGS="$SAGE_ROOT/logs/pkgs" SAGE_SPKG_INST="$SAGE_LOCAL/var/lib/sage/installed" SAGE_VERSION=`cat $SAGE_ROOT/VERSION.txt | sed 's+.*\ \(.*\),.*+\1+'` PATH="$SAGE_ROOT/src/bin:$SAGE_LOCAL/bin:$PATH" PYTHONPATH="$SAGE_LOCAL" export SAGE_ROOT SAGE_SRC SAGE_LOCAL SAGE_EXTCODE SAGE_LOGS SAGE_SPKG_INST SAGE_VERSION PATH PYTHONPATH # Storing the start time of the build process. The time is stored in # seconds since 1970-01-01 in a hidden file called # "SAGE_ROOT/.BUILDSTART". See ticket #6744. echo `date -u "+%s"` > "$SAGE_ROOT/.BUILDSTART" ######################################################################## # Support for upgrading ######################################################################## # Check that we aren't accidentally upgrading from old (< 6.0) # versions of Sage. See #14715. # The file $SAGE_ROOT/spkg/install no longer exists in Sage 6.0, # but it did exist in all earlier versions. if [ -f "$SAGE_ROOT/spkg/install" ]; then cat >&2 <&2 </dev/null 2>/dev/null; then CXX=g++ fi fi if [ -z "$FC" ]; then if [ -n "$SAGE_FORTRAN" ]; then FC="$SAGE_FORTRAN" elif command -v gfortran >/dev/null 2>/dev/null; then FC=gfortran elif command -v g95 >/dev/null 2>/dev/null; then FC=g95 elif command -v g77 >/dev/null 2>/dev/null; then FC=g77 fi fi if [ -f "$SAGE_LOCAL/bin/gcc" ]; then # GCC is already installed. Normally we don't need to re-install # GCC, unless this is an upgrade. To disable unneeded rebuilding # of GCC, we touch the installed file for GCC, such that it will # really only be built if one of its dependencies has been upgraded. if [ "$SAGE_UPGRADING" = yes ]; then echo >&2 "We are upgrading Sage and GCC was installed before, it will get" echo >&2 "re-installed if needed." need_to_install_gcc=yes for f in "$SAGE_SPKG_INST"/gcc-*; do if [ -f "$f" ]; then touch "$f" fi done else need_to_install_gcc=no fi elif [ -n "$SAGE_INSTALL_GCC" ]; then # Check the value of the environment variable SAGE_INSTALL_GCC case "$SAGE_INSTALL_GCC" in yes) echo >&2 "Installing GCC because SAGE_INSTALL_GCC is set to 'yes'." need_to_install_gcc=yes;; no) need_to_install_gcc=no;; *) echo >&2 "Error: SAGE_INSTALL_GCC should be set to 'yes' or 'no'." echo >&2 "You can also leave it unset to install GCC when needed." exit 2;; esac else # SAGE_INSTALL_GCC is not set, install GCC when needed. need_to_install_gcc=no # Check whether $CC is some version of GCC. If it's a different # compiler, install GCC. CCtype=`testcc.sh $CC` if [ "$CCtype" != GCC ]; then echo >&2 "Installing GCC because your '$CC' isn't GCC (GNU CC)." need_to_install_gcc=yes else # $CC points to some version of GCC, find out which version. GCCVERSION=`$CC -dumpversion` case $GCCVERSION in [0-3].*|4.[0-3]|4.[0-3].*) # Install our own GCC if the system-provided one is older than gcc-4.4. # * gcc-4.2.4 compiles a slow IML: # https://groups.google.com/forum/?fromgroups#!topic/sage-devel/Ux3t0dW2FSI # * gcc-4.3 might have trouble building ATLAS: # https://groups.google.com/forum/?fromgroups#!topic/sage-devel/KCeFqQ_w2FE echo >&2 "Installing GCC because you have $CC version $GCCVERSION, which is quite old." need_to_install_gcc=yes;; 4.4*|4.5*) # GCC 4.4.x and GCC 4.5.x fail to compile PARI/GP on ia64: # * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46044 if [ x`uname -m` = xia64 ]; then echo >&2 "Installing GCC because you have $CC version $GCCVERSION on ia64." echo >&2 "gcc <= 4.5 fails to compile PARI/GP on ia64." need_to_install_gcc=yes fi;; 4.6.[01]) # Also install GCC if we have version 4.6.0 or 4.6.1, which is # known to give trouble within Sage: # * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48702 # * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48774 echo >&2 "Installing GCC because you have $CC version $GCCVERSION." echo >&2 "gcc-4.6.0 and gcc-4.6.1 have known bugs affecting Sage." need_to_install_gcc=yes;; 4.6*) # GCC 4.6.x doesn't compile ECL on Cygwin: # * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52061 if uname | grep CYGWIN >/dev/null; then echo >&2 "Installing GCC because you have $CC version $GCCVERSION on Cygwin." echo >&2 "gcc-4.6.x fails to compile ECL on Cygwin." need_to_install_gcc=yes fi;; 4.7.0) # GCC 4.7.0 is very broken on ia64, see # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48496 # This is fixed in GCC 4.7.1. if [ x`uname -m` = xia64 ]; then echo >&2 "Installing GCC because you have $CC version $GCCVERSION on ia64." echo >&2 "gcc-4.7.0 has a serious bug on ia64." need_to_install_gcc=yes fi;; esac fi # Check C++ and Fortran compilers. if [ -z "$CXX" ]; then echo >&2 "Installing GCC because a C++ compiler is missing." need_to_install_gcc=yes fi if [ -z "$FC" ]; then echo >&2 "Installing GCC because a Fortran compiler is missing." need_to_install_gcc=yes fi fi # If we are not installing GCC: check that the assembler and linker # used by $CC match $AS and $LD. # See http://trac.sagemath.org/sage_trac/ticket/14296 if [ $need_to_install_gcc != yes ]; then if [ "$AS" != "" ]; then CC_as=`$CC -print-file-name=as 2>/dev/null` CC_as=`command -v $CC_as 2>/dev/null` cmd_AS=`command -v $AS` if [ "$CC_as" != "" -a "$CC_as" != "$cmd_AS" ]; then echo >&2 "Error: Mismatch of assemblers between" echo >&2 " * $CC using $CC_as" echo >&2 " * \$AS equal to $AS" if [ "$SAGE_PORT" = "" ]; then echo >&2 "Aborting, either change or unset AS or set SAGE_PORT=yes or set" echo >&2 "SAGE_INSTALL_GCC=yes (this GCC would use assembler $AS)" exit 1 else echo >&2 "Continuing since SAGE_PORT is set." fi fi fi if [ "$LD" != "" ]; then CC_ld=`$CC -print-file-name=ld 2>/dev/null` CC_ld=`command -v $CC_ld 2>/dev/null` cmd_LD=`command -v $LD` if [ "$CC_ld" != "" -a "$CC_ld" != "$cmd_LD" ]; then echo >&2 "Error: Mismatch of linkers between" echo >&2 " * $CC using $CC_ld" echo >&2 " * \$LD equal to $LD" if [ "$SAGE_PORT" = "" ]; then echo >&2 "Aborting, either change or unset LD or set SAGE_PORT=yes or set" echo >&2 "SAGE_INSTALL_GCC=yes (this GCC would use linker $LD)" exit 1 else echo >&2 "Continuing since SAGE_PORT is set." fi fi fi fi ############################################################################### # Create the sage_fortran script. ############################################################################### # Don't use FC and SAGE_FORTRAN_LIB if we are installing GCC or have # installed gfortran, as that can cause compatibility problems. # We want to use the Fortran compiler that we build as part of GCC. if [ "$need_to_install_gcc" = yes ] || [ -x "$SAGE_LOCAL/bin/gfortran" ]; then unset FC unset SAGE_FORTRAN_LIB fi # Write sage_fortran script. cat >"$SAGE_LOCAL/bin/sage_fortran" <&2 <Makefile cat >&3 <&3 echo "" >&3 fi # Usage: newest_version_base $pkg # Print version number of latest (according to modification time) # base package $pkg newest_version_base() { PKG=$1 # As a fallback, we also look at the latest installed package. for FILE in `{ ls -1t base/$PKG-*-install; ls -1t installed/$PKG-*; } 2>/dev/null` do ANS=`echo "$FILE" | sed 's|.*/||; s|-install||'` if [ -n "$ANS" ]; then echo "$ANS" return 0 fi done echo >&2 "Cannot determine latest version of $PKG." echo "$PKG" return 1 } # Usage: newest_version $pkg # Print version number of latest standard package $pkg newest_version() { PKG=$1 if [ -f "$SAGE_ROOT/build/pkgs/$PKG/package-version.txt" ]; then echo -n $PKG- cat "$SAGE_ROOT/build/pkgs/$PKG/package-version.txt" else echo >&2 "Cannot determine latest version of $PKG." echo "$PKG" return 1 fi } cat >&3 <&3 -n 'TOOLCHAIN =' if [ "$SAGE_INSTALL_CCACHE" = yes ]; then echo >&3 -n ' $(INST)/ccache' fi if [ "$need_to_install_gcc" = yes ]; then echo >&3 -n ' $(INST)/$(GCC)' # Use this option for the prereq configure script, such that it # will skip all compiler checks. export PREREQ_OPTIONS="--disable-compiler-checks $PREREQ_OPTIONS" fi echo >&3 echo >&3 'SCRIPT_SOURCES = \' for file in "$SAGE_SRC/bin/"*; do echo >&3 " \$(SAGE_SRC)${file#$SAGE_SRC} \\" done echo >&3 echo >&3 'SCRIPT_TARGETS = \' for file in "$SAGE_SRC/bin/"*; do echo >&3 " \$(SAGE_LOCAL)${file#$SAGE_SRC} \\" done echo >&3 echo >&3 'EXTCODE_SOURCES = \' for file in `find "$SAGE_SRC"/ext -type f`; do echo >&3 " \$(SAGE_SRC)${file#$SAGE_SRC} \\" done echo >&3 echo >&3 'EXTCODE_TARGETS = \' for file in `find "$SAGE_SRC"/ext -type f`; do echo >&3 " \$(SAGE_EXTCODE)${file#$SAGE_SRC/ext} \\" done echo >&3 cat >&3 <&3 <&3 # Close the Makefile exec 3>&- ############################################################################### # Skip the rest if nothing to do (i.e., to [re]build). ############################################################################### # Set MAKE to "make" if unset if [ -z "$MAKE" ]; then export MAKE=make fi # If "make" doesn't understand the -q option (although we require # GNU make, which supports it), it should exit with a non-zero status # which is not a problem. if $MAKE -q "$@" >/dev/null 2>/dev/null; then echo "Nothing to (re)build / all up-to-date." exit 0 fi # Dump environment for debugging purposes: echo "*** ALL ENVIRONMENT VARIABLES BEFORE BUILD: ***" env | sort echo "***********************************************" ############################################################################### # NOW do the actual build: ############################################################################### time $MAKE "$@" if [ $? -ne 0 ]; then cat >&2 </dev/null; then base_f=`basename $f .log` cat >&2 <&2 <