Compiling matplotlib in Solaris 10

Trying to install matplotlib 1.5.1 in my Solaris 10 machines produces the following compiling error:

[...]
    In file included from /usr/local/include/python3.5m/Python.h:36:0,
                     from src/mplutils.h:21,
                     from src/ft2font_wrapper.cpp:1:
    /usr/include/unistd.h:496:75: error: conflicting declaration of C function ‘void swab(const void*, void*, ssize_t)’
     extern void swab(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, ssize_t);
                                                                               ^
    In file included from /usr/local/include/python3.5m/Python.h:34:0,
                     from src/mplutils.h:21,
                     from src/ft2font_wrapper.cpp:1:
    /usr/include/stdlib.h:143:13: note: previous declaration ‘void swab(const char*, char*, ssize_t)’
     extern void swab(const char *, char *, ssize_t);
                 ^
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
  Rolling back uninstall of matplotlib

The problem is that Solaris tries hard to maintain binary and source code compatibility and what is Unix is a moving target.

In particular you can read this in file /usr/include/stdlib.h:

/*
 * swab() has historically been in <stdlib.h> as delivered from AT&T
 * and continues to be visible in the default compilation environment.
 * As of Issue 4 of the X/Open Portability Guides, swab() was declared
 * in <unistd.h>. As a result, with respect to X/Open namespace the
 * swab() declaration in this header is only visible for the XPG3
 * environment.
 */

That comment is followed with a scary conditional compilacion evaluation. I would usually try to find the magic #define to solve this, but I am in a hurry so I will go quick & dirty:

  1. Do a copy of /usr/include/stdlib.h and just (temporally) delete swab() declaration:

    # cp -a /usr/include/stdlib.h /usr/include/stdlib.h.OLD
    # vi /usr/include/stdlib.h
    (Edit the file and delete "swab()" declaration)
    
  2. Install matplotlib package.

    # python3 -m pip install -U matplotlib
    [...]
    
  3. Recover the old version of the header file:

    # mv /usr/include/stdlib.h.OLD /usr/include/stdlib.h
    

Yes, I agree. This is a huge kludge. Life sucks and time is limited...