# HG changeset patch
# User J. H. Palmieri
# Date 1290401054 28800
# Node ID 97e1530398191b7760de24cba5cd8434da1d0be0
# Parent 59635e5e648992b2bc16abf08c98e26e89b27ad3
#10303: clean up use of SAGE64. Don't insist that it is only used on Solaris or OS X, only call sagecheck64 in sagebuild and sagespkg, store the setting of SAGE64 in the file SAGE_LOCAL/lib/sage64.txt, and query the user if SAGE64 disagrees with the contents of that file, to prevent mixed 32bit and 64bit builds.
diff r 59635e5e6489 r 97e153039819 sagebuild
 a/sagebuild
+++ b/sagebuild
@@ 88,9 +88,11 @@ if [ $DO_BUILD_ALL = 1 ]; then
cd "$CUR"
fi
# In case SAGE64 has been set to yes before reinject 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/sagecheck64
+# Check whether this seems to a 64bit build:
+source "$SAGE_LOCAL"/bin/sagecheck64
+
+if [ $? ne 0 ]; then
+ exit 1
+fi
build "sage"
diff r 59635e5e6489 r 97e153039819 sagecheck64
 a/sagecheck64
+++ b/sagecheck64
@@ 1,42 +1,104 @@
#!/usr/bin/env bash
# If SAGE64 is set to yes check if $SAGE_LOCAL/lib exists on Solaris as well as
# OSX since those are currently the only two platforms which require SAGE64. If
# it does not exist create the directory and then create a file sage64.txt
# Eventually Linux PPC on the PS3 might need to be added here
+# WARNING: This file should not be executed directly. It should be
+# executed, using 'source', by other scripts which have set the
+# environment correctly. (This script is run by sagespkg before
+# running an spkg's spkginstall file. It is also run by sagebuild,
+# and also by SAGE_ROOT/spkg/install before starting the build
+# process.)
if [ "$SAGE64" = "yes" ]; then
 CHECKFILE="no"
 if [ `uname` = "SunOS" ]; then
 echo "Building Sage on Solaris in 64bit mode"
 CHECKFILE="yes"
 fi
 if [ `uname` = "Darwin" ]; then
 echo "Building Sage on OS X in 64bit mode"
 CHECKFILE="yes"
 fi
 if [ $CHECKFILE = "yes" ]; then
 if ! [ d "$SAGE_LOCAL"/lib ]; then
 echo "Creating SAGE_LOCAL/lib since it does not exist"
 mkdir "$SAGE_LOCAL"/lib
 fi
 echo "Creating SAGE_LOCAL/lib/sage64.txt since it does not exist"
 touch "$SAGE_LOCAL"/lib/sage64.txt
+# Check whether to build 64bit or not. Print a message if building
+# 64bit.
+
+# This script checks the variable SAGE64 as well as the file
+# SAGE_LOCAL/lib/sage64.txt. If the file does not exist, then save
+# the value of SAGE64 to that file, using value "no" if SAGE64 is not
+# set. If the file does exist, its contents should be either "yes" or
+# "no". If this agrees with the value of SAGE64, proceed. If not,
+# query the user about whether to continue. If the user wants to
+# continue, change the contents of the file to match SAGE64.
+
+if [ "$SAGE_LOCAL" = "" ]; then
+ echo
+ echo "SAGE_LOCAL undefined ... exiting"
+ echo "Do not call sagecheck64 directly!"
+ return 1
+fi
+
+# Note that setting the variable SAGE64 to 'yes' is only allowed on OS
+# X, Solaris, or OpenSolaris machines. On any other platform, check
+# the setting. If bad, error and return. If okay, return
+# immediately: no need to do bother with the file
+# SAGE_LOCAL/lib/sage64.txt.
+if [ "$UNAME" != Darwin ] && [ "$UNAME" != SunOS ]; then
+ if [ "$SAGE64" != no ] && ! [ z "$SAGE64" ]; then
+ echo
+ echo "Error: On any platform other than OS X, Solaris, or OpenSolaris,"
+ echo "SAGE64 must be unset or set to 'no'."
+ return 1
+ else
+ # exit silently if SAGE64=no or is unset
+ return 0
fi
fi
# Check if SAGE_LOCAL/lib/sage64.txt exists. If it does on Solaris and OSX
# force the setting of SAGE64

if [ a "$SAGE_LOCAL"/lib/sage64.txt ]; then
 echo "Detected SAGE64 flag"
 if [ `uname` = "SunOS" ]; then
 echo "Building Sage on Solaris in 64bit mode"
 SAGE64="yes"; export SAGE64
