build matplotlib-0.98.3 on Solaris with SunStudio 12

1. Set the CBE environment (/opt/jdsbld/bin/env.sh), and export CC=$CXX, so that /usr/lib/python2.4/pycc would eventually use the C++ compiler in SunStudio.

2. Download the source code from http://matplotlib.sourceforge.net, then apply the following patch,

--- setupext.py	2008-08-04 02:15:22.000000000 +0800
+++ setupext.py	2008-11-03 17:08:41.387138200 +0800
@@ -218,6 +218,8 @@ def get_win32_compiler():
 win32_compiler = get_win32_compiler()
 if sys.platform == 'win32' and win32_compiler == 'msvc':
     std_libs = []
+elif sys.platform == 'sunos5':
+    std_libs = ['Crun', 'Cstd']
 else:
     std_libs = ['stdc++', 'm']

@@ -298,6 +300,7 @@ def check_for_freetype():
         for d in basedirs:
             module.include_dirs.append(os.path.join(d, 'freetype2'))

+    module.include_dirs.append('/usr/include')
     print_status("freetype2", get_pkgconfig_version('freetype2'))
     if not find_include_file(module.include_dirs, 'ft2build.h'):
         print_message(
--- src/_backend_gdk.c	2008-08-04 02:14:18.000000000 +0800
+++ src/_backend_gdk.c	2008-11-03 17:31:32.896210699 +0800
@@ -62,6 +62,7 @@ static PyMethodDef _backend_gdk_function
     { NULL, NULL, 0 }
 };

+extern "C"
 DL_EXPORT(void)
 init_backend_gdk(void)
 {

3. Then build and install,

$ python setup.py build
$ pfexec python setup.py install

Note: this version of matplotlib requires numpy-1.1 or higher version, you need build and install a newer one since solaris only has 1.0.4.

build scipy-0.6.0 on Solaris with SunStudio 12

I finally got some clues about how to build scipy with SunStudio and Sun Performance library from this discussion thread. And here are the steps I sumerized:

1. Download the source tar file of scipy, SciPy 0.6.0 tarball, and extract it to anywhere. Apply the following changes to /usr/lib/python2.4/vendor-packages/numpy/distutils/fcompiler/sun.py, since f77compat library is not available on x86/x64 platform,

--- sun.py.orig	2008-10-31 18:30:17.519425733 +0800
+++ sun.py	2008-10-31 18:30:23.842495794 +0800
@@ -38,7 +38,7 @@
         return ['-xtarget=generic']
     def get_libraries(self):
         opt = []
-        opt.extend(['fsu','sunmath','mvec','f77compat'])
+        opt.extend(['fsu','sunmath','mvec'])
         return opt

 if __name__ == '__main__':

and apply the following patch,


--- scipy/sparse/sparsetools/sparsetools.h    2007-09-22 15:55:25.000000000 +0800
+++ scipy/sparse/sparsetools/sparsetools.h    2008-10-31 17:54:47.317379521 +0800
@@ -22,6 +22,7 @@

 #include <vector>
 #include <algorithm>
+#include <functional>

 /*

2. Set CBE environment (/opt/jdsbld/bin/env.sh), and the following environment variables,

$ export LDFLAGS="-lCrun -lCstd"
$ export LAPACK=/opt/SUNWspro/lib/libsunmath.so
$ export BLAS=/opt/SUNWspro/lib/libsunperf.so

3. Then build, install, and test

$ python setup.py build
$ pfexec setup.py install
$ cd ~ # don't run the test under the source directory
$ python
>>> import scipy
>>> scipy.test()

Though, you would see several errors, most of the tests passed.

SunStudio C/C++ compiler can not initialize the pointer member within a packed structure

#include<stdio.h>

#pragma pack(1)

struct foo{
        char a;
        char *str;
};

int main()
{
        struct  foo bar={'a', "test"};
        printf ("%p, %p\n", &(bar.a), &(bar.str));
}


$ cc test.c
"test.c", line 12: cannot use an address to initialize a field of a packed struct (#pragma pack)


While, gcc (even on sparc) could compile this test program, and from the output we could see that the "str" member just follows the char member -- 'a', and does not align with the 4/8 byte boundary. So it's not limitation of architecture, but a constraint of compiler.