building.html 18.8 KB
Newer Older
1 2 3 4 5 6 7 8
<HTML>
<HEAD>
<TITLE>Building Mac Python from source</TITLE>
</HEAD>
<BODY>
<H1>Building Mac Python from source</H1>
<HR>

9
This document explains how to build MacPython from source. This is
Jack Jansen's avatar
Jack Jansen committed
10 11 12
necessary if you want to make modifications to the Python core. Building
Python is not something to be undertaken lightly, you need a reasonable
working knowledge of the CodeWarrior development environment, a good net
13
connection and probably quite some time too. <p>
14

15 16 17
Note that if you only want to build new extension modules you don't need to
build Python from source, see the <a href="#extending">note on extending Python</a>.<p>

18 19 20 21
The information density in this file is high, so you should probably
print it and read it at your leasure. Most things are explained only
once (and probably in the wrong place:-). <p>

22 23 24 25
<blockquote>
First a warning: this information may become outdated if a new CodeWarrior is
released after MacPython. The 
<a href="http://www.cwi.nl/~jack/macpython.html">MacPython homepage</a> will
26
hopefully have updated instructions in that case. These instructions are for CW7.
27 28
</blockquote>

29
I am very interested in feedback on this document, send your
30 31 32
comments to the <A
HREF="http://www.python.org/sigs/pythonmac-sig/">Mac Python Special
Interest Group</A>.
33 34 35 36 37 38

<H2>What you need.</H2>

The following things you definitely need:

<UL>
39 40

<LI> You need a MacPython source distribution, of course. You can
41 42
obtain one via <A HREF="http://www.cwi.nl/~jack/macpython.html">
http://www.cwi.nl/~jack/macpython.html</A>  (which has up-to-date links
43 44
to the other packages needed too) and possibly also from the standard
<A HREF="ftp://ftp.python.org/pub/python/mac">python.org ftp
Jack Jansen's avatar
Jack Jansen committed
45
site</A>. <BR>
46

Jack Jansen's avatar
Jack Jansen committed
47
A better alternative is to check the sources straight out of the CVS
48 49 50
repository, see below. Most of the packages mentioned here are also
available through CVS. Check the section on <a href="#cvs">CVS
repository use</a> below.
51 52

<LI> You need MetroWerks CodeWarrior. The current distribution has
53
been built with CodeWarrior Pro 7.1. Ordering information is
54
available on the <A HREF="http://www.metrowerks.com/">MetroWerks
55 56
homepage</A>. Building Python with MPW, Think/Symantec C or the OSX
developer tools is impossible without major surgery.
57

Jack Jansen's avatar
Jack Jansen committed
58 59
<LI> You need GUSI version 2, the Grand Unified Socket Interface, by
Matthias Neeracher. The original GUSI is obtainable from <A
60 61
HREF="ftp://gusi.sourceforge.net/pub/gusi/">
ftp://gusi.sourceforge.net/pub/gusi/</A>. At
62 63
the moment Python is built with a modified version of GUSI
with Carbon adaptations, so it may be better to check the <A
Jack Jansen's avatar
Jack Jansen committed
64 65
HREF="http://www.cwi.nl/~jack/macpython.html">MacPython homepage</A>
for a GUSI that is most easily used for building Python. 
66

67 68
</UL>

69 70
<A NAME="optional">The MacPython project files are configured to
include a plethora of optional modules</A>, and these modules need a
71
number of extra packages. To use the project files as-is you have to
Jack Jansen's avatar
Jack Jansen committed
72
download these packages too. Python has all such modules as
73
dynamically loaded modules, so if you don't need a certain package it
Jack Jansen's avatar
Jack Jansen committed
74 75
suffices to just refrain from builing the extension module.
Here are the locations for the various things
76
you need:
77 78

<UL>
79

80 81
<LI> Tcl and Tk are somewhat less supported on the Mac than on Unix
or Windows.
82 83
See the section on <A HREF="#tcltk">building Tcl/Tk Python</A>
below.
84 85 86

<LI> Waste, a TextEdit replacement written by Marco Piovanelli, <A
HREF="mailto:piovanel@kagi.com">&lt;piovanel@kagi.com&gt;</A>.  Python
87 88
was built using version 2.0, which is included in the CodeWarrior
package. You can also obtain it from <A
89
HREF="http://www.merzwaren.com/waste">&lt;http://www.merzwaren.com/waste&gt;</A>
90 91
and various other places.

