Building matplotlib on Leopard

I did this with a MacPorts build system. It checks out the matplotlib from subversion, applies some patches, then builds.

Ah, I built with Apple's pre-release GCC 4.2 for Leopard, which is available for ADC members... I have also built this with a "stock" GCC 4.2.1, so you might be able to just get that compiler. And almost certainly it would work with Apple's GCC 4.0, but you'll have to remove the CFLAGS settings (see below).

Oh yes... I also didn't like the flags that Apple used to build Python; distutils has no way of overriding these and it breaks GCC 4.2.x. So I used a 'fake' gcc that strips off the offending flags and then calls the 'real' compiler:

I used MacPorts to do all this. But here is a way that might work with a bash shell -- I'm just writing this down as an example, I haven't tested it, but this is sort of what I have in mind:

### ;;;;;;;;;;;;;;;;;;;;;;;;;;; cut here

mkdir mpl-devel
cd mpl-devel

cat > gccflt-4.2 <<EOF
#!/usr/bin/env python

# test with this at the command line
# ./gccflt-4.2 -v -x c -E -mtune=native /dev/null -o /dev/null 2>&1

import sys
import os

realprog = "/usr/bin/gcc-4.2"
options_to_remove = set(['-no-cpp-precomp', '-Wno-long-double',
                          '-mno-fused-madd', '-faltivec',
                         ])

args = [a for a in sys.argv[1:] if a not in options_to_remove]

args.insert(0, '-fno-strict-aliasing')
print args
os.execvp(realprog, [realprog] + args)
EOF

sed -e 's,gcc-4.2,g++-4.2' < gccflt > g++flt

chmod +x gccflt
chmod +x g++flt

svn co matplotlib download | SourceForge.net -r '{2007-10-25}'
;
export CPPFLAGS=\(/usr/X11R6/bin/freetype\-config \-\-cflags\) export LDFLAGS=(/usr/X11R6/bin/freetype-config --libs )
export ARCHFLAGS='-arch i386'

cd matplotlib

patch -p0 < ~/Desktop/patch-setupext.py
patch -p0 < ~/Desktop/patch-stdc++

python setup.py build
python setup.pu install

#;;;;;;;;;;;;;;;;;;;
#================================= end shell script

One of my targets is to make a "developer" build available - which means that my boss will be gently reminding me to provide this.

I was granted commit permissions on MacPorts, but have so far failed to commit my things back upstream to them; before Leopard I had really torn up their Python modules so that everything is deployed in a single /opt/local... tree. (I didn't put things in /Library).

With Leopard, if you want to use the system (Apple) Python, then I put things in /Library/Python/2.5/site-packages. I'm not sure that's the best thing to do. Initially it seems like no problem but we *always* run into conflicts, or want to have multiple versions available simultaneously...

Portfile (3.7 KB)

patch-setupext.py (1.41 KB)

patch-stdc++ (329 Bytes)

···

On Nov 14, 2007, at 11:11 AM, Jeremy Conlin wrote:

Mr. Waters,

I read on the matplotlib mailing lists that you have compiled
matplotlib on Leopard using libpng, freetype, etc. that are included
with Leopard. I am trying to do the same, but have so far been
unsuccessful. I could install those libraries from source, but would
rather not. Would you mind sharing what you did to compile matplotlib
with the included libraries?

> Mr. Waters,
>
> I read on the matplotlib mailing lists that you have compiled
> matplotlib on Leopard using libpng, freetype, etc. that are included
> with Leopard. I am trying to do the same, but have so far been
> unsuccessful. I could install those libraries from source, but would
> rather not. Would you mind sharing what you did to compile matplotlib
> with the included libraries?

I did this with a MacPorts build system. It checks out the matplotlib
from subversion, applies some patches, then builds.

Ah, I built with Apple's pre-release GCC 4.2 for Leopard, which is
available for ADC members... I have also built this with a "stock" GCC
4.2.1, so you might be able to just get that compiler. And almost
certainly it would work with Apple's GCC 4.0, but you'll have to
remove the CFLAGS settings (see below).

Oh yes... I also didn't like the flags that Apple used to build
Python; distutils has no way of overriding these and it breaks GCC
4.2.x. So I used a 'fake' gcc that strips off the offending flags and
then calls the 'real' compiler:

I used MacPorts to do all this. But here is a way that might work with
a bash shell -- I'm just writing this down as an example, I haven't
tested it, but this is sort of what I have in mind:

### ;;;;;;;;;;;;;;;;;;;;;;;;;;; cut here

mkdir mpl-devel
cd mpl-devel

cat > gccflt-4.2 <<EOF
#!/usr/bin/env python

# test with this at the command line
# ./gccflt-4.2 -v -x c -E -mtune=native /dev/null -o /dev/null 2>&1

import sys
import os

realprog = "/usr/bin/gcc-4.2"
options_to_remove = set(['-no-cpp-precomp', '-Wno-long-double',
                          '-mno-fused-madd', '-faltivec',
                         ])

args = [a for a in sys.argv[1:] if a not in options_to_remove]

args.insert(0, '-fno-strict-aliasing')
print args
os.execvp(realprog, [realprog] + args)
EOF

sed -e 's,gcc-4.2,g++-4.2' < gccflt > g++flt

chmod +x gccflt
chmod +x g++flt

svn co matplotlib download | SourceForge.net
  -r '{2007-10-25}'
;
export CPPFLAGS=\(/usr/X11R6/bin/freetype\-config \-\-cflags\) export LDFLAGS=(/usr/X11R6/bin/freetype-config --libs )
export ARCHFLAGS='-arch i386'

cd matplotlib

patch -p0 < ~/Desktop/patch-setupext.py
patch -p0 < ~/Desktop/patch-stdc++

python setup.py build
python setup.pu install

#;;;;;;;;;;;;;;;;;;;
#================================= end shell script

One of my targets is to make a "developer" build available - which
means that my boss will be gently reminding me to provide this.

I was granted commit permissions on MacPorts, but have so far failed
to commit my things back upstream to them; before Leopard I had really
torn up their Python modules so that everything is deployed in a
single /opt/local... tree. (I didn't put things in /Library).

With Leopard, if you want to use the system (Apple) Python, then I put
things in /Library/Python/2.5/site-packages. I'm not sure that's the
best thing to do. Initially it seems like no problem but we *always*
run into conflicts, or want to have multiple versions available
simultaneously...

Hope this helps!

I'm sorry, but I couldn't get that shell script to work. I tried
copying everything between the "perforations" into a MPL.sh file.
Then I executed the file as

bash MPL.sh

That didn't work. I also tried making a Python file from the portion
that looks like Python code, but I couldn't get that to do anything
useful either.

Please forgive my ignorance :-!

Oh, shoot... I didn't tell you how to build IPython with readline
support... this email is too long already, but search the IPython dev
list or I can send along a patch.

I would like a patch for this too, if you don't mind! IPython was my
next step after matplotlib.

Thanks a bunch,
Jeremy

···

On Nov 14, 2007 3:00 PM, Boyd Waters <bwaters@...451...> wrote:

On Nov 14, 2007, at 11:11 AM, Jeremy Conlin wrote:

   - boyd

Boyd Waters
http://www.aoc.nrao.edu/~bwaters