Ticket #7818: sage-env.patch

File sage-env.patch, 16.8 KB (added by drkirkby, 12 years ago)

Patch file which should hopefully commit, as Robert Miller said the previous one had a problem.

  • sage-env

    # HG changeset patch
    # User David Kirkby <david.kirkby@onetel.net>
    # Date 1263425404 0
    # Node ID b095ee2a8b698e6738816737284d2373c79ec2af
    # Parent  2b7281fda22b906b6602a59ad41ea42d9b6f3cbd
    Adds -Wall -g to all builds, -m64 when SAGE64 is set to yes,
    and defines some variables which are currently unused in Sage.
    
    diff -r 2b7281fda22b -r b095ee2a8b69 sage-env
    a b  
    66#  You must source this; see below!
    77#
    88#  AUTHORS:   William Stein                            2005-12
    9 #             David Kirkby <david.kirkby@onetel.net>   2005-12-17
     9#             David Kirkby <david.kirkby@onetel.net>   2009-12-29
    1010#
    1111###########################################################################
    1212
     
    6363fi
    6464
    6565
    66 if [ 1 = 2 ]; then
    67     echo "The following enviroment variables can be set by the user"
     66if [ "x$SAGE_PRINT_ENVIRONMENT" = "xyes" ] ; then
     67    echo "The following environment variables can be set by the user"
     68    echo "but unfortunately, not all packages use them, so you can not"
     69    echo "rely on them working as intended. "
    6870    echo "AR          The archiver (e.g. ar, /usr/ccs/bin/ar or /usr/bin/ar)"
    6971    echo "AS          The assembler (e.g. as, /usr/ccs/bin/as or /usr/bin/as)"
    7072    echo "CC          The C compiler (e.g cc, /opt/SUNWspro/bin/cc or /usr/bin/gcc)"
    71     echo "CFLAGS      Flag(s) for the C compiler (e.g.  -g -Wall -O2)"
    72     echo "            (You are advised to a some optimisation flag(s), such as -O2 or -xO2 to CFLAGS)"
     73    echo "CFLAGS      Flag(s) for the C compiler"
    7374    echo "CXX         The C++ compiler (e.g g++, /opt/SUNWspro/bin/CC or /usr/local/bin/g++)"
    74     echo "CXXFLAGS    Flag(s) for the C++ compiler (e.g. -fast -fsimple=1 -x04)"
     75    echo "CXXFLAGS    Flag(s) for the C++ compiler"
    7576    echo "LD          The linker (e.g. ld, /usr/ccs/bin/ld or /usr/bin/ld)"
    7677    echo "LDFLAGS     Linker flag(s) (e.g. -D token)"
    77     echo "LN          Used to make links (e.g. ln, /usr/xpg4/bin/ln or /usr/bin/ln)"
    7878    echo "MAKE        The make program (e.g. make, /usr/bin/make or /usr/local/bin/gmake)"
    7979    echo "MAKEFLAGS   Flag(s) to make (e.g. -j4)."
    8080    echo "RANLIB      Archiver ranlib (e.g. ranlib, /usr/ccs/bin/ranlib etc)"
    81     echo "SAGE64      Set to \"yes\" to build a 64-bit binary (Solaris SPARC or Solaris x86 only)"
    82     echo "SHAREDFLAGS Flag(s) necessary for building a shared library (e.g. -fPIC or -xcode=pic32)"
     81    echo "SAGE64      Set to \"yes\" to build a 64-bit binary"
     82    echo "SAGE_DEBUG  Set to \"no\" if you do not want debugging information"
    8383    echo "We attempt to set this to sensible values, but check below to"
    8484    echo "ensure they are OK. If you wish to override any then please use:"
    85     echo "setenv NAME_OF_ENVIROMENT_VARIABLE value_of_enviroment_variable"
     85    echo "setenv NAME_OF_ENVIROMENT_VARIABLE value_of_environment_variable"
    8686    echo "(if you use tcsh, csh or a similar shell) or"
    87     echo "NAME_OF_ENVIROMENT_VARIABLE value_of_enviroment_variable"
     87    echo "NAME_OF_ENVIROMENT_VARIABLE=value_of_environment_variable"
    8888    echo "export NAME_OF_ENVIROMENT_VARIABLE"
    8989    echo "if you use sh, bash or a similar shell"
    9090fi
     
    9999
    100100# We offer a toolchain option, so if $SAGE_LOCAL/toolchain/toolchain-env exists source it.
    101101# Since the user might do something crazy we do not do any checks, but hope for the best.
     102# source is not portable - use a dot instead.
    102103if [ -f $SAGE_LOCAL/toolchain/toolchain-env ]; then
    103   source $SAGE_LOCAL/toolchain/toolchain-env
     104  . $SAGE_LOCAL/toolchain/toolchain-env
    104105fi
    105106
    106107# For a framework Python build on OS X, Python's bin directory is not local/bin
     
    180181# This could be used in code to make special changes only when
    181182# code is being built as part of Sage.
    182183__sage__="" && export __sage__
    183 # Set the default compiler to gcc if the enviroment variable
     184# Set the default compiler to gcc if the environment variable
    184185# CC is not set.
    185186if [ "$CC" = "" ]; then
    186187     CC="gcc"         && export CC
     
    211212fi
    212213
    213214if [ "$SAGE64" = "" ]; then
    214     SAGE64="no"
     215    SAGE64="no" && export SAGE64
    215216fi
    216217
    217218if [ "$SAGE64" != "yes" -a "$SAGE64" != "no" ]; then
     
    222223# In case SAGE64 has been set to yes before re-inject it into the environment
    223224# This is only done on OSX and Solaris since those are the only real multi lib
    224225# arches we support. Eventually Linux PPC on the PS3 might need to be added here
    225 source $SAGE_LOCAL/bin/sage-check-64 2> /dev/null
     226# Although not supported by Sage, both the HP-UX and AIX operating systems
     227# can have both 32 and 64 bit code on the same system
     228. $SAGE_LOCAL/bin/sage-check-64 2> /dev/null
    226229export SAGE64
    227230
     231# Make use of the scripts on Trac #7505 to determine the correct
     232# compiler options. One of the following will be output by the
     233# the scripts testcc.sh and testcxx.sh
     234#  * GCC
     235#  * Sun_Studio
     236#  * HP_on_Tru64
     237#  * HP_on_Alpha_Linux
     238#  * HP_on_HP-UX
     239#  * IBM_on_AIX
     240#  * Unknown
     241
     242# In each case, I've called the flag as similar as
     243# possible to the GNU names, to make it easier to change code.
     244# i.e. the flag for generating position independent code is called
     245# FPIC_FLAG, as the option with gcc is -fPIC. 
     246# The option for generating shared libraries is called
     247# SHARED_FLAG, as the option for gcc is -shared.
     248# Likewise for SONAME_FLAG, WHOLE_ARCHIVE_FLAG and NO_WHOLE_ARCHIVE_FLAG
     249
     250# If all instances of -fPIC in Sage were replaced by $FPIC_FLAG
     251# Sage would be a lot more portable than it currently is.
     252# Likewise, for several other options which depend on the compiler.
     253if  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xGCC" ] ; then
     254    # These are the names of the environment variables, and their GCC
     255    # name. They are not appended to CFLAGS, CXXFLAGS or FCFLAGS as they
     256    # are not always needed.
     257    FPIC_FLAG="-fPIC"
     258    SHARED_FLAG="-shared"
     259    SONAME_FLAG="-soname"
     260    WHOLE_ARCHIVE_FLAG="--whole-archive" 
     261    NO_WHOLE_ARCHIVE_FLAG="--no-whole-archive"
     262
     263    # Enable warnings on gcc.
     264    CFLAGS="$CFLAGS -Wall" 
     265    CXXFLAGS="$CXXFLAGS -Wall"
     266    FCFLAGS="$FCFLAGS -Wall"
     267elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xSun_Studio" ] ; then
     268    # -xcode=pic32 is valid on 64-bit too, despite the name.
     269    # It is equivalent to the obsolete -KPIC on SPARC and -kPIC on x86
     270    # These flags for Solaris should work in most circumstances.
     271    # Identical flags have been used to build a 32-bit version of Sage
     272    # on SPARC.
     273    FPIC_FLAG="-xcode=pic32"
     274    SHARED_FLAG="-G"
     275    SONAME_FLAG="-h"
     276    WHOLE_ARCHIVE_FLAG="-z allextract"
     277    NO_WHOLE_ARCHIVE_FLAG="-z defaultextract"
     278
     279    # The Sun C++ compiler is supplied with two standard libraries.
     280    # http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html
     281    # The default library is based on an old version of the C++ standard
     282    # and is not compatible with the latest standard. This line forces the
     283    # use of the new library with: -library=stlport4.
     284    CXXFLAGS="$CXXFLAGS -library=stlport4"
     285
     286    # The Sun compiler is quite fussy by default (much
     287    # more so than the GNU ones, so adding more warnings will
     288    # be too much)
     289elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xHP_on_HP-UX" ] ; then
     290    # HP's C++ compiler creates position independent code by default, but
     291    # I assume the C compiler does not.
     292    FPIC_FLAG="-b"       # HP's C++ compiler creates position independent code by default.
     293    SHARED_FLAG="-b"     # I'm not 100% sure of this.
     294    SONAME_FLAG=""
     295    WHOLE_ARCHIVE_FLAG=""
     296    NO_WHOLE_ARCHIVE_FLAG=""
     297
     298    # Like the Sun compiler, the HP compiler has an old and a new library
     299    # and by default uses the old library. To use a newer library, which
     300    # is closer to the current C++ standard, the option -AA must be given.
     301    # Unlike most other compilers, by default it does no optimization at
     302    # all, which is undesirable, so -O is added.
     303    CFLAGS="$CFLAGS -O"
     304    CXXFLAGS="$CXXFLAGS -AA -O"
     305    FCFLAGS="$FCFLAGS -O"
     306elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xIBM_on_AIX" ] ; then
     307    echo "Warning: Some compiler options when using HP's compiler"
     308    echo "on HP-UX are in the file sage-env. These might"             
     309    echo "not be correct and so will need adjusting."
     310    echo "It is suggested that you try to build Sage with"
     311    echo "GCC first, as that is more likely to work, as the"
     312    echo "compiler flags used by GCC are the same, irrespective"
     313    echo "of the operating system. "
     314    FPIC_FLAG="-qpic"       
     315    SHARED_FLAG=""   
     316    SONAME_FLAG=""
     317    WHOLE_ARCHIVE_FLAG=""
     318    NO_WHOLE_ARCHIVE_FLAG=""
     319elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xHP_on_Tru64" ] ; then
     320    echo "Warning: Some compiler options when using HP's compiler"
     321    echo "on Tru64 are in the file sage-env. These might"             
     322    echo "not be correct and so will need adjusting."
     323    echo "It is suggested that you try to build Sage with"
     324    echo "GCC first, as that is more likely to work, as the"
     325    echo "compiler flags used by GCC are the same, irrespective"
     326    echo "of the operating system. "
     327    FPIC_FLAG=""       
     328    SHARED_FLAG=""   
     329    SONAME_FLAG=""
     330    WHOLE_ARCHIVE_FLAG=""
     331    NO_WHOLE_ARCHIVE_FLAG=""
     332elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xHP_on_Alpha_Linux" ] ; then
     333    echo "Warning: Some compiler options when using HP's compiler"
     334    echo "on Alpha Linux are in the file sage-env. These might"             
     335    echo "not be correct and so will need adjusting."
     336    echo "It is suggested that you try to build Sage with"
     337    echo "GCC first, as that is more likely to work, as the"
     338    echo "compiler flags used by GCC are the same, irrespective"
     339    echo "of the operating system. "
     340    FPIC_FLAG=""       
     341    SHARED_FLAG=""   
     342    SONAME_FLAG=""
     343    WHOLE_ARCHIVE_FLAG=""
     344    NO_WHOLE_ARCHIVE_FLAG=""
     345elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xUnknown" ] ; then
     346    echo "Your compiler type is unknown. So suitable compiler"
     347    echo "options are unknown. The flags will be set to the names"
     348    echo "used by GCC, but these are probably wrong"
     349    echo "Please advise on the sage-support mailing list what"
     350    echo "compiler you are using, and someone will help you"
     351    FPIC_FLAG="-fPIC"
     352    SHARED_FLAG="-shared"
     353    SONAME_FLAG="-soname"
     354    WHOLE_ARCHIVE_FLAG="--whole-archive"
     355    NO_WHOLE_ARCHIVE_FLAG="--no-whole-archive"
     356    CFLAGS = "$CFLAGS -Wall"
     357    CXXFLAGS = "$CXXFLAGS -Wall"
     358    FCFLAGS = "$FCFLAGS -Wall"
     359fi
     360
     361# Add debugging option (-g) unless SAGE_DEBUG is set to "no".
     362
     363if [  "x$SAGE_DEBUG" != "xno"  ] ; then
     364   CFLAGS="$CFLAGS -g"
     365   CXXFLAGS="$CXXFLAGS -g"
     366   FCFLAGS="$FCFLAGS -g"
     367fi
     368
     369
     370# Add the appropate options to CFLAGS, CXXFLAGS and FCFLAGS to
     371# produce a 64-bit binary. Doing this once, and only once in
     372# sage-env is preferable to setting it in virtually all
     373# .spkg files. If its wrong, it can be changed here.
     374
     375# It is possible that -m64 or the appropiate option might be
     376# needed for linking in some places, so it is also exported
     377# as a variable itself, though I doubt it would be needed
     378# often. Flint will need this, and so does ECL I believe.
     379
     380if [ "x$SAGE64" = "xyes" ] ; then
     381   if  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xGCC" ] ; then
     382      # Flags for a 64-bit build.
     383      CFLAG64="-m64"
     384      CXXFLAG64="-m64"
     385      FCFLAG64="-m64"
     386   elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xSun_Studio" ] ; then
     387      CFLAG64="-m64"
     388      CXXFLAG64="-m64"
     389      FCFLAG64="-m64"
     390   elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xIBM_on_AIX" ] ; then
     391      # http://www-01.ibm.com/support/docview.wss?uid=swg27012860&aid=1
     392      # The appropriate 64-bit option for IBM's C++ and Fortran
     393      # compilers are assumed to be the same as the
     394      # C compiler. This has not been checked
     395      # Adding -q64 to generate 64-bit code
     396      CFLAG64="-q64"
     397      CXXFLAG64="-q64"
     398      FCFLAG64="-q64"
     399   elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xHP_on_HP-UX" ] ; then
     400      # Two sort of processors are used on HP-UX machines - the older
     401      # PA-RISC and the newer Itanium. The 'model' command is the preffered
     402      # way to get this information, rather than 'uname', as HP might in future
     403      # use model numbers which are incompatible with the 'uname' command.
     404      # This is documented in the 'model' man page.
     405      if [ `model | grep 9000` ] ; then
     406         # Adding compiler flags for PA-RISC 2.0 architecture.
     407         CFLAG64="+DA2.0W"
     408         CXXFLAG64="+DA2.0W"
     409         FCFLAG64="+DA2.0W"
     410      elif [ `model | grep ia64` ]  ; then
     411         # Itanium.
     412         CFLAG64="+DD64"
     413         CXXFLAG64="+DD64"
     414         FCFLAG64="+DD64"
     415      fi
     416   elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xHP_on_Tru64" ] ; then
     417      # 64-bit is the default on Tru64, so no options needed to build
     418      # http://h30097.www3.hp.com/docs/porting/tru64-to-hpux/TITLE.HTM
     419      CFLAG64=""
     420      CXXFLAG64=""
     421      FCFLAG64=""
     422   elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xHP_on_Alpha_Linux" ] ; then
     423      # I've not carefully checked the Tru64 or Alpha Linux documentation
     424      # but it can be found at http://h30097.www3.hp.com/cplus/
     425      # I'll add the correct flags at a later date, but this is not urgent
     426      # as there is nobody porting Sage to Tru64 yet.
     427      CFLAG64="-HP_on_Alpha_Linux_option-to-build-64-bit-code"
     428      CXXFLAG64="-HP_on_Alpha_Linux_option-to-build-64-bit-code"
     429      FCFLAG64="-HP_on_Alpha_Linux_option-to-build-64-bit-code"
     430   elif  [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = "xUnknown" ] ; then
     431      echo "Warning: Since the compiler type is unknown, the"
     432      echo "compiler option to generate 64-bit code is unknown. The -m64"
     433      echo "option, which is used by GCC will be added, but this"
     434      echo "is probably wrong. Without knowing the compiler, it's"
     435      echo "impossible to know the right flags to use"
     436      CFLAG64="-m64"
     437      CXXFLAG64="-m64"
     438      FCFLAG64="-m64"
     439   fi
     440   CFLAGS="$CFLAGS $CFLAG64"
     441   CXXFLAGS="$CXXFLAGS $CXXFLAG64"
     442   FCFLAGS="$FCFLAGS $FCFLAG64"
     443fi
     444
    228445if [ "$CXXFLAGS" = "" ]; then
    229446   CXXFLAGS="$CFLAGS"
    230447fi
     
    272489# See trac 7186 -- this is needed if ecl is moved
    273490ECLDIR="$SAGE_LOCAL/lib/ecl/" && export ECLDIR
    274491
     492# Set a variable SHARED_LIBRARY_EXTENSION equal to the extension (without the dot)
     493# used on shared libraries. Lots of bits of code in Sage have differenent excepts for
     494# OS X and Cygwin, but a lot of this could be cleared up using
     495if [ "x$UNAME" = "xAIX" ] ; then
     496    SHARED_LIBRARY_EXTENSION="a"
     497elif [ "x$UNAME" = "xCYGWIN" ] ; then
     498    SHARED_LIBRARY_EXTENSION="dll"
     499elif [ "x$UNAME" = "xDarwin" ] ; then
     500    SHARED_LIBRARY_EXTENSION="dylib"
     501elif [ "x$UNAME" = "xHP-UX" ] ; then
     502    SHARED_LIBRARY_EXTENSION="sl"
     503else
     504    SHARED_LIBRARY_EXTENSION="so"
     505fi
     506
    275507# Export variable names.
    276 export SHAREDFLAGS
     508export CC
     509export CFLAG64
     510export CFLAGS
     511export CXXFLAG64
     512export CXXFLAGS
     513export FCFLAG64
     514export FCFLAGS
     515export FPIC_FLAG
     516export NO_WHOLE_ARCHIVE_FLAG
     517export SAGE_DEBUG
     518export SHARED_FLAG
     519export SHARED_LIBRARY_EXTENSION
     520export SONAME_FLAG
    277521export UNAME
    278 export CC
    279 export CFLAGS
     522export WHOLE_ARCHIVE_FLAG
    280523
    281 if [ 1 = 2 ]; then
    282 echo "AR=$AR"
    283 echo "AS=$AS"
    284 echo "CC=$CC"
    285 echo "CFLAGS=$CFLAGS"
    286 echo "CXX=$CXX"
    287 echo "CXXFLAGS=$CXXFLAGS"
    288 echo "ECLDIR=$ECLDIR"
    289 echo "LD=$LD"
    290 echo "LDFLAGS=$LDFLAGS"
    291 echo "LN=$LN"
    292 echo "MAKE=$MAKE"
    293 echo "MAKEFLAGS=$MAKEFLAGS (MFLAGS will be exported the same too)"
    294 echo "RANLIB=$RANLIB"
    295 echo "SAGE64=$SAGE64"
    296 echo "SHAREDFLAGS=$SHAREDFLAGS"
    297 echo "If any of the above are wrong, or are not optimal, override"
    298 echo "them by setting the appropiate enviroment variable."
     524# Print environment variables if the variable SAGE_PRINT_ENVIRONMENT
     525# is exported to 'yes'
     526if [ "x$SAGE_PRINT_ENVIRONMENT" = "xyes" ] ; then
     527   echo "The environment for Sage will be as follows. If any"
     528   echo "variables are wrong, you may be able to change them"
     529   echo "by setting a variable."
     530   echo "AR=$AR"
     531   echo "AS=$AS"
     532   echo "CC=$CC"
     533   echo "CFLAG64=$CFLAG64  - Used by C compiler to build 64-bit code (-m64 for gcc)"
     534   echo "CFLAGS=$CFLAGS"
     535   echo "CP=$CP"
     536   echo "CXX=$CXX"
     537   echo "CXXFLAG64=$CXXFLAG64  - Used by C++ compiler to build 64-bit code (-m64 for g++)"
     538   echo "CXXFLAGS=$CXXFLAGS"
     539   echo "ECLDIR=$ECLDIR"
     540   echo "FCFLAG64=$FCFLAG64 flag used by Fortran compiler to build 64-bit code (-m64 for gfortran)"
     541   echo "FCFLAGS=$FCFLAGS"
     542   echo "FPIC_FLAG=$FPIC_FLAG  - Used to produce position independent code"
     543   echo "LD=$LD"
     544   echo "LDFLAGS=$LDFLAGS"
     545   echo "MAKE=$MAKE"
     546   echo "MAKEFLAGS=$MAKEFLAGS (MFLAGS will be exported the same too)"
     547   echo "RANLIB=$RANLIB"
     548   echo "SAGE64=$SAGE64"
     549   echo "SHARED_FLAG=$SHARDED_FLAG  - used to build a shared library"
     550   echo "SHARED_LIBRARY_EXTENSION=$SHARED_LIBRARY_EXTENSION  - sl, so, dll etc"
     551   echo "SONAME_FLAG="$SONAME_FLAG"
     552   echo "WHOLE_ARCHIVE_FLAG="$WHOLE_ARCHIVE_FLAG"
     553   echo "NO_WHOLE_ARCHIVE_FLAG=$NO_WHOLE_ARCHIVE_FLAG"
    299554fi