92 93 94
<LI> Gdbm library for the Mac. Available from Jack's Mac software page at
<A HREF="http://www.cwi.nl/~jack/macsoftware.html">
http://www.cwi.nl/~jack/macsoftware.html</A> and <A HREF="ftp://ftp.cwi.nl/pub/jack/mac">
95
ftp://ftp.cwi.nl/pub/jack/mac</A>. 
96 97 98 99

<LI> JPEG library by the Independent JPEG Group. A version including
Mac projects can be found at Jack's page mentioned above. 
The most recent JPEG library can always be obtained from <A
100
HREF="ftp://ftp.uu.net/graphics/jpeg/">ftp://ftp.uu.net/graphics/jpeg/</A>. 
101

102
<LI> The netpbm/pbmplus, libtiff, zlib and png libraries. The netpbm distribution
103 104 105 106
(which includes libtiff) is generally available on Internet ftp
servers. For Python pbmplus, an older incarnation of netpbm, is
functionally identical to netpbm, since Python only uses the library
and not the complete applications. A distribution with correct
107
projects and library source only is available from, you guessed it, Jack's Mac software
108
page mentioned above. 
109

110 111 112 113
</UL>

<H2>Setting Up</H2>

114
Now that you have collected everything you should start with building
115
the various parts.  If you don't want to fix
116 117
access paths try to set things up as follows:

118 119
<PRE>
Top-level-folder:
Jack Jansen's avatar
Jack Jansen committed
120
	GUSI2
121
	imglibs
122 123 124
		jpeg
		netpbm
			libtiff
125
		zlib
126
		png
127
	gdbm
128
	Python
129 130 131 132 133 134
		Modules
		...
		Mac
			Modules
			Build
			...
135
	Tcl/Tk Folder 8.3.4
136 137
</PRE>

138 139 140
If your setup of the libraries is exactly the same as mine (which is
not very likely, unless you happen to work from the same CVS
repository) you can use the project <code>buildlibs.prj</code> in the
Jack Jansen's avatar
Jack Jansen committed
141
<code>:Mac:Build</code> folder to build all needed libraries in one
142 143 144
fell swoop, otherwise you will have to build the libraries one by
one. <p>

145
First build GUSI, both the normal one and the Carbon variant.
Jack Jansen's avatar
Jack Jansen committed
146
 <p>
147

148
Next, in
Jack Jansen's avatar
Jack Jansen committed
149
<code>libjpeg</code>, <code>pbmplus</code>,
150
<code>zlib</code>, <code>libpng</code>, <code>gdbm</code>,
151
and<code>libtiff</code> you build all projects. Usually the projects are in "mac"
152
subfolders, sometimes they are in the main folder. Tcl/tk is a special
Jack Jansen's avatar
Jack Jansen committed
153
case, see below.
154 155 156

<H2><A NAME="tcltk">Building Tcl/Tk</H2>

157 158 159 160 161 162
Tkinter has been built with Tcl/Tk 8.3.4. Load the Mac source distribution
from the tcl sourceforge site and build it. Build with CW7, but you will
need CW6 to build the MDEF resource (or copy it from a binary
installation). As of this writing the projects are CW6, so they need
massaging to build with CW7, but this is a lot less work than applying
all the workarounds for CW6 that the build instructions give. <P>
Jack Jansen's avatar
Jack Jansen committed
163

164
Note that if you use a different release of Tcl and Tk than the ones
Jack Jansen's avatar
Jack Jansen committed
165
I have used you may have to adapt the Python <code>tkresources.rsrc</code> file.
166
This is easiest done by building <code>Tk8.3.shlb</code> and copying the TEXT, ICON
Jack Jansen's avatar
Jack Jansen committed
167 168
and CRSR resources from it to <code>tkresources.rsrc</code>. This allows
the <code>_tkinter</code> module to work without an installed Tk/Tcl on your
169 170 171
machine. <P>

Also note that the <code>_tkinter.ppc.slb</code> that is normally distributed
172
in the <code>lib-dynload</code> folder is the one from the Imaging extension,
173 174
which has some extra features needed by PIL (and which features should not
hinder normal operation).
175

176 177
</UL>

Jack Jansen's avatar
Jack Jansen committed
178
Build first the Tcl library, then
179 180 181
SimpleTcl (test it by typing <code>ls -l</code> in the window you get)
then the Tk library, then SimpleTk (which can again be tested with
<code>ls -l</code>). If this all worked you are all set to try
182 183 184 185
building Python.

