]> git.saurik.com Git - wxWidgets.git/blob - wxPython/BUILD.unix.txt
Do not redeclare a struct (w32api 2.2 will have it).
[wxWidgets.git] / wxPython / BUILD.unix.txt
1 Building wxPython on Unix or Unix-like Systems
2 ----------------------------------------------
3
4 The basic steps for building wxPython for Unix or Unix-like systems
5 are:
6
7 1. Compile and/or install glib and gtk+
8 2. Compile and/or install wxGTK
9 3. Compile and install wxPython
10
11 We'll go into more detail of each of these steps below, but first a
12 few bits of background information on tools.
13
14 I use a tool called SWIG (http://www.swig.org) to help generate the
15 C++ sources used in the wxPython extension module. However you don't
16 need to have SWIG unless you want to modify the *.i files. I've made
17 several modifications to SWIG specific to wxPython's needs and so the
18 modified sources are included in the wx CVS at .../wxPython/wxSWIG.
19 If you need to modify the *.i files for wxPython then change to this
20 directory and run:
21
22 configure
23 make
24
25 (Do not run "make install" as wxswig is run in-place.) You'll then
26 need to change a flag in the setup.py script as described below so the
27 wxPython build process will use SWIG if needed.
28
29 I use the new Python Distutils tool to build wxPython. It is included
30 with Python 2.0, but if you want to use Python 1.5.2 or 1.6 then
31 you'll need to download and install Distutils 1.0 from
32 http://www.python.org/sigs/distutils-sig/
33
34 Okay, now on the the fun stuff...
35
36
37 1. Compile and/or install glib and gtk+
38 ---------------------------------------
39
40 A. First of all, check and see if you've already got glib/gtk+ on your
41 system, all the Linux distributions I know of come with it, at
42 least as an option. Look for libglib.* and libgtk.* in your system's
43 standard library directories. You'll also need the headers and
44 config scripts in order to build things that use glib/gtk. Try
45 running gtk-config:
46
47 gtk-config --version
48
49 If you have version 1.2.5 or better then you're all set. You can
50 skip to step #2.
51
52 B. If your system has a binary package mechanism, (RPMs, debs,
53 whatever...) check and see if binaries for glib abd gtk+ are
54 available. Be sure to get the runtime library package as well as
55 the development package, if they are separate. Install them with
56 your package tool, and skip to step #2.
57
58 C. If all else fails, you can get the source code for glib and gtk+ at
59 http://www.gtk.org/. Fetch the latest of each in the 1.2.x
60 series. Compile and install each of them like this:
61
62 gzip -d [package].tar.gz | tar xvf -
63 cd [package]
64 ./configure
65 make
66 make install
67
68 The last step will probably have to be done as root. Also, if your
69 system needs anything done to update the dynamic loader for shared
70 libraries, (such as running ldconfig on Linux) then do it after
71 each library is installed.
72
73
74
75 2. Compile and/or install wxGTK
76 -------------------------------
77
78 A. You can find the sources and RPMs for wxGTK at
79 http://wxwindows.org/, just follow the download links from the
80 nevigation panel. You can also check out a current snapshot of the
81 sources from the CVS server. (Some information about annonymous
82 CVS access is at http://wxwindows.org/cvs.htm.) The advantage of
83 using CVS is that you can easily update as soon as the developers
84 check in new sources or fixes. The advantage of using a released
85 version is that it usually has had more thorough testing done. You
86 can decide which method is best for you.
87
88 B. You'll usually want to use a version of wxGTK that has the same
89 version number as the wxPython sources you are using. (Another
90 advantage of using CVS is that you'll get both at the same time.)
91
92 C. If using the RPMs be sure to get both the wxGTK and wxGTK-devel
93 RPMs (at a minimum) and then install them as root.
94
95 rpm -Uhv wxGTK-2.2.2-0.i386.rpm wxGTK-devel-2.2.2-0.i386.rpm
96
97 D. If using the sources (either from the tarball or from CVS) then
98 configure it like this:
99
100 cd wxWindows # or whatever your top-level directory is called
101 mkdir build
102 cd build
103 ../configure --with-gtk
104
105 There are gobs and gobs of options for the configure script, run
106 ../configure --help to see them all. I'll describe some that I find
107 useful here.
108
109 If you have OpenGL or compatible libraries installed, then add the
110 --with-opengl flag.
111
112 If you are on Solaris and are using a recent version of GCC, then
113 you'll probably want to add the --enable-permissive flag so the
114 compiler won't barf on your broken X11 header files.
115
116 To make a debugging version of wxGTK, add the --enable-debug flag.
117 This sets the -g flag for the compiler and also activates some
118 special debugging code in wxWindows by defining the __WXDEBUG__
119 macro. You'll get some extra asserts, failure logging, etc.
120
121 To make a static library and not make a shared library, use the
122 --disable-shared and --enable-static flags.
123
124 NOTE: There is a potential type mismatch between Python and wxGTK.
125 This happens if Python defines some flags that turn on 64-bit file
126 offset support and wxGTK does not. This causes some basic types,
127 like off_t, to be typedef'd differently causing the C++ method
128 signatures to be incompatible and giving link errors at runtime.
129 If you get errors upon running a wxPython script that looks
130 something like this:
131
132 SeekI_13wxInputStream10wxSeekMode: referenced symbol not found
133
134 then that is probably the issue. This can be fixed in the current
135 code by predefining these flags before wxGTK's configure is run,
136 for example:
137
138 export CFLAGS="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DHAVE_LARGEFILE_SUPPORT"
139 export CXXFLAGS=$CFLAGS
140 ../configure --with-gtk --with-opengl --enable-debug
141
142 In the 2.3.3 final release there will be a real configure flag for
143 it, and it should be enabled by default. You will be able to use
144 --enable-largefile or --disable-largefile to control it. If you
145 still get this or a similar error with 2.3.3 then try disabling
146 largefile support in wxGTK.
147
148 E. Now just compile and install. You need to use GNU make, so if your
149 system has something else get GNU make and build and install it and
150 use it instead of your system's default make command.
151
152 make
153 make install
154
155 The last step will probably have to be done as root. Also, if your
156 system needs anything done to update the dynamic loader for shared
157 libraries, (such as running ldconfig on Linux) then do it now.
158
159 F. You can test your build by changing to one of the directories under
160 build/samples or build/demos, running make and then running the
161 executable that is built.
162
163
164
165 3. Compile and install wxPython
166 -------------------------------
167
168 A. You have the same options (and same advantages/disadvantages) for
169 getting the wxPython source, either a released snapshot or from
170 CVS. The released version file is named wxPython-[version].tar.gz
171 and is available at http://wxpython.org/download.php. If you want
172 to use CVS you'll find wxPython in the wxWindows CVS tree (see
173 above) in the wxWindows/wxPython directory.
174
175 B. As mentioned previouslly, wxPython is built with the standard
176 Python Distutils tool. If you are using Python 2.0 or later you
177 are all set, otherwise you need to download and install Distutils
178 1.0 from http://www.python.org/sigs/distutils-sig/.
179
180 On Unix systems Distutils figures out what commands and flags to
181 use for the compiler and linker by looking in the Makefile that was
182 used to build Python itself. Most of the time this works okay. If
183 it doesn't, there doesn't seem to be a way to override the values
184 that Distutils uses without hacking either Distutils itself, or
185 Python's Makefile. (Complain to the distutils-sig about this
186 please.) For example, on a Solaris system I had to edit
187 /usr/local/lib/python1.5/config/Makefile and replace
188
189 LDSHARED=ld -G
190
191 with
192
193 LDSHARED=gcc -G
194
195 This particular problem has been fixed in Python 1.6 and beyond,
196 but there may be similar issues on other platforms.
197
198 While we're on the subject of how Python was built... Since
199 wxPython is a C++ extension some platforms and/or compilers will
200 require that the Python executable was linked with the C++ linker
201 in order for everything to work correctly. If you build and
202 install Python yourself then this is easy to take care of,
203 otherwise you may have to mess with binary packages or bribe your
204 system administrator...
205
206 In my case on Solaris wxPython applications would core dump on
207 exit. The core file indicated that the fault happened after
208 _exit() was called and the run-time library was trying to execute
209 cleanup code. After relinking the Python executable the problem
210 went away. To build Python to link with the C++ linker do this:
211
212 cd Python-2.0 # wherever the root of the source tree is
213 rm python # in case it's still there from an old build
214 make LINKCC=g++ # or whatever your C++ command is
215 make install
216
217 I recently built Python 2.1.3 and Python 2.2.1 on Solaris and did
218 not have to resort to this workaround so apparently thigns are
219 getting better there. I will leave this note here though in case
220 there are similar issues elsewhere. However I did run into a
221 Python build issue that affects the wxPython build when attempting
222 to use SunCC instead of GNU gcc. See the note below titled
223 "Building with non-GNU compilers" if you are interested.
224
225 C. Change to the root wxPython directory and look at the setup.py
226 file. This is the script that configures and defines all the
227 information that Distutils needs to build wxPython. There are some
228 options near the begining of the script that you may want or need
229 to change based on your system and what options you have selected
230 up to this point, (sources from tar.gz or from CVS, etc.) You can
231 either change these flags directly in setup.py or supply them on
232 the command-line.
233
234 BUILD_GLCANVAS Set to zero if you don't want to build the
235 Open GL canvas extension module. If you don't
236 have OpenGL or compatible libraries then you'll
237 need to set this to zero.
238
239 BUILD_OGL Set to zero if you don't want to build the
240 Object Graphics Library extension module.
241
242 BUILD_STC Set to zero if you don't want to build the
243 wxStyledTextCtrl (the Scintilla wrapper)
244 extension module.
245
246 USE_SWIG If you have edited any of the *.i files you
247 will need to set this flag to non-zero so SWIG
248 will be executed to regenerate the wrapper C++
249 and shadow python files.
250
251 IN_CVS_TREE If you are using the CVS version of the
252 wxWindows and wxPython sources then you will
253 need to set this flag to non-zero. This is
254 needed because some source files from the
255 wxWindows tree are copied to be under the
256 wxPython tree in order to keep Distutils happy.
257 With this flag set then setup.py will
258 automatically keep these copied sources up to
259 date if the original version is ever updated.
260 If you are using the tar.gz version of the
261 Python sources then these copied sources are
262 already present in your source tree.
263
264
265 D. To build and install wxPython you simply need to execute the
266 setup.py script. If you have more than one version of Python
267 installed, be sure to execute setup.py with the version you want to
268 build wxPython for. Depending on the permissions on your
269 site-packages directory you may need to be root to run the install
270 command.
271
272 python setup.py build
273 python setup.py install
274
275 E. At this point you should be able to change into the wxPython/demo
276 directory and run the demo:
277
278 python demo.py
279
280 F. If you would like to make a test build that doesn't overwrite the
281 installed version of wxPython you can do so with this command
282 instead of the install command above:
283
284 python setup.py build_ext --inplace
285
286 This will build the wxPython package in the local wxPython
287 directory instead of installing it under your Python installation.
288 To run using this test version just add the base wxPython source
289 directory to the PYTHONPATH:
290
291 export PYTHONPATH=~/projects/wxWindows/wxPython
292 # or whatever is required for your shell
293 cd ~/projects/wxWindows/wxPython/demo
294 python demo.py
295
296
297
298 4. Building with non-GNU compilers
299 ----------------------------------
300
301 As mentioned above Python's distutils uses whatever compiler Python
302 was compiled with to compile extension modules. It also appears that
303 distutils assumes that this compiler can compile C or C++ sources as
304 distutils makes no differentiation between the two. For builds using
305 GNU gcc and a few other compilers this is not an issue as they will
306 determine the type of source from the file extension. For SunCC (and
307 probably other compilers that came from cfront) it won't work as the C
308 compiler (cc) is totally separate from the C++ compiler (CC). This
309 causes distutils to attempt to compile the wxPython sources with the C
310 compiler, which won't work.
311
312 There may be better ways to get around this, but here is the
313 workaround I devised. I created a script that will execute either cc
314 or CC based on the file extension given to it. If Python uses this
315 script for its compiler then it will also be used by extensions built
316 with distutils and everybody will be more or less happy. Here is a
317 copy of the script I used. It was a fairly quick rush job so there
318 are probably issues with it but it worked for me.
319
320 #!/bin/bash
321 #--------------------------------------------------------------
322 # Try to determine type of file being compiled and then
323 # launch cc for C sources or CC for C++.
324 #
325
326 args=$@
327 is_C=
328
329 for arg in $args; do
330
331 # is the arg a file that exists?
332 if [ -e $arg ]; then
333
334 # does it end in ".c"?
335 if [ "${arg:${#arg}-2}" == ".c" ]; then
336 is_C=yes
337 fi
338 fi
339 done
340
341 # if the flag wasn't set then assume C++ and execute CC,
342 # otherwise execute cc.
343 if [ -z $is_C ]; then
344 exec CC -w $@
345 else
346 exec cc -w $@
347 fi
348 #--------------------------------------------------------------
349
350 I called it pycc, put it in ${prefix}/bin and set its execute
351 permission bit.
352
353 The next step is to configure and build Python such that it uses pycc
354 as it's compiler. You can do that by setting CC in your environment
355 before running configure, like this in bash:
356
357 export CC=pycc
358 configure
359
360 After making and installing Python with this configuration you should
361 be able to build wxPython as described in the steps above.
362
363 -----------------
364 robin@alldunn.com