#7505: Add scripts which check C and C++ compilers, and report what they are.
---------------------------+------------------------------------------------
Reporter: drkirkby | Owner: tbd
Type: enhancement | Status: new
Priority: minor | Milestone: sage-4.3
Component: build | Keywords:
Work_issues: | Author: David Kirkby
Reviewer: | Merged:
---------------------------+------------------------------------------------
In some parts of Sage, it is desirable to know what compiler is being used
- in particular if its gcc or Sun, but there are other cases too.
The two scripts check the variable CC and CXX, and try to determine what
the compiler is. I've no idea where the scripts should go though -
ultimately they should be copied to SAGE_LOCAL/bin, but if great if
someone can put them in a sensible place to start with. I would be
appreciate that.
The scripts can report one of several answers.
* GNU (for GNU gcc, on any platform.)
* Sun_on_Solaris (for the Sun Studio compiler on Solaris)
* Intel_improved_GCC (An improved commercial version of gcc by Intel.
Compatible with gcc, but supposedly faster)
* Sun_improved_GCC (A compiler by Sun, that appears to code to be gcc,
but uses Sun Studio as a back-end.)
* HP_on_Alpha_Linux (HP compiler on Alpha hardware running Linux)
* HP_on_HPUX (HP's commerical compiler on HP-UX)
* IBM_on_AIX (IBM's commercial compiler on AIX)
* HP_on_Tru64 (HP's commerical compiler on Tru64)
* Unknown (The scripts can't work out what the compiler is).
These two scripts work by testing what pre-processor directives the
compilers test. For example, gcc will define __GNUC__.
But so will the Intel and Sun compilers which try to be GNU like. But the
Intel one will define __INTEL_COMPILER
Rhe Sun compilers defined __SUNPRO_C so it's possible to differentiate
the GNU, Intel and Sun compilers, even though they all aim to be GCC-like.
Compiler documentation was obtained from various sites, and is documented
in the scripts.
== Testing ==
Obviously a reviewer can test these scripts on any platforms they have
access to, but here are some tests I performed. I've not managed to check
these scripts on every platform and compiler for which they are aimed to
work on, due to lack of access to the hardware.
* On a Sun Blade 2000 SPARC box, with Sun Studio 12.1
{{{
drkir...@swan:[~] $ uname -a
SunOS swan 5.10 Generic_139555-08 sun4u sparc SUNW,Sun-Blade-1000
drkir...@swan:[~] $ echo $CC
/opt/xxxsunstudio12.1/bin/cc
drkir...@swan:[~] $ echo $CXX
/opt/xxxsunstudio12.1/bin/CC
drkir...@swan:[~] $ ./testcc
Sun_on_Solaris
drkir...@swan:[~] $ ./testcxx
Sun_on_Solaris
}}}
* On the same Sun Blade 2000, but with CC and CXX set to gcc and g++
{{{
drkir...@swan:[~] $ export CC=gcc
drkir...@swan:[~] $ export CXX=g++
drkir...@swan:[~] $ ./testcc
GNU
drkir...@swan:[~] $ ./testcxx
GNU
}}}
* On a Sun Ultra 27, but with CC defined to be a simple ''hello world
program'', to prove the code returns ''Unknown'' when it can not determine
the compiler.
{{{
SunOS hawk 5.11 snv_111b i86pc i386 i86pc
bash-3.2$ gcc hello.c -o hello
bash-3.2$ export CC=./hello
bash-3.2$ ./testcc
Unknown
}}}
* On an IBM machine running AIX 6.
{{{
$ uname -a
AIX client9 1 6 00C6B7C04C00
$ export CC=gcc
$ export CXX=g++
$ ./testcc
GNU
$ ./testcxx
GNU
}}}
* On the same IBM machine running AIX 6, but with CC and CXX set to the
IBM commercial compilers.
{{{
$ uname -a
AIX client9 1 6 00C6B7C04C00
$ export CC=/usr/vacpp/bin/xlc
$ export CXX=/usr/vacpp/bin/xlc++
$ ./testcc
IBM_on_AIX
$ ./testcxx
IBM_on_AIX
}}}
* On a HP C3600 running HP-UX 11.11, CC and CXX set to GNU compilers.
{{{
$ uname -a
HP-UX hpbox B.11.11 U 9000/785 2016698240 unlimited-user license
$ export CC=gcc
$ export CXX=g++
$ ./testcc
GNU
$ ./testcxx
GNU
}}}
* On the same HP C3600, but this time using trial versions of HP's
commercial C and C++ compilers.
{{{
$ export CC=/opt/ansic/bin/cc
$ export CXX=/opt/aCC/bin/aCC
$ ./testcc
HP_on_HPUX
$ ./testcxx
HP_on_HPUX
}}}
* On a linux machine (sage.math.washington.edu), with the variable CC and
CXX not set. In this case, the exit code is 1, not 0.
{{{
kir...@sage:~$ unset CC
kir...@sage:~$ unset CXX
kir...@sage:~$ ./testcc
Sorry, you should define the environment variable CC
kir...@sage:~$ ./testcxx
Sorry, you should define the environment variable CXX
}}}
* On the same Linux machine, but with CC and CXX set to locations of GNU
compilers. In one case an absolute path is given, in the other case it is
not
{{{
kir...@sage:~$ uname -a
Linux sage.math.washington.edu 2.6.24-23-server #1 SMP Wed Apr 1 22:14:30
UTC 2009 x86_64 GNU/Linux
kir...@sage:~$ export CC=/usr/bin/gcc
kir...@sage:~$ export CXX=g++
kir...@sage:~$ ./testcc
GNU
kir...@sage:~$ ./testcxx
GNU
}}}
* On an Apple (bsd.math.washington.edu) running OS X
{{{
[kir...@bsd ~]$ uname -a
Darwin bsd.local 10.2.0 Darwin Kernel Version 10.2.0: Tue Nov 3 10:37:10
PST 2009; root:xnu-1486.2.11~1/RELEASE_I386 i386 i386 MacPro1,1 Darwin
[kir...@bsd ~]$ export CC=gcc
[kir...@bsd ~]$ export CXX=g++
[kir...@bsd ~]$ ./testcc
GNU
[kir...@bsd ~]$ ./testcxx
GNU
}}}
The code was tested by someone else on Tru64, but I can not show the
results of this.
I have not verified it with the Sun or Intel compilers which are GCC
compatible, nor on Alpha linux. In each case, I've used compiler
documentation, and hope it is right.
Dave
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7505>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=.