<H2>The organization of the Python source tree</H2>

186 187 188
Time for a short break, while we have a look at the organization of
the Python source tree.  At the top level, we find the following
folders:
189 190 191

<DL>
<DT> Demo
192
<DD> Demo programs that are not Mac-specific. Some of these may not
Jack Jansen's avatar
Jack Jansen committed
193
work.
194 195

<DT> Extensions
196
<DD> Extensions to the interpreter that are not Mac-specific. Contains
Jack Jansen's avatar
Jack Jansen committed
197 198
the <code>img</code>, <code>Imaging</code> and <code>Numerical</code> extensions
in this distribution.
199 200

<DT> Grammar
201 202
<DD> The Python grammar. Included for reference only, you cannot build
the parser on a Mac.
203 204 205 206 207

<DT> Include
<DD> Machine-independent header files.

<DT> Modules
208 209
<DD> Machine-independent optional modules. Not all of these will work
on the Mac.
210

211 212 213 214 215 216
<DT> Lib
<DD> Machine-independent modules in Python.

<DT> Lib:lib-dynload
<DD> This is where the Classic and Carbon dynamically-loaded plugin modules live.

217
<DT> Objects
Jack Jansen's avatar
Jack Jansen committed
218
<DD> Machine-independent code for various object types. Most of these are
219
not really optional: the interpreter will not function without them.
220 221 222 223 224

<DT> Parser
<DD> The Python parser (machine-independent).

<DT> Python
225 226
<DD> The core interpreter. Most files are machine-independent, some
are unix-specific and not used on the Mac.
227 228

<DT> Tools
Jack Jansen's avatar
Jack Jansen committed
229 230 231 232 233 234
<DD> Tools for python developers. Contains <code>modulator</code> which
builds skeleton C extension modules, <code>bgen</code> which generates
complete interface modules from information in C header files and
<code>freeze</code> which is used to turn Python scripts into real
applications (used by MacFreeze and BuildApplication) There are some
readme files, but more documentation is sorely needed.
235

236 237 238 239
</DL>

All the mac-specific stuff lives in the <code>Mac</code> folder:
<DL>
240 241 242 243
<DT> Build
<DD> This is where the project files live and where you build the
libraries, shared libraries, executables and plugin modules. All the
resulting binaries, except for intermedeate results, are deposited in
244
the toplevel folder or the Mac:PlugIns folder (for plugin modules).
245 246

<DT> Compat
Jack Jansen's avatar
Jack Jansen committed
247 248
<DD> Unix-compatability routines. Most of these are not used anymore,
since GUSI provides a rather complete emulation, but you may need
249
these if you are trying to build a non-GUSI python.
250 251 252 253 254 255 256 257

<DT> Demo
<DD> Mac-specific demo programs, some of them annotated.

<DT> Include
<DD> Mac-specific but compiler-independent include files. 

<DT> Lib
258
<DD> Mac-specific standard modules. The <code>Carbon</code> package
259
contains modules specifically needed with various MacOS toolbox
260
interface modules, both for Carbon and classic PPC, despite the name.
261 262

<DT> Modules
263 264
<DD> Mac-specific builtin modules. Theoretically these are all
optional, but some are rather essential (like
265
<code>macosmodule</code>). A lot of these modules are generated with
266 267
<code>bgen</code>, in which case the bgen input files are included so
you can attempt to regenerate them or extend them.
268 269

<DT> MPW
270 271
<DD> MPW-specific files. These have not been used or kept up-to-date
for a long time, so use at your own risk.
272 273

<DT> mwerks
274 275 276 277 278 279 280 281 282 283 284 285
<DD> Mwerks-specific sources and headers. Contains glue code for
Pythons shared-library architecture, a replacement for
<code>malloc</code> and a directory with various projects for building
variations on the Python interpreter. The <code>mwerks_*.h</code>
files here are the option-setting files for the various interpreters
and such, comparable to the unix command-line <code>-D</code> options
to the compiler. Each project uses the correct option file as its
"prefix file" in the "C/C++ language" settings. Disabling optional
modules (for the 68K interpreter), building non-GUSI interpreters and
various other things are accomplished by modifying these files (and
possibly changing the list of files included in the project window, of
course).
286

