Guido van Rossum | d849a48 | 1994-08-20 21:55:48 +0000 | [diff] [blame^] | 1 | BUILDING PYTHON 1.1 FOR THE MACINTOSH |
| 2 | ************************************* |
| 3 | |
| 4 | Python can be built on the Mac using either THINK C 6.0 or MPW 3.2. |
| 5 | In the past it has been compiled with earlier versions of these |
| 6 | compilers, but no guarantees are made that the source is still |
| 7 | compatible with those versions. Likewise, new compiler versions may |
| 8 | effectively change the language accepted (or the library!) and thus |
| 9 | cause problems. |
| 10 | |
| 11 | [[MPW version and procedure must still be checked]] |
| 12 | |
| 13 | |
| 14 | 1. Using Think C 6.0 |
| 15 | ==================== |
| 16 | |
| 17 | 1.1 The directory structure |
| 18 | --------------------------- |
| 19 | |
| 20 | I duplicate the UNIX directory structure from the distribution. The |
| 21 | subdirectories needed to compile are: Mac, Include, Parser, Python, |
| 22 | Objects, Modules. (Don't bother with Grammar and the parser |
| 23 | generator, nor with the Doc subdirectory.) |
| 24 | |
| 25 | For running and testing, you also need Lib and its subdirectories test |
| 26 | and stdwin. You could also copy some things from the Demo/stdwin |
| 27 | directory (unfortunately most other demos are UNIX specific and even |
| 28 | many stdwin demos are). |
| 29 | |
| 30 | Make sure there is no config.c file in the Modules subdirectory (if |
| 31 | you copy from a directory where you have done a UNIX build this might |
| 32 | occur). Also don't use the config.h generated on UNIX. |
| 33 | |
| 34 | 1.2 The project file |
| 35 | -------------------- |
| 36 | |
| 37 | I put all source files in one project, which I place in the parent |
| 38 | directory of the source directories. |
| 39 | |
| 40 | 1.2.1 Project type |
| 41 | |
| 42 | (This is the Set Project Type... dialog in the Project menu.) |
| 43 | |
| 44 | Set the creator to PYTH; turn on "far data"; leave "far code" and |
| 45 | "separate strs" unchecked (they just serve to bloat the application). |
| 46 | A partition size of 1000K should be enough to run the standard test |
| 47 | suite (which requires a lot of memory because it stress tests the |
| 48 | parser quite a bit) and most demos or medium-size applications. The |
| 49 | interpreter will do basic things in as little at 500K but this may |
| 50 | prevent parsing larger modules. |
| 51 | |
| 52 | 1.2.2 Compiler options |
| 53 | |
| 54 | (This is the Options -> THINK C ... dialog in the Edit menu.) |
| 55 | |
| 56 | - Start with Factory Settings. |
| 57 | |
| 58 | - In the Prefix, remove #include <MacHeaders> and add |
| 59 | #define HAVE_CONFIG_H |
| 60 | |
| 61 | - Choose any optimizer and debugger settings you like. - You |
| 62 | can choose 4-byte ints if you want. This requires that you |
| 63 | rebuild the ANSI and unix libraries with 4-bytes ints as well |
| 64 | (better make copies with names like ANSI 32 bit). With 4-byte |
| 65 | ints the interpreter is marginally bigger and somewhat (~10%) |
| 66 | slower, but Python programs can use strings and lists with |
| 67 | more than 32000 items (with 2-byte ints these can cause |
| 68 | crashes). The range of Python integers is not affected (these |
| 69 | are always represented as longs). |
| 70 | |
| 71 | 1.2.3 Files to add |
| 72 | |
| 73 | (This is the Add Files... dialog in the Source menu.) |
| 74 | |
| 75 | The following source files must be added to the project. I use a |
| 76 | separate segment for each begin letter -- this avoids segment |
| 77 | overflow, except for 'c', where you have to put either ceval.c or |
| 78 | compile.c in a separate segment. You could also group them by |
| 79 | subdirectory or function, but you may still have to split segments |
| 80 | arbitrarily because of the 32000 bytes restriction. |
| 81 | |
| 82 | - From Mac: all .c files except fopenRF.c [[which shouldn't even |
| 83 | be there]]. |
| 84 | |
| 85 | - From Parser: acceler.c, grammar1.c, myreadline.c, node.c, |
| 86 | parser.c, parsetok.c, tokenizer.c. |
| 87 | |
| 88 | - From Python: bltinmodule.c, ceval.c, cgensupport.c, |
| 89 | compile.c, errors.c, getopt.c, graminit.c, import.c, |
| 90 | marshal.c, modsupport.c, mystrtoul.c, pythonmain.c, |
| 91 | pythonrun.c, structmember.c, sysmodule.c, traceback.c |
| 92 | (i.e. all .c files except dup2.c, fmod.c, frozenmain.c, |
| 93 | getcwd.c, getmtime.c, memmove.c, sigcheck.c, strerror.c, |
| 94 | strtod.c, thread.c) |
| 95 | |
| 96 | - From Objects: all .c files except xxobject.c. |
| 97 | |
| 98 | - From Modules: all the modules listed in config.c (in the Mac |
| 99 | subdirectory) in the initializer for inittab[], before |
| 100 | "ADDMODULE MARKER 2". Also add md5c.c if you add md5module.c, |
| 101 | and regexpr.c if you add regexmodule.c. (You'll find |
| 102 | macmodule.c in the Mac subdirectory, so it should already have |
| 103 | been added in a previous step.) Note that for most modules, |
| 104 | the source file is called <name>module.c, but for a few long |
| 105 | module names it is just <module>.c. - If you don't add |
| 106 | signalmodule.c, you must add intrcheck.c from Parser and |
| 107 | sigcheck.c from Python. |
| 108 | |
| 109 | The following THINK C libraries must be added: from Standard |
| 110 | Libraries, ANSI and unix; from Mac Libraries, MacTraps. I put each |
| 111 | library in a separate segment. Also see my earlier remark on 4-byte |
| 112 | ints. |
| 113 | |
| 114 | 1.3 Living without STDWIN |
| 115 | ------------------------- |
| 116 | |
| 117 | Although STDWIN is really neat on the Mac, it's easier to begin |
| 118 | building Python without it, so you can concentrate on the Python |
| 119 | build. To this end, you have to comment out the lines defining the |
| 120 | symbol USE_STDWIN in macmain.c and config.c. |
| 121 | |
| 122 | 1.4 Adding STDWIN |
| 123 | ----------------- |
| 124 | |
| 125 | STDWIN is built in two separate projects: stdwin.pi contains the core |
| 126 | STDWIN implementation from Ports/mac, textedit.pi contains the files |
| 127 | from Packs/textedit. Use the same compiler options as for Python and |
| 128 | the same general source setup (in a sister directory of the toplevel |
| 129 | Python directory). Put all sources in the same segment. To |
| 130 | stdwin.pi, also add Tools/strdup.c and Gen/wtextbreak.c. |
| 131 | |
| 132 | The two projects can now be added as libraries to the Python project, |
| 133 | and the two lines commented out to live without STDWIN should be |
| 134 | reinstated. |
| 135 | |
| 136 | Note that stdwinmodule.c contains an #include statement that |
| 137 | references "stdwin.h" by relative path name -- if the stdwin toplevel |
| 138 | directory is not a sibling of the python toplevel directory, you may |
| 139 | have to adjust the number of colons in the pathname. |
| 140 | |
| 141 | 1.5 Resources |
| 142 | ------------- |
| 143 | |
| 144 | Since I created them with ResEdit I have no text source of the |
| 145 | resources needed to give the application an icon etc... You can copy |
| 146 | the size, bundle, file reference and icon resources from the |
| 147 | distributed Python application with ResEdit. THINK C automatically |
| 148 | copies resources into the application file from a file |
| 149 | <projectname>.rsrc. |
| 150 | |
| 151 | |
| 152 | 2. Using MPW |
| 153 | ============ |
| 154 | |
| 155 | See the subdirectory MPW. I haven't tried this recently. You're |
| 156 | supposed to merge the directory tree found here with the UNIX source |
| 157 | tree. I think this is intended for use with MPW 3.2. The dynload |
| 158 | stuff in not recommended. |
| 159 | |
| 160 | |
| 161 | --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl> |
| 162 | <URL:http://www.cwi.nl/cwi/people/Guido.van.Rossum.html> |