1
1
"""
2
2
Some helper functions for building the C extensions
3
3
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
5
6
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
9
8
10
- * You need to following libraries (saved in win32_static):
9
+ I have installed all of the backends on OSX.
11
10
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
17
14
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.
29
20
30
- compiler_cxx='g++ -mcygwin -O -Wall',
21
+ WIN32
31
22
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.
33
25
34
- > python setup.py build --compiler=mingw32 > build23.out
26
+ python setup.py build --compiler=mingw32 bdist_wininst --install-script postinstall.py > build23.out
35
27
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
+ """
43
29
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 = {
47
31
32
+ 'win32' : 'win32_static' ,
33
+ 'linux2' : '/usr' ,
34
+ 'linux' : '/usr' ,
35
+ 'darwin' : '/usr/local' ,
36
+ }
48
37
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
- """
55
38
import sys , os
56
39
from distutils .core import Extension
57
40
import glob
@@ -81,18 +64,12 @@ def getoutput(s):
81
64
def add_agg_flags (module ):
82
65
'Add the module flags to build extensions which use agg'
83
66
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' )
91
69
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' ])
96
73
97
74
# put these later for correct link order
98
75
module .libraries .extend (['stdc++' , 'm' ])
@@ -106,17 +83,14 @@ def add_gd_flags(module):
106
83
def add_ft2font_flags (module ):
107
84
'Add the module flags to build extensions which use gd'
108
85
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
+
109
92
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' )
116
93
module .libraries .append ('gw32c' )
117
- else :
118
- module .include_dirs .extend (
119
- ['/usr/include' , '/usr/include/freetype2' ,])
120
94
121
95
# put this last for library link order
122
96
module .libraries .append ('m' )
@@ -131,44 +105,31 @@ def add_pygtk_flags(module):
131
105
module .library_dirs .extend (
132
106
['C:/GTK/bin' , 'C:/GTK/lib' ])
133
107
134
-
135
108
module .include_dirs .extend (
136
109
['win32_static/include/pygtk-2.0' ,
137
110
'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' ,
144
111
])
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' ])
151
112
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 ])
157
113
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 ])
161
118
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
164
122
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' )])
167
128
168
129
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' ))])
172
133
173
134
174
135
def add_tk_flags (module ):
@@ -178,6 +139,9 @@ def add_tk_flags(module):
178
139
module .include_dirs .extend (['win32_static/include/tcl' ])
179
140
module .library_dirs .extend (['C:/Python23/dlls' ])
180
141
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' ])
181
145
else :
182
146
module .libraries .extend (['tk' , 'tcl' ])
183
147
0 commit comments