287 288 289 290 291 292 293
<DT> OSX
<DD> Specific to unix-Python (also known as MachoPython) on OSX, not used
by MacPython.

<DT> OSXResources
<DD> Specific to unix-Python (also known as MachoPython) on OSX, not used
by MacPython.
294

295 296 297 298 299 300 301
<DT> Python
<DD> Mac-specific parts of the core interpreter.

<DT> Resources
<DD> Resource files needed to build the interpreter.

<DT> Scripts
302 303 304
<DD> A collection of various mac-specific Python scripts. Some are
essential, some are useful but few are documented, so you will have to
use your imagination to work them out.
305

306 307 308 309 310 311 312 313
<DT> Tools
<DD> A collection of tools, usually bigger than those in the scripts
folder. The important ones here are the IDE and macfreeze. The IDE is built
with the buildIDE.py script, which puts the resulting applet in the toplevel
folder. Macfreeze is usually invoked through the BuildApplication script,
but for more control over the freezing process you can run the main script here.


314 315 316 317
<DT> Unsupported
<DD> Modules that are not supported any longer but may still work with a little effort.
</DL>

Jack Jansen's avatar
Jack Jansen committed
318
<H2>Building the PPC interpreter</H2>
319
<em>This is different since 2.1. You are best off using the fullbuild.py
320 321
script, see <a href="#fullbuild">below</a>. </em><p>

322 323
First you optionally build the external libraries with buildlibs.prj. Next, 
the projects for
324 325 326 327 328 329 330 331 332 333
interpreter and core library are linked together, so
building the PythonInterpreterClassic and/or PythonInterpreterCarbon target
in <code>PythonInterpreter.prj</code> 
will result in everything being built. The result, however, is an "Application
template", (filetype Atmp). If you don't use fullbuild you can manually
turn either of these into an interpreter by copying it to PythonInterpreter
and setting the filetype to APPL (with ResEdit or some such). <p>

Fullbuild does this for you, and the Atmp files is also how ConfigurePythonCarbon
and ConfigurePythonClassic work their magic. <p>
334 335

For completeness sake here is a breakdown of the projects:
336 337 338

<DL>

339
<DT> PythonCore
340
<DD> The shared library that contains the bulk of the interpreter and
341 342
its resources. It has targets for PythonCore and PythonCoreCarbon.
It is a good idea to immedeately put an alias to this
343 344
shared library in the <code>Extensions</code> folder of your system
folder.  Do exactly that: put an <em>alias</em> there, copying or
345
moving the file will cause you grief later if you rebuild the library and
346 347
forget to copy it to the extensions folder again. The ConfigurePythonXXX applets
will also do this. <br>
348

349
<DT> PythonInterpeter
350
<DD> The interpreter. This is basically a routine to call out to the
351
shared library. Unlike in previous releases the same program is used for
352 353 354 355
creating applets (for which formerly PythonApplet was used). There are 4 targets
in here: two for the classic and carbon templates (which are normally used, and
converted to PythonInterpreter by the ConfigurePython* applets) and two
for PythonInterpreter in it's classic and carbon version.<p>
356

