Peter Jeremy wrote:

>> 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).

Thank you very much Peter.

I must admit, your scripting skills are a lot better than mine. What is the 
function of "E*O*F"? I'm impressed with this!

Anyway, I agree your revised version is much cleaner. I revised the C++ version 
in a similar way. Could you have a quick look and see if you see anything wrong 
with it. If not, I'll upload the revised C and C++ versions to the trac ticket.

I added you as an author, as clearly you have made a major contribution to 
improving this.

Are you aware of any major compilers which are not covered? All the 
Intel/HP/Sun 
compilers which are GCC-like will return 'GCC' which is fine. I can't think of 
any other different compiler. Perhaps something like for the CUDA systems, but 
that's a bit too specialised for now.

I'd like to get these into Saga asap, so I can work on making the code a bit 
more portable, and sort out this SAGE64 mess, which is a pain on Solaris, as 
some .spkg files use SAGE64 irrespective of the operating system, whereas 
others 
ignore it on any platform except HP-UX.

dave


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
#!/bin/sh
# Determine the type of C++ compiler, which can later
# be used to determine the flags the compiler 
# will want. This is done by testing what the 
# C++ compiler's pre-processor defines. For example, 
# g++ will always define __GNUC__ (as does gcc).

# Copyright Dr. David Kirkby 
# Released under the GPL version 2, or any later version
# the user wishes to use.  
# Re-written in a simpler way by Peter Jeremy

# 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


# First, make sure the environment variable CXX is defined. 

if [ -z "$CXX" ]; then
   echo "Sorry, you should define the environment variable CXX"
   exit 1
fi

# 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 g++ or a g++ 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 
'CXX'
EOF
}

# Exit if the user supplies more than one command line argument. 
if [ $# -ne 0 ] ; then
  usage
  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.$$.cpp
cat >$TESTFILE <<"E*O*F"

#ifdef __GNUC__                    
GCC
#define KNOWN_CXX
#endif

#ifdef __SUNPRO_CC              
Sun_Studio
#define KNOWN_CXX
#endif

#ifdef __digital__              
#ifdef __DECCXX                
HP_on_Tru64
#define KNOWN_CXX
#endif
#endif

#ifdef __linux__
#ifdef __DECCXX
HP_on_Alpha_Linux
#define KNOWN_CXX
#endif
#endif

#ifdef __HP_aCC
HP_on_HP-UX
#define KNOWN_CXX
#endif

#ifdef __xlC__
IBM_on_AIX
#define KNOWN_CXX
#endif

#ifndef KNOWN_CXX
Unknown
#endif
E*O*F

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

Reply via email to