On 2009-Dec-29 13:51:43 +0000, "Dr. David Kirkby" <david.kir...@onetel.net> 
wrote:
>Then when I thought about it more, I do not know if its worth the hassle. Why
>not simply ask the user to export SAGE64 to "yes" on Open Solaris, and forget
>about a 32-bit build?

It looks like OpenSolaris/SPARC defaults to 32-bit mode (looking at the
installed executables - I don't have a development system installed on
my OSol box yet).

Note that the current assumption that Sage is building in 32-bit mode
unless 'SAGE64' is set is not universally true:  Tru64, FreeBSD/amd64
and FreeBSD/SPARC64 (at least) default to building 64-bit executables
and have minimal, if any, support for building 32-bit executables.

>http://trac.sagemath.org/sage_trac/ticket/7505
>
>could get a positive review and be integrated into Sage asap. Two people have
>looked at it, and both agree it is OK.

I like the idea but the actual implementation seems somewhat convoluted.
Why not make '${CC} -E ${TESTFILE}' directly output the wanted identifier,
rather than running $CC multiple times and grepping for strings in the
output.  This approach also seems likely to cause maintenance issues as
changes need to be implemented in three places (including the usage).  I
have attached a suggested alternative (testcxx could be similarly adapted).

>1) Determine what compiler is in use by the use of the scripts in #7505
>2) Set CFLAGS to have the appropriate option for a 64-bit build in sage-env if
>SAGE64 is set to "yes". That will be -m64 with Sun Studio or GCC, but will be
>different for other compilers.
>3) Remove all the SAGE64 junk from every spkg-install, because:
>  * It's unnecessary duplication
>  * Currently has a mix of those that only work on OS X and those that work on
>    Solaris, and those that only work on OS X.
>  * It's incorrect to assume the flag to build 64-bit code will always be
>    -m64, as some compilers use a different flag.

The code also needs to handle the situation where a 64-bit Sage will
be built by default.  Ideally, the 32 vs 64 bit code should be
centralised and the relevant cc/c++/fortran/linker flags passed into
each spkg-install.

-- 
Peter Jeremy
#!/bin/sh
# Determine the type of C compiler, which can later
# be used to determine the flags the C compiler
# will want. This is done by testing what the
# C compiler's pre-processor defines. For example,
# gcc will always define __GNUC__

# Copyright Dr. David Kirkby
# Released under the GPL version 2, or any later version
# the user wishes to use.

# Some of the compilers have been tested, though some have
# not, due to a lack of hardware or software.

# Documentation on the compilers is taken from many source
# in particular, for the commercial Unix compilers:

# HP-UX C and C++ compiler.
# http://docs.hp.com/en/7730/newhelp0610/preprocess.htm

# IBM Compiler Reference - XL C/C++ for AIX, V10.1
# http://www-01.ibm.com/support/docview.wss?uid=swg27012860&aid=1

# Using HP C++ for Tru64 UNIX and Linux Alpha
# http://h30097.www3.hp.com/cplus/ugu_impl.html#implem_chap


# Define a function to display usage information.
usage()
{
cat <<EOF 1>&2
Usage: $0
  Will return one of the following, to indicate the C compiler

  GCC                 - For gcc or a gcc-like C compiler on any platform
  Sun_Studio          - For Sun Studio or earlier Sun C compiler
  HP_on_Tru64         - For a C compiler produced by HP/Compaq for Tru64
  HP_on_HP-UX         - For a C compiler produced by HP/Compaq for HP-UX
  IBM_on_AIX          - For a C compiler produced by IBM for AIX
  HP_on_Alpha_Linux   - For a C compiler produced by HP for Alpha linux
                        (This script has not been tested on Alpha Linux,
                        but is based on HP's documentation)
  Unknown             - If the C compiler type is unknown

  Note that the C compiler name must be passed in the environment variable 'CC'
EOF
}

# Exit if the user supplies any command-line arguments.
if [ $# -ne 0 ] ; then
  usage
  exit 1
fi

# Make sure the environment variable CC is defined.
if [ -z "$CC" ]; then
   echo "Sorry, you must define the environment variable CC"
   exit 1
fi


# Create a test file. It does not need to be a complete
# C file, as it is only pre-processed. So there is no
# need for a 'main'

TESTFILE=/tmp/test.$$.c

cat >$TESTFILE <<"E*O*F"
#ifdef __GNUC__
GCC
#define KNOWN_CC
#endif

#ifdef __SUNPRO_C
Sun_Studio
#define KNOWN_CC
#endif

/*
 * I've not found any official documentation to suggest __DECC
 * would be defined, but __DECCC is defined for C++,
 * and a Google on __DECC shows many hits. I do not have
 * easy access to a Tru64 system.
 */
#ifdef __digital__
#ifdef __DECC
HP_on_Tru64
#define KNOWN_CC
#endif
#endif

/* Untested, as I have no access to a Alpha Linux system. */
#ifdef __linux__
#ifdef __DECCC
HP_on_Alpha_Linux
#define KNOWN_CC
#endif
#endif

#ifdef __HP_cc
HP_on_HP-UX
#define KNOWN_CC
#endif

#ifdef __xlC__
IBM_on_AIX
#define KNOWN_CC
#endif

#ifndef KNOWN_CC
Unknown
#endif
E*O*F

${CC} -E $TESTFILE | grep '^[A-Z]'
rm $TESTFILE
exit 0

Attachment: pgpxLXFq2WsoO.pgp
Description: PGP signature

Reply via email to