357
<DT> Plugin projects
358 359 360
<DD> Each plugin module has a separate project, and these can be rebuilt on
the fly. Fullbuild (or actually it's little helper genpluginprojects) takes
care of this.
361
</DL>
362

363
After creating the alias to <code>PythonCore</code> you remove any old
364
<code>Python XXXX Preferences</code> file from the <code>Preferences</code> folder
365
(if you had python installed on your system before) and run the interpreter once
366
to create the correct preferences file.  <p>
367

368
Next, you have to build the extension modules.
369
If you don't use fullbuild simply open each project and build it.
370
<p>
371 372

Finally, you must build the standard applets:
373 374 375
<code>EditPythonPrefs</code>, <code>BuildApplet</code>, etc. For the N-th time:
fullbuild does this for you, but you can also manually drag/drop them onto
BuildApplet. <p>
376 377

<BLOCKQUOTE>
378 379
<a name="fullbuild"></a>
The <code>fullbuild</code> script can be used to build
380 381
everything, but you need a fully-functional interpreter before you can
use it (and one that isn't rebuilt in the process: you cannot rebuild
Jack Jansen's avatar
Jack Jansen committed
382 383 384 385
a running program). You could copy the interpreter to a different
place and use that to run fullbuild. The <code>PythonStandSmall.prj</code>
project builds an interpreter that is suited to this, and it can also come
in handy if you need to debug things (which is easier in a static program). <p>
386

387 388
</BLOCKQUOTE>

389
You are all set now, and should read the release notes and
390
<code>ReadMe</code> file from the <code>Mac</code> folder.
391

392
Rebuilding .exp files is no longer needed since CodeWarrior 7.
393

394
<H2><a name="cvs">Using the CVS source archive</a></H2>
395

Jack Jansen's avatar
Jack Jansen committed
396
It is possible (and probably best) to access the Python sources through remote CVS. The
397 398 399 400
advantage of this is that you get the very latest sources, so any bug
fixed or new features will be immedeately available. This is also the
disadvantage, of course: as this is the same tree as is used for
development it may sometimes be a little less stable. <p>
401 402

The CVS client of choice is Alexandre Parenteau's MacCVS. It can be
403 404 405 406 407
obtained through the <a href="http://www.wincvs.org">WinCVS
homepage</a>. MacCVS uses Internet Config to set file types correctly
based on the filename extension. In the maccvs preferences you should
also set (in the "binary files" section) "use mac encoding:
applesingle" and (in the "text files" section) "use ISO latin 1
408 409
conversion". <p>

410 411 412 413 414 415 416
<blockquote>
There is one group of people for whom MacCVS is not the best choice: people with
checkin rights to the Python repository. You will have to use MacCVS Pro
(completely unrelated) from www.maccvs.org, because it has working SSH support.
</blockquote>

It is a good idea to disable Quicktime Exchange in the Quicktime
417 418 419 420
control panel. Quicktime Exchange will magically map some extensions to
filetypes, and this can seriously hinder you if, for instance, <code>.bmp</code>
is not a Windows bitmap file. <p>

421
The Python sources are checked out from the main
Jack Jansen's avatar
Jack Jansen committed
422
Python CVS archive on sourceforge.net, see the <a
423 424
href="http://www.python.org/download/cvs.html">Source access via
CVS</a> page for details. When you check the sources out you will get
425
something like <code>Python:dist:src</code>, and under that the
426 427
<code>Modules</code>, <code>Lib</code>, <code>Mac</code> etc hierarchy. The
<code>src</code> folder can be renamed to <code>Python</code>, and
428 429
is what this document refers to as the "toplevel Python folder". <P>

430 431 432 433 434
The CVS repository does not contain all the projects for the plugin modules,
these are built with <code>fullbuild.py</code> normally. For this reason
it is probably a good idea to first build <code>PythonStandSmall.prj</code>,
which builds a fairly minimal interpreter, and then follow the
<a href="#fullbuild">fullbuild instructions</a>.
435

436 437 438 439 440
<H2>Odds and ends</H2>

Some remarks that I could not fit in elsewhere:

<UL>
441 442 443

<LI> It may be possible to use the <code>PythonCore</code> shared
library to embed Python in another program, if your program can live
444
with using GUSI for I/O. Use PythonCore in stead of your MSL C library
Jack Jansen's avatar
Jack Jansen committed
445
(or, at the very least, link it before the normal C library).
446

447 448 449 450
<LI> <a name="extending"></a>It is possible to build PPC extension
modules without building a complete Python. The binary distribution
installer can optionally install all the needed folders (the develop
option). A template for a dynamic module can be found in
451
<code>xx.prj</code>.
452 453 454 455

<LI> The Python shared library architecture is a variant of the architecture
described as "application with shared libraries and dropins" in the MetroWerks
"Targeting MacOS" documentation. The Python Application and applet-template use
456 457 458 459
the <code>MSL AppRuntime.Lib</code> runtime library (with properly set CFM
initialization and termination routines). PythonCore uses <code>MSL Runtime.Lib</code>,
which is really intended for standalone programs but which we fool into working by
providing a dummy main program.
460 461
It is linked statically into PythonCore (and exported to the applications and plugins)
so we do not have to distribute yet another shared library. Plugin modules use
462 463
<code>MSL ShlibRuntime.Lib</code> (not the dropin runtime: modules are never unloaded)
and obtain the rest from PythonCore. PythonCore uses a
464
non-standard initialization entry point, <code>__initialize_with_resources</code>, to
465 466
be able to obtain resources from the library file later on. Plugins can do the same
(_tkinter does) or use the standard <code>__initialize</code> entry point.
467 468


469
</UL>
470 471
</BODY>
</HTML>