Changes between Initial Version and Version 6 of Ticket #7375

11/19/09 01:55:18 (13 years ago)

Hi, I have had a few beers tonight, which are a nice benefit of attending the London Open Solaris User Group (LOSUG), so I hope my comments are coherent! (FWIW, one of tonights talks at LOSUG was very interesting from the point of view of Sage).

Anyway, back to the trac ticket...There are still some problems with this, which means the configure script believes the Sun compiler is broken. I've also made some other points. Some are nit-picking, but while you resolve one issue, you might as well resolve the others.

The main problem is that spkg-install sets CFLAGS to include -fPIC and -Wall, both of which are GNU specific flags. So when called with the Sun compiler, the compiler fails to build an executable, as its given erroneous flags. That can be seen in the config.log attached. It's essential that flags like those are only added on compilers that accept them.

I've attached a small script called testcc that I was intending at some point including in a more general place in Sage, but you can use it if you wish. It tests the C compiler and will report one of:

  • GNU (for any GCC compatible compiler)
  • Sun_on_Solaris (for the Sun compiler on Solaris)
  • Intel_improved_GCC
  • Sun_improved_GCC
  • HP_on_Alpha_Linux
  • HP_on_HPUX
  • IBM_on_AIX
  • HP_on_Tru64
  • Unknown

The script works by checking what the C pre-processor defines, which is more reliable than looking for words like GNU or Sun in the output. You could use that script to decide what flag to add to the compiler - whether it is -fPIC for GNU compilers, or -Kpic for the Sun compiler. I would not worry about the others at the minute.

Here is what the script gives as output on both Sun and GNU compilers on a Sun workstation. It's also been tested on AIX, tru64 and HP-UX too.

drkirkby@swan:[~] $ export CC=/opt/xxxsunstudio12.1/bin/cc
drkirkby@swan:[~] $ ./testcc
drkirkby@swan:[~] $ export CC=gcc
drkirkby@swan:[~] $ ./testcc

Out of completeness, I'll attach another for the C++ compiler (testcxx), but I do not think you will want the one for C++.

Using that script, you could then add in spkg-install something like the following, which I have not tested.

if [ x`testcc`  = "xGNU" ] ; then 
   CFLAGS="$CFLAGS -fPIC -Wall "
elif [ x`testcc` = "xSun_on_Solaris" ] ; then 
   CLFAGS="$CLFAGS -Kpic "
elif [ x`testcc` = "xHP_on_HPUX" ] ; then
   CFLAGS="$CFLAGS + z "

The Sun compilers are a lot more fussy than the GNU ones, so enabling extra warnings will probably show too many.

Whilst Sage does not aim to support HP-UX, it would be worth adding that +z flag, as compiling with other compilers tends to show problems in code. The library might build on HP-UX with those changes.)

Others issues I see are:

  • -m64 is added only on OS X. I suggest a better alternative would be to have:
 if [ "x$SAGE64" = "xyes" ] ; then 
    CFLAGS="$CFLAGS -m64 "

That's far from perfect, but will work with the Sun and GNU compilers, as both accept -m64.

I do not believe you need to set CPPFLAGS to -m64, as that is not an option for the C pre-processor. But it would be worth double-checking that.

  • The standard name for the file that creates the configure script was changed from to So the autoconf manual says to use that. See where it says "Previous versions of Autoconf promoted the name, which is somewhat ambiguous (the tool needed to process this file is not described by its extension), and introduces a slight confusion with and so on (for which ‘.in’ means “to be processed by configure”). Using is now preferred."
  • The autoconf manual says should start with AC_INIT, but your does not. This might possibly be the reason the configure script thinks the compiler is broken, though I doubt it.

  • I do not think it is a good idea to test for the Sun compiler in (or, to find what flags the compiler needs for C99 support, for several reasons
    • First, not all Sun compilers need any flag at all.
    • Other compilers from HP, IBM, Intel etc might need their own flags.

A better way to add a flag for c99 support (if it is needed), is to call the autoconf macro AC_PROG_CC_C99 That macro was designed for exactly this purpose. As such, you can delete all the code that checks for the Sun compiler in and just use the built-in macro. It would also be wise to exit with an error if the compiler is not C99 compliant, if that is needed. Test if $ac_cv_prog_cc_c99 = no, and if so exit with an error that the code needs to be able to find a C99 compliant compiler.

If you can make those changes, this has a reasonable chance of building on Solaris with the Sun compiler. I'll also try it on HP-UX for you. The machine is not running at the minute, but there is no point in even trying, as I know the GNU flags will break the build.