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