11"""
22Some helper functions for building the C extensions
33
4- BUILDING ON WIN32
4+ you may need to edit basedir to point to the default location of your
5+ required libs, eg, png, z, freetype
56
6- * You need to make the cygwin import library. Assuming you have a
7- typical cygwin and python install, run the script importlib22.bat or
8- importlib23.bat to build the python2.2 or 2.3 import libs
7+ DARWIN
98
10- * You need to following libraries (saved in win32_static):
9+ I have installed all of the backends on OSX.
1110
12- http://gnuwin32.sourceforge.net/downlinks/freetype.php
13- http://gnuwin32.sourceforge.net/downlinks/zlib.php
14- http://gnuwin32.sourceforge.net/downlinks/libgw32c.php
15- http://gnuwin32.sourceforge.net/downlinks/libpng.php
16- http://www.activestate.com/Products/Download/Download.plex?id=ActiveTcl
11+ Tk: If you want to install TkAgg, I recommend the "batteries included"
12+ binary build of Tcl/Tk at
13+ http://www.apple.com/downloads/macosx/unix_open_source/tcltkaqua.html
1714
18- * To install the gtk packages, you need pkg-config. This is
19- included in the GTK development lib. You should have the GTK
20- runtime and development libs installed to C:\GTK and make sure
21- c:\GTK\lib and c:\GTK\b in are in your PATH. Also, copy
22- win32_static/pygtk-2.0.pc to c:\GTK\lib\pkgconfig
23-
24- * You must patch distutils for python23 or python22 to build agg
25- with g++. See
26- http://mail.python.org/pipermail/distutils-sig/2004-January/003553.html.
27- Edit c:/Python23/lib/distutils/cygwinccompiler.py and add the line
28- to the two set_executables calls
15+ GTK: I installed GTK from src as described at
16+ http://www.macgimp.org/index.php?topic=gtk. There are several
17+ packages, but all configure/make/make install w/o problem. In
18+ addition to the packages listed there, You will also need libpng,
19+ libjpeg, and libtiff if you want output to these formats from GTK.
2920
30- compiler_cxx='g++ -mcygwin -O -Wall',
21+ WIN32
3122
32- * build command
23+ If you are sufficiently masochistic that you want to build this
24+ yourself, contact me and I'll send you win32_static as a zip file.
3325
34- > python setup.py build --compiler=mingw32 > build23.out
26+ python setup.py build --compiler=mingw32 bdist_wininst --install-script postinstall.py > build23.out
3527
36- * make the windows installer
37-
38- > python setup.py bdist_wininst
39-
40- Note on some systems this fails with a "extensions need to be
41- built with the same version of the compiler" message. The
42- following workaround helps
28+ """
4329
44- > python setup.py build --compiler=mingw32 bdist_wininst > build23.out
45-
46- See for details http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=mailman.1060311735.32666.python-list%40python.org&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dpython%2B%2522extensions%2Bneed%2Bto%2Bbe%2Bbuilt%2Bwith%2Bthe%2Bsame%2Bversion%2Bof%2Bthe%2Bcompiler%2522
30+ basedir = {
4731
32+ 'win32' : 'win32_static' ,
33+ 'linux2' : '/usr' ,
34+ 'linux' : '/usr' ,
35+ 'darwin' : '/usr/local' ,
36+ }
4837
49- Note building for python22. Delete c:\python22\lib\distutils and copy
50- the (patched) python23 version into this folder. Delete all the
51- *.pyc in c:\python22\lib\distutils and the command subdir. Should work
52-
53-
54- """
5538import sys , os
5639from distutils .core import Extension
5740import glob
@@ -81,18 +64,12 @@ def getoutput(s):
8164def add_agg_flags (module ):
8265 'Add the module flags to build extensions which use agg'
8366
84- module .include_dirs .extend (['src' ,'agg2/include' ])
85- module .libraries .extend (['freetype' , 'png' , 'z' ])
86- if sys .platform == 'win32' :
87- module .include_dirs .extend (
88- ['win32_static/include' , ] )
89- module .library_dirs .append ('win32_static' )
90- module .libraries .append ('gw32c' )
67+ # before adding the freetype flags since -z comes later
68+ module .libraries .append ('png' )
9169
92- else :
93- module .include_dirs .extend (
94- ['/usr/include/freetype2' ,]
95- )
70+ add_ft2font_flags (module )
71+
72+ module .include_dirs .extend (['src' ,'agg2/include' ])
9673
9774 # put these later for correct link order
9875 module .libraries .extend (['stdc++' , 'm' ])
@@ -106,17 +83,14 @@ def add_gd_flags(module):
10683def add_ft2font_flags (module ):
10784 'Add the module flags to build extensions which use gd'
10885 module .libraries .extend (['freetype' , 'z' ])
86+
87+ inc = os .path .join (basedir [sys .platform ], 'include' )
88+ module .include_dirs .append (inc )
89+ module .include_dirs .append (os .path .join (inc , 'freetype2' ))
90+ module .library_dirs .append (os .path .join (basedir [sys .platform ], 'lib' ))
91+
10992 if sys .platform == 'win32' :
110- module .include_dirs .extend (
111- [ 'win32_static/include' , # for ft2build.h
112- 'win32_static/include/freetype' , # renamed from freetype2
113- ]
114- )
115- module .library_dirs .append ('win32_static' )
11693 module .libraries .append ('gw32c' )
117- else :
118- module .include_dirs .extend (
119- ['/usr/include' , '/usr/include/freetype2' ,])
12094
12195 # put this last for library link order
12296 module .libraries .append ('m' )
@@ -131,44 +105,31 @@ def add_pygtk_flags(module):
131105 module .library_dirs .extend (
132106 ['C:/GTK/bin' , 'C:/GTK/lib' ])
133107
134-
135108 module .include_dirs .extend (
136109 ['win32_static/include/pygtk-2.0' ,
137110 'C:/GTK/include' ,
138- 'C:/GTK/include/glib-2.0' ,
139- 'C:/GTK/lib/glib-2.0/include' ,
140- 'C:/GTK/include/gtk-2.0' ,
141- 'C:/GTK/lib/gtk-2.0/include' ,
142- 'C:/GTK/include/atk-1.0' ,
143- 'C:/GTK/include/pango-1.0' ,
144111 ])
145-
146- module .libraries .extend ([
147- 'gtk-win32-2.0' , 'gdk-win32-2.0' , 'atk-1.0' ,
148- 'gdk_pixbuf-2.0' , 'pangowin32-1.0' , 'gdi32' ,
149- 'pango-1.0' , 'gobject-2.0' , 'gmodule-2.0' ,
150- 'glib-2.0' , 'intl' , 'iconv' ])
151112
152- else :
153- pygtkIncludes = getoutput ('pkg-config --cflags-only-I pygtk-2.0' ).split ()
154- gtkIncludes = getoutput ('pkg-config --cflags-only-I gtk+-2.0' ).split ()
155- includes = pygtkIncludes + gtkIncludes
156- module .include_dirs .extend ([include [2 :] for include in includes ])
157113
158- pygtkLinker = getoutput ('pkg-config --libs pygtk-2.0' ).split ()
159- gtkLinker = getoutput ('pkg-config --libs gtk+-2.0' ).split ()
160- linkerFlags = pygtkLinker + gtkLinker
114+ pygtkIncludes = getoutput ('pkg-config --cflags-only-I pygtk-2.0' ).split ()
115+ gtkIncludes = getoutput ('pkg-config --cflags-only-I gtk+-2.0' ).split ()
116+ includes = pygtkIncludes + gtkIncludes
117+ module .include_dirs .extend ([include [2 :] for include in includes ])
161118
162- module .libraries .extend (
163- [flag [2 :] for flag in linkerFlags if flag .startswith ('-l' )])
119+ pygtkLinker = getoutput ('pkg-config --libs pygtk-2.0' ).split ()
120+ gtkLinker = getoutput ('pkg-config --libs gtk+-2.0' ).split ()
121+ linkerFlags = pygtkLinker + gtkLinker
164122
165- module .library_dirs .extend (
166- [flag [2 :] for dir in linkerFlags if flag .startswith ('-L' )])
123+ module .libraries .extend (
124+ [flag [2 :] for flag in linkerFlags if flag .startswith ('-l' )])
125+
126+ module .library_dirs .extend (
127+ [flag [2 :] for dir in linkerFlags if flag .startswith ('-L' )])
167128
168129
169- module .extra_link_args .extend (
170- [flag for flag in linkerFlags if not
171- (flag .startswith ('-l' ) or flag .startswith ('-L' ))])
130+ module .extra_link_args .extend (
131+ [flag for flag in linkerFlags if not
132+ (flag .startswith ('-l' ) or flag .startswith ('-L' ))])
172133
173134
174135def add_tk_flags (module ):
@@ -178,6 +139,9 @@ def add_tk_flags(module):
178139 module .include_dirs .extend (['win32_static/include/tcl' ])
179140 module .library_dirs .extend (['C:/Python23/dlls' ])
180141 module .libraries .extend (['tk84' , 'tcl84' ])
142+ elif sys .platform == 'darwin' :
143+ module .extra_link_args .extend (['-framework' ,'Tcl' ])
144+ module .extra_link_args .extend (['-framework' ,'Tk' ])
181145 else :
182146 module .libraries .extend (['tk' , 'tcl' ])
183147
0 commit comments