blob: 036ff91b9897bada84a1a1216a36eac0cfeced71 [file] [log] [blame]
Jack Jansen8f2d8021996-08-05 15:34:45 +00001<HTML>
2<HEAD>
3<TITLE>Building Mac Python from source</TITLE>
4</HEAD>
5<BODY>
6<H1>Building Mac Python from source</H1>
7<HR>
Jack Jansen8f2d8021996-08-05 15:34:45 +00008
Jack Jansen4c1e56c1996-08-06 16:16:20 +00009This document explains how to build MacPython from source. This is
10necessary if you want to write extension modules for 68K Python, and
11currently also probably the easiest way to build PPC extension
12modules. Building Python is not something to be undertaken lightly,
13the process is not very streamlined so you need a reasonable working
14knowledge of the CodeWarrior development environment, a good net
15connection and probably quite some time too. <p>
Jack Jansen8f2d8021996-08-05 15:34:45 +000016
Jack Jansen4c1e56c1996-08-06 16:16:20 +000017The information density in this file is high, so you should probably
18print it and read it at your leasure. Most things are explained only
19once (and probably in the wrong place:-). <p>
20
21I am very interested in feedback on this document, contact me at <A
22HREF="mailto:jack@cwi.nl">&lt;jack@cwi.nl&gt;</A> or send your
23comments to the <A
24HREF="http://www.python.org/sigs/pythonmac-sig/">Mac Python Special
25Interest Group</A>.
Jack Jansen8f2d8021996-08-05 15:34:45 +000026
27<H2>What you need.</H2>
28
29The following things you definitely need:
30
31<UL>
Jack Jansen8f2d8021996-08-05 15:34:45 +000032
Jack Jansen4c1e56c1996-08-06 16:16:20 +000033<LI> You need a MacPython source distribution, of course. You can
34obtain one from <A
35HREF="ftp://ftp.cwi.nl/pub/jack/python/mac">ftp://ftp.cwi.nl/pub/jack/python/mac</A>,
36and possibly also from the standard <A
37HREF="ftp://ftp.python.org/pub/python/mac">python.org ftp
38site</A>. Everything you need is also included in the standard Python
39source distribution, but the organization is different. Look in
40directory <code>Mac/mwerks/projects</code> for the project files and
41related stuff.
Jack Jansen8f2d8021996-08-05 15:34:45 +000042
Jack Jansen4c1e56c1996-08-06 16:16:20 +000043<LI> You need MetroWerks CodeWarrior. The current distribution has
44been built with version 9 of CodeWarrior. Ordering information is
45available on the <A HREF="http://www.metrowerks.com/">MetroWerks
46homepage</A>. You might still be able to build Python with MPW or
47Think/Symantec C but you are basically on your own.
48
49<LI> You need GUSI, the Grand Unified Socket Interface, by Matthias
50Neeracher. The current distribution has been built with CWGUSI 1.7.2,
51obtainable from <A
52HREF="ftp://ftp.switch.ch/software/mac/src/mw_c">ftp://ftp.switch.ch/software/mac/src/mw_c</A>.
53It is possible to build a non-GUSI Python, see below.
54
Jack Jansen8f2d8021996-08-05 15:34:45 +000055</UL>
56
Jack Jansen4c1e56c1996-08-06 16:16:20 +000057<A NAME="optional">The MacPython project files are configured to
58include a plethora of optional modules</A>, and these modules need a
59number extra packages. To use the project files as-is you have to
60download these packages too. PPC Python has all such modules as
61dynamically loaded modules, so if you don't need a certain package it
62suffices to just refrain from builing the extension module. For 68K
63Python things are a bit more complicated: you have to edit the
64interpreter project file to remove the reference to the module (and
65the libraries it uses). Here are the locations for the various things
66you need:
Jack Jansen8f2d8021996-08-05 15:34:45 +000067
68<UL>
Jack Jansen8f2d8021996-08-05 15:34:45 +000069
Jack Jansen4c1e56c1996-08-06 16:16:20 +000070<LI> Tcl and Tk can be obtained from <A
71HREF="ftp://ftp.smli.com/pub/tcl/mac/">ftp://ftp.smli.com/pub/tcl/mac/</A>.
72The current distributions, Tcl 7.5p1 and Tk 4.1p1 need a bit of work,
73see the section on <A HREF="#tcltk">building Tcl/Tk Python</A>
74below. Get the "full source" distribution, which includes MoreFiles.
Jack Jansen8f2d8021996-08-05 15:34:45 +000075
Jack Jansen4c1e56c1996-08-06 16:16:20 +000076<LI> Waste, a TextEdit replacement written by Marco Piovanelli, <A
77HREF="mailto:piovanel@kagi.com">&lt;piovanel@kagi.com&gt;</A>. Python
78was built using version 1.2, which you can obtain from <A
79HREF="ftp://rhino.harvard.edu/pub/dan/WASTE">&lt;ftp://rhino.harvard.edu/pub/dan/WASTE&gt;</A>
80and various other places.
Jack Jansen8f2d8021996-08-05 15:34:45 +000081
Jack Jansen4c1e56c1996-08-06 16:16:20 +000082<LI> JPEG library by the Independent JPEG Group. Python is still built
83using an archaic version of the library, version 4. It can be obtained
84from the <A HREF="ftp://ftp.cwi.nl/pub/jack/python/mac">
85ftp://ftp.cwi.nl/pub/jack/python/mac</A> directory, complete with CW8
86projects. If someone manages to build Python with the version 6
87library I would be grateful if they sent me the changes needed. The
88most recent JPEG library can always be obtained from <A
89HREF="ftp://ftp.uu.net/graphics/jpeg/">ftp://ftp.uu.net/graphics/jpeg/</A>.
90
91<LI> The netpbm/pbmplus and libtiff libraries. The netpbm distribution
92(which includes libtiff) is generally available on Internet ftp
93servers. For Python pbmplus, an older incarnation of netpbm, is
94functionally identical to netpbm, since Python only uses the library
95and not the complete applications. A distribution with correct
96projects and library source only is available from, you guessed it, <A
97HREF="ftp://ftp.cwi.nl/pub/jack/python/mac">ftp://ftp.cwi.nl/pub/jack/python/mac</A>.
98
Jack Jansen8f2d8021996-08-05 15:34:45 +000099</UL>
100
101<H2>Setting Up</H2>
102
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000103Now that you have collected everything you should start with building
104the various parts. Everything is independent, with the single
105exception that Tcl and Tk depend on CWGUSI. If you don't want to fix
106access paths try to set things up as follows:
107
Jack Jansen8f2d8021996-08-05 15:34:45 +0000108<PRE>
109Top-level-folder:
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000110 CWGUSI
Jack Jansen8f2d8021996-08-05 15:34:45 +0000111 imglibs
112 libjpeg
113 pbmplus
114 libtiff
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000115 MoreFiles 1.4.2 (not needed by Python, only by tcl/tk)
Jack Jansen8f2d8021996-08-05 15:34:45 +0000116 Python
117 Tcl 7.5
118 Tk 4.1
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000119 Waste 1.2 distribution (if you want waste)
Jack Jansen8f2d8021996-08-05 15:34:45 +0000120</PRE>
121
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000122Now build all the libraries. In <code>CWGUSI</code> you build the
123projects <code>GUSI.68K.µ</code> and <code>GUSI.PPC.µ</code>, in
124<code>MoreFiles</code>, <code>libjpeg</code>, <code>pbmplus</code>
125and<code>libtiff</code> you build all projects. Tcl/tk is a special
126case, see below. Of course, if you are only interested in 68K you can
127skip building the PPC libraries and vice versa.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000128
129<H2><A NAME="tcltk">Building Tcl/Tk</H2>
130
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000131You need to make a minor organizational change to the Tcl/Tk
132distribution. The current instructions are for the
133<code>tcl7.5.1</code> and <code>tk4.1.1</code> distribution:
134
Jack Jansen8f2d8021996-08-05 15:34:45 +0000135<UL>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000136
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000137<LI> Rename the <code>compat</code> folders to <code>(compat)</code>
138in both the Tcl and Tk folders.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000139
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000140<LI> In the Tcl folder, move <code>strncasecmp.c</code> and
141<code>tclErrno.h</code> from <code>(compat)</code> to the main Tcl
142folder.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000143
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000144<LI> Fix <code>dnr.c</code> as provided by MetroWerks by inserting
145<pre><code> #pragma ANSI_strict off </code></pre> at the
146beginning. The tcl library is built with strict ANSI on, and this file
147uses C++ style comments.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000148
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000149<LI> If you want to build <code>SimpleTcl</code> and
150<code>SimpleTk</code> you will probably have to remove the references
151to <code>libmoto</code> from the project.
152
153<LI> You are <EM>strongly</EM> advised to add a line
Jack Jansen8f2d8021996-08-05 15:34:45 +0000154<pre><code>
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000155#define USE_TCLALLOC 1
Jack Jansen8f2d8021996-08-05 15:34:45 +0000156</code></pre>
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000157somewhere at the beginning of <code>MW_TclHeader.pch</code>.
158As distributed, tcl and tk assume that malloc calls always succeed and
159use the resulting pointer without checking for <code>NULL</code>
160values. Needless to say, this wreaks havoc on a Macintosh.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000161
Jack Jansen8f2d8021996-08-05 15:34:45 +0000162</UL>
163
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000164Build first the MoreFiles library, then the Tcl library, then
165SimpleTcl (test it by typing <code>ls -l</code> in the window you get)
166then the Tk library, then SimpleTk (which can again be tested with
167<code>ls -l</code>). If this all worked you are all set to try
Jack Jansen8f2d8021996-08-05 15:34:45 +0000168building Python.
169
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000170<H2>Building Waste</H2>
171
172You do not need to build the Waste libraries, as Python includes the
173source modules themselves. You have to make one modification,
174though. In file <code>ICCFMGlue.c</code> in folder <code>Minimal IC
175APIs</code>, add the following lines:
176
177<blockquote><pre><code>
178#include <Gestalt.h>
179#include <Errors.h>
180</code></pre></blockquote>
181
Jack Jansen8f2d8021996-08-05 15:34:45 +0000182<H2>The organization of the Python source tree</H2>
183
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000184Time for a short break, while we have a look at the organization of
185the Python source tree. At the top level, we find the following
186folders:
Jack Jansen8f2d8021996-08-05 15:34:45 +0000187
188<DL>
189<DT> build.mac68k.stand
190<DD> This is where you will build 68K interpreters.
191
192<DT> build.macppc.shared
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000193<DD> This is where you build the PPC shared library, interpreter and
194applet framework.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000195
196<DT> build.macppc.stand
197<DD> This is where you build a nonshared PPC interpreter (optional).
198
199<DT> Demo
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000200<DD> Demo programs that are not Mac-specific. Some of these may not
201work, the file <code>README-Mac</code> has some details.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000202
203<DT> Extensions
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000204<DD> Extensions to the interpreter that are not Mac-specific. Contains
205only the <code>img</code> extension in this distribution. Extensions
206are <em>not</em> built here, as they are on Unix, but incorporated in
207the core interpreter or built as plugin modules.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000208
209<DT> Grammar
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000210<DD> The Python grammar. Included for reference only, you cannot build
211the parser on a Mac.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000212
213<DT> Include
214<DD> Machine-independent header files.
215
216<DT> Modules
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000217<DD> Machine-independent optional modules. Not all of these will work
218on the Mac.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000219
220<DT> Objects
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000221<DD> Machine-independent code for various objects. Most of these are
222not really optional: the interpreter will not function without them.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000223
224<DT> Parser
225<DD> The Python parser (machine-independent).
226
227<DT> PlugIns
228<DD> This is where you build the PPC dynamically-loaded plugin modules.
229
230<DT> Python
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000231<DD> The core interpreter. Most files are machine-independent, some
232are unix-specific and not used on the Mac.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000233
234<DT> Tools
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000235<DD> Tools for python developers. Contains <code>modulator</code>
236which builds skeleton C extension modules and <code>bgen</code> which
237generates complete interface modules from information in C header
238files. There are some readme files, but more documentation is sorely
239needed.
240
Jack Jansen8f2d8021996-08-05 15:34:45 +0000241</DL>
242
243All the mac-specific stuff lives in the <code>Mac</code> folder:
244<DL>
245
246<DT> Compat
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000247<DD> Unix-compatability routines. Some of these are not used anymore,
248since CWGUSI provides a rather complete emulation, but you may need
249these if you are trying to build a non-GUSI python.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000250
251<DT> Demo
252<DD> Mac-specific demo programs, some of them annotated.
253
254<DT> Include
255<DD> Mac-specific but compiler-independent include files.
256
257<DT> Lib
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000258<DD> Mac-specific standard modules. The <code>toolbox</code> folder
259contains modules specifically needed with various MacOS toolbox
260interface modules.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000261
262<DT> Modules
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000263<DD> Mac-specific builtin modules. Theoretically these are all
264optional, but some are rather essential (like
265<code>macmodule</code>). A lot of these modules are generated with
266<code>bgen</code>, in which case the bgen input files are included so
267you can attempt to regenerate them or extend them.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000268
269<DT> MPW
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000270<DD> MPW-specific files. These have not been used or kept up-to-date
271for a long time, so use at your own risk.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000272
273<DT> mwerks
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000274<DD> Mwerks-specific sources and headers. Contains glue code for
275Pythons shared-library architecture, a replacement for
276<code>malloc</code> and a directory with various projects for building
277variations on the Python interpreter. The <code>mwerks_*.h</code>
278files here are the option-setting files for the various interpreters
279and such, comparable to the unix command-line <code>-D</code> options
280to the compiler. Each project uses the correct option file as its
281"prefix file" in the "C/C++ language" settings. Disabling optional
282modules (for the 68K interpreter), building non-GUSI interpreters and
283various other things are accomplished by modifying these files (and
284possibly changing the list of files included in the project window, of
285course).
Jack Jansen8f2d8021996-08-05 15:34:45 +0000286
287<DT> Python
288<DD> Mac-specific parts of the core interpreter.
289
290<DT> Resources
291<DD> Resource files needed to build the interpreter.
292
293<DT> Scripts
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000294<DD> A collection of various mac-specific Python scripts. Some are
295essential, some are useful but few are documented, so you will have to
296use your imagination to work them out.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000297
298<DT> Unsupported
299<DD> Modules that are not supported any longer but may still work with a little effort.
300</DL>
301
302<H2>Building the 68K interpreter</H2>
303
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000304If you have all the optional libraries mentioned <A
305HREF="#optional">above</A> loaded buildin Python for 68K macs is a
306breeze: open the project in the folder <code>build.mac68k.stand</code>
307and build it. Do <em>not</em> run it yet, this will possibly result
308in a garbled preferences file. <p>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000309
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000310First remove the <code>Python preferences</code> file from your
311preference folder, only if you had an older version of Python
312installed. (this is also what you do if you did not heed the last
313sentence of the preceeding paragraph). Next, move the interpreter to
314the main Python folder (up one level) and run it there. This will
315create a correct initial preferences file. You are now all set, and
316your tree should be completely compatible with a binary-only
317distribution. Read the release notes
318(<code>Relnotes-somethingorother</code>) and
319<code>ReadMeOrSuffer</code> in the <code>Mac</code> folder.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000320
321<H2>Building the PPC interpreter</H2>
322
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000323First you build the interpreter, core library and applet skeleton in
324folder <code>build.macppc.stand</code>. The order to build things is
325the following:
Jack Jansen8f2d8021996-08-05 15:34:45 +0000326
327<DL>
328<DT> PythonCoreRuntime
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000329<DD> A modified version of the MetroWerks runtime library that is
330suitable for Pythons' shared library architecture. The sources all
331come from the MW distribution.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000332
333<DT> PythonCore
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000334<DD> The shared library that contains the bulk of the interpreter and
335its resources. It is a good idea to immedeately put an alias to this
336shared library in the <code>Extensions</code> folder of your system
337folder. Do exactly that: put an <em>alias</em> there, copying or
338moving the file will cause you grief later.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000339
340<DT> PythonPPC
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000341<DD> The interpreter. This is basically a routine to call out to the
342shared library. Because of the organization of GUSI it also contains
343the Gusi settings resource (together with a ResEdit template, so you
344can change the gusi settings should you feel like doing so). Do
345<em>not</em> run it yet, this will possibly result in a garbled
346preferences file. <p>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000347
348<DT> PythonApplet
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000349<DD> The applet skeleton application. Very similar to
350<code>PythonPPC</code>, but it calls to a different entrypoint in the
351core library. The <code>mkapplet</code> script will copy this complete
352file, and add a <code>'PYC '</code> with the module to generate an
353applet. <p>
354
Jack Jansen8f2d8021996-08-05 15:34:45 +0000355</DL>
356
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000357After creating the alias to <code>PythonCore</code> you should move
358<code>PythonPPC</code> to the main Python folder. Next you remove any
359old <code>Python Preferences</code> file from the
360<code>Preferences</code> folder (if you had python installed on your
361system before) and run the interpreter once to create the correct
362preferences file. You should also make an alias to
363<code>PythonApplet</code> in the main Python folder. (again: making an
364alias is preferrable to copying or moving the file, since this will
365cause the correct file to be used if you ever rebuild
366PythonApplet). <p>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000367
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000368Next, you have to build the extension modules in the
369<code>PlugIns</code> folder. Open each project and build it. After all
370the dynamically loaded modules are built you have to create a number
371of aliases: some modules live together in a single dynamic
372library. Copy or move the <code>MkPluginAliases.py</code> script from
373<code>Mac:scripts</code> to the main python folder and run it. <p>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000374
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000375Finally, you must build the standard applets:
376<code>EditPythonPrefs</code>, <code>mkapplet</code>, etc. This is
377easiest done with the <code>fullbuild</code> script from
378<code>Mac:scripts</code>. Answer <em>no</em> to all questions except
379when it asks whether to build the applets. <p>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000380
381<BLOCKQUOTE>
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000382Actually, the <code>fullbuild</code> script can be used to build
383everything, but you need a fully-functional interpreter before you can
384use it (and one that isn't rebuilt in the process: you cannot rebuild
385a running program). You could copy the 68K interpreter to a different
386place and use that to run fullbuild, or use the standalone PPC python
387for this. I tend to keep a standalone interpreter in a safe place for
388this use only.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000389</BLOCKQUOTE>
390
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000391You are all set now, and should read the release notes and
392<code>ReadMeOrSuffer</code> file from the <code>Mac</code> folder.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000393
394<H2>Odds and ends</H2>
395
396Some remarks that I could not fit in elsewhere:
397
398<UL>
Jack Jansen8f2d8021996-08-05 15:34:45 +0000399
Jack Jansen4c1e56c1996-08-06 16:16:20 +0000400<LI> It may be possible to use the <code>PythonCore</code> shared
401library to embed Python in another program, if your program can live
402with using GUSI for I/O. Use PythonCore in stead of your C library
403(or, at the very least, link it before the normal C library). Let me
404know whether this works.
405
406<LI> It is possible to build PPC extension modules without building a
407complete Python. Take the binary distribution, add folders
408<code>Include</code>, <code>Mac:Include</code> and
409<code>Mac:mwerks</code> from the source distribution and you should be
410all set. A template for a dynamic module can be found in
411<code>xxmodule.µ</code>.
Jack Jansen8f2d8021996-08-05 15:34:45 +0000412
413
414<UL>
415</BODY>
416</HTML>