+# if SAGE64 not set or empty, set it to the contents of $sage64file,
+# or to "no" if that file is not present.
+sage64file="$SAGE_LOCAL"/lib/sage64.txt
+if [ z "$SAGE64" ]; then
+ # If SAGE64 was not set, it defaults to the contents of
+ # $sage64file, or to "no" if that file is not present.
+ if [ f "$sage64file" ]; then
+ SAGE64=`cat "$sage64file"`
+ else
+ SAGE64=no
fi
 if [ `uname` = "Darwin" ]; then
 echo "Building Sage on OS X in 64bit mode"
 SAGE64="yes"; export SAGE64
 fi
+ export SAGE64
fi
+# Now make sure SAGE64 is either "yes" or "no" and that it is
+# consistent with the contents of SAGE_LOCAL/lib/sage64.txt.
+case "$SAGE64" in
+ yesno)
+ if [ f "$sage64file" ]; then
+ contents=`cat "$sage64file"`
+ if [ "$contents" != "$SAGE64" ]; then
+ echo
+ echo "Warning: SAGE64 (=$SAGE64) and the file SAGE_LOCAL/lib/sage64.txt"
+ echo "(which contains '$contents') are not compatible. Continuing"
+ echo "could lead to incompatible files in your Sage build, some"
+ echo "32bit and some 64bit."
+ echo
+ echo n "Continue anyway [y/N]?"
+ read CONFIRM
+ case $CONFIRM in
+ yYYESyesYes)
+ echo $SAGE64 > "$sage64file";;
+ *)
+ echo "Aborting"
+ return 1;;
+ esac
+ fi
+ else
+ mkdir p "$SAGE_LOCAL"/lib
+ echo "Creating SAGE_LOCAL/lib/sage64.txt since it does not exist."
+ if [ $SAGE64 = no ]; then
+ echo "32bit build, so writing 'no' to SAGE_LOCAL/lib/sage64.txt."
+ else
+ echo "64bit build, so writing 'yes' to SAGE_LOCAL/lib/sage64.txt."
+ fi
+ echo $SAGE64 > "$sage64file"
+ fi
+ ;;
+ *)
+ echo
+ echo "The environment variable SAGE64 (=$SAGE64) must be either unset, yes or no."
+ echo "Aborting."
+ return 1
+ ;;
+esac
+
+# Now print a message if building 64bit.
+if [ "$SAGE64" = "yes" ]; then
+ echo "Building Sage in 64bit mode"
+fi
diff r 59635e5e6489 r 97e153039819 sageenv
 a/sageenv
+++ b/sageenv
@@ 101,7 +101,7 @@ if [ 1 = 2 ]; then
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 64bit binary (Solaris SPARC or Solaris x86 only)"
+ echo "SAGE64 Set to \"yes\" to build a 64bit binary (OS X, Solaris, or OpenSolaris 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:"
@@ 275,21 +275,6 @@ 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."
 exit 1
fi

# In case SAGE64 has been set to yes before reinject 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/sagecheck64 2> /dev/null
export SAGE64

if [ "$CXXFLAGS" = "" ]; then
CXXFLAGS="$CFLAGS"
fi
diff r 59635e5e6489 r 97e153039819 sagemake_devel_packages
 a/sagemake_devel_packages
+++ b/sagemake_devel_packages
@@ 138,6 +138,7 @@ mkdir $SCRIPTS
chmod +x sage*
chmod x sageREADMEosx.txt sagebanner sagegdbcommands
chmod x sagemaxima.lisp sageverifypyc
+chmod x sagecheck64
rm sage*~
cp pr sage* .hg* ipy_profile_sage.py $SCRIPTS/
diff r 59635e5e6489 r 97e153039819 sagesdist
 a/sagesdist
+++ b/sagesdist
@@ 39,6 +39,7 @@ cd "$CUR"
cp $SAGE_ROOT/local/bin/sagespkg $PKGDIR/base/
cp $SAGE_ROOT/local/bin/sageenv $PKGDIR/base/
cp $SAGE_ROOT/local/bin/sagemake_relative $PKGDIR/base/
+cp $SAGE_ROOT/local/bin/sagecheck64 $PKGDIR/base/
TMP="/tmp/$TARGET"
diff r 59635e5e6489 r 97e153039819 sagespkg
 a/sagespkg
+++ b/sagespkg
@@ 311,6 +311,11 @@ uname a
if [ $? ne 0 ]; then
echo "Unable to determine host system information."
fi
+# Check whether this seems to a 64bit build:
+source "$SAGE_LOCAL"/bin/sagecheck64
+if [ $? ne 0 ]; then
+ exit 1
+fi
echo "****************************************************"
echo "****************************************************"