11"""
22Some helper functions for building the C extensions
3+
4+ BUILDING ON WIN32
5+
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
9+
10+ * You need to following libraries (saved in win32_static):
11+
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
17+
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
29+
30+ compiler_cxx='g++ -mcygwin -O -Wall',
31+
32+ * build command
33+
34+ > python setup.py build --compiler=mingw32 > build23.out
35+
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
43+
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
47+
48+
49+ Current problems:
50+
51+ c:\mingw\b in\dllwrap.exe -mno-cygwin -mdll -static --entry _DllMain@12 --output-lib build\t emp.win32-2.2\Release\lib_tkagg.a --def build\t emp.win32-2.2\Release\_tkagg.def -s build\t emp.win32-2.2\Release\_tkagg.o -LC:/Python23/dlls -Lwin32_static -LC:\PYTHON22\libs -ltk84 -ltcl84 -lfreetype -lpng -lz -lgw32c -lstdc++ -lm -lpython22 -o build\lib.win32-2.2\matplotlib\b ackends\_tkagg.pyd
52+ error: command 'dllwrap' failed with exit status 1
53+
54+ ideas: libstdc++ or libpython22 need to be moved up in link order?
55+
356"""
457import sys , os
558from distutils .core import Extension
2275
2376def getoutput (s ):
2477 'get the output of a system command'
25- return os .popen (s ).read ().strip ()
78+
79+ ret = os .popen (s ).read ().strip ()
80+ return ret
2681
2782
2883def add_agg_flags (module ):
@@ -32,7 +87,7 @@ def add_agg_flags(module):
3287 module .libraries .extend (['freetype' , 'png' , 'z' ])
3388 if sys .platform == 'win32' :
3489 module .include_dirs .extend (
35- ['c:/GnuWin32 /include' , ] )
90+ ['win32_static /include' , ] )
3691 module .library_dirs .append ('win32_static' )
3792 module .libraries .append ('gw32c' )
3893
@@ -55,8 +110,8 @@ def add_ft2font_flags(module):
55110 module .libraries .extend (['freetype' , 'z' ])
56111 if sys .platform == 'win32' :
57112 module .include_dirs .extend (
58- [ 'c:/GnuWin32/ include' , # for ft2build.h
59- 'c:/GnuWin32 /include/freetype' , # renamed from freetype2
113+ [ 'win32_static/ include' , # for ft2build.h
114+ 'win32_static /include/freetype' , # renamed from freetype2
60115 ]
61116 )
62117 module .library_dirs .append ('win32_static' )
@@ -72,37 +127,58 @@ def add_ft2font_flags(module):
72127
73128def add_pygtk_flags (module ):
74129 'Add the module flags to build extensions which use gtk'
75- pygtkIncludes = getoutput ('pkg-config --cflags-only-I pygtk-2.0' ).split ()
76- gtkIncludes = getoutput ('pkg-config --cflags-only-I gtk+-2.0' ).split ()
77- includes = pygtkIncludes + gtkIncludes
78- module .include_dirs .extend ([include [2 :] for include in includes ])
79130
80- pygtkLinker = getoutput ('pkg-config --libs pygtk-2.0' ).split ()
81- gtkLinker = getoutput ('pkg-config --libs gtk+-2.0' ).split ()
82- linkerFlags = pygtkLinker + gtkLinker
131+ if sys .platform == 'win32' :
132+ # popen broken on my win32 plaform so I can't use pkgconfig
133+ module .library_dirs .extend (
134+ ['C:/GTK/bin' , 'C:/GTK/lib' ])
83135
84- module .libraries .extend (
85- [flag [2 :] for flag in linkerFlags if flag .startswith ('-l' )])
86136
87- module .library_dirs .extend (
88- [flag [2 :] for dir in linkerFlags if flag .startswith ('-L' )])
137+ module .include_dirs .extend (
138+ ['win32_static/include/pygtk-2.0' ,
139+ 'C:/GTK/include' ,
140+ 'C:/GTK/include/glib-2.0' ,
141+ 'C:/GTK/lib/glib-2.0/include' ,
142+ 'C:/GTK/include/gtk-2.0' ,
143+ 'C:/GTK/lib/gtk-2.0/include' ,
144+ 'C:/GTK/include/atk-1.0' ,
145+ 'C:/GTK/include/pango-1.0' ,
146+ ])
147+
148+ module .libraries .extend ([
149+ 'gtk-win32-2.0' , 'gdk-win32-2.0' , 'atk-1.0' ,
150+ 'gdk_pixbuf-2.0' , 'pangowin32-1.0' , 'gdi32' ,
151+ 'pango-1.0' , 'gobject-2.0' , 'gmodule-2.0' ,
152+ 'glib-2.0' , 'intl' , 'iconv' ])
89153
90- if sys . platform == 'win32' :
91- module . library_dirs . extend ([ 'C: \\ GTK \\ bin' , 'C: \\ GTK \\ lib' ] )
92- module . extra_link_args . extend (
93- [ flag for flag in linkerFlags if not
94- ( flag . startswith ( '-l' ) or flag . startswith ( '-L' )) ])
154+ else :
155+ pygtkIncludes = getoutput ( 'pkg-config --cflags-only-I pygtk-2.0' ). split ( )
156+ gtkIncludes = getoutput ( 'pkg-config --cflags-only-I gtk+-2.0' ). split ()
157+ includes = pygtkIncludes + gtkIncludes
158+ module . include_dirs . extend ([ include [ 2 :] for include in includes ])
95159
160+ pygtkLinker = getoutput ('pkg-config --libs pygtk-2.0' ).split ()
161+ gtkLinker = getoutput ('pkg-config --libs gtk+-2.0' ).split ()
162+ linkerFlags = pygtkLinker + gtkLinker
96163
164+ module .libraries .extend (
165+ [flag [2 :] for flag in linkerFlags if flag .startswith ('-l' )])
166+
167+ module .library_dirs .extend (
168+ [flag [2 :] for dir in linkerFlags if flag .startswith ('-L' )])
169+
170+
171+ module .extra_link_args .extend (
172+ [flag for flag in linkerFlags if not
173+ (flag .startswith ('-l' ) or flag .startswith ('-L' ))])
97174
98-
99175
100176def add_tk_flags (module ):
101177 'Add the module flags to build extensions which use tk'
102178
103179 if sys .platform == 'win32' :
104- module .include_dirs .extend (['C: \\ Tcl \\ include' ])
105- module .library_dirs .extend (['C:\\ Tcl \\ lib ' ])
180+ module .include_dirs .extend (['win32_static/ include/tcl ' ])
181+ module .library_dirs .extend (['C:/Python23/dlls ' ])
106182 module .libraries .extend (['tk84' , 'tcl84' ])
107183 else :
108184 module .libraries .extend (['tk' , 'tcl' ])
0 commit comments