| 1 | Building a Python Mac OS X distribution
 | 
|---|
| 2 | =======================================
 | 
|---|
| 3 | 
 | 
|---|
| 4 | The ``build-install.py`` script creates Python distributions, including
 | 
|---|
| 5 | certain third-party libraries as necessary.  It builds a complete 
 | 
|---|
| 6 | framework-based Python out-of-tree, installs it in a funny place with 
 | 
|---|
| 7 | $DESTROOT, massages that installation to remove .pyc files and such, creates 
 | 
|---|
| 8 | an Installer package from the installation plus other files in ``resources`` 
 | 
|---|
| 9 | and ``scripts`` and placed that on a ``.dmg`` disk image.
 | 
|---|
| 10 | 
 | 
|---|
| 11 | For Python 2.7.x and 3.2.x, PSF practice is to build two installer variants
 | 
|---|
| 12 | for each release.
 | 
|---|
| 13 | 
 | 
|---|
| 14 | 1.  32-bit-only, i386 and PPC universal, capable on running on all machines
 | 
|---|
| 15 |     supported by Mac OS X 10.3.9 through (at least) 10.8::
 | 
|---|
| 16 | 
 | 
|---|
| 17 |         /usr/bin/python build-installer.py \
 | 
|---|
| 18 |             --sdk-path=/Developer/SDKs/MacOSX10.4u.sdk \
 | 
|---|
| 19 |             --universal-archs=32-bit \
 | 
|---|
| 20 |             --dep-target=10.3 
 | 
|---|
| 21 | 
 | 
|---|
| 22 |     - builds the following third-party libraries
 | 
|---|
| 23 | 
 | 
|---|
| 24 |         * Bzip2
 | 
|---|
| 25 |         * NCurses
 | 
|---|
| 26 |         * GNU Readline (GPL)
 | 
|---|
| 27 |         * SQLite 3.7.13
 | 
|---|
| 28 |         * Zlib 1.2.3
 | 
|---|
| 29 |         * Oracle Sleepycat DB 4.8 (Python 2.x only)
 | 
|---|
| 30 | 
 | 
|---|
| 31 |     - requires ActiveState ``Tcl/Tk 8.4`` (currently 8.4.19) to be installed for building
 | 
|---|
| 32 | 
 | 
|---|
| 33 |     - recommended build environment:
 | 
|---|
| 34 |         
 | 
|---|
| 35 |         * Mac OS X 10.5.8 PPC or Intel
 | 
|---|
| 36 |         * Xcode 3.1.4
 | 
|---|
| 37 |         * ``MacOSX10.4u`` SDK (later SDKs do not support PPC G3 processors)
 | 
|---|
| 38 |         * ``MACOSX_DEPLOYMENT_TARGET=10.3``
 | 
|---|
| 39 |         * Apple ``gcc-4.0``
 | 
|---|
| 40 |         * system Python 2.5 for documentation build with Sphinx
 | 
|---|
| 41 | 
 | 
|---|
| 42 |     - alternate build environments:
 | 
|---|
| 43 | 
 | 
|---|
| 44 |         * Mac OS X 10.6.8 with Xcode 3.2.6
 | 
|---|
| 45 |             - need to change ``/System/Library/Frameworks/{Tcl,Tk}.framework/Version/Current`` to ``8.4``
 | 
|---|
| 46 |         * Note Xcode 4.* does not support building for PPC so cannot be used for this build
 | 
|---|
| 47 | 
 | 
|---|
| 48 | 
 | 
|---|
| 49 | 2.  64-bit / 32-bit, x86_64 and i386 universal, for OS X 10.6 (and later)::
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         /usr/bin/python build-installer.py \
 | 
|---|
| 52 |             --sdk-path=/Developer/SDKs/MacOSX10.6.sdk \
 | 
|---|
| 53 |             --universal-archs=intel \
 | 
|---|
| 54 |             --dep-target=10.6
 | 
|---|
| 55 | 
 | 
|---|
| 56 |     - builds the following third-party libraries
 | 
|---|
| 57 | 
 | 
|---|
| 58 |         * NCurses 5.9 (http://bugs.python.org/issue15037)
 | 
|---|
| 59 |         * SQLite 3.7.13
 | 
|---|
| 60 | 
 | 
|---|
| 61 |     - uses system-supplied versions of third-party libraries
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         * readline module links with Apple BSD editline (libedit)
 | 
|---|
| 64 |         * builds Oracle Sleepycat DB 4.8 (Python 2.x only)
 | 
|---|
| 65 | 
 | 
|---|
| 66 |     - requires ActiveState Tcl/Tk 8.5.9 (or later) to be installed for building
 | 
|---|
| 67 | 
 | 
|---|
| 68 |     - recommended build environment:
 | 
|---|
| 69 | 
 | 
|---|
| 70 |         * Mac OS X 10.6.8 (or later)
 | 
|---|
| 71 |         * Xcode 3.2.6
 | 
|---|
| 72 |         * ``MacOSX10.6`` SDK
 | 
|---|
| 73 |         * ``MACOSX_DEPLOYMENT_TARGET=10.6``
 | 
|---|
| 74 |         * Apple ``gcc-4.2``
 | 
|---|
| 75 |         * system Python 2.6 for documentation build with Sphinx
 | 
|---|
| 76 | 
 | 
|---|
| 77 |     - alternate build environments:
 | 
|---|
| 78 | 
 | 
|---|
| 79 |         * none.  Xcode 4.x currently supplies two C compilers.
 | 
|---|
| 80 |           ``llvm-gcc-4.2.1`` has been found to miscompile Python 3.3.x and
 | 
|---|
| 81 |           produce a non-functional Python executable.  As it appears to be
 | 
|---|
| 82 |           considered a migration aid by Apple and is not likely to be fixed,
 | 
|---|
| 83 |           its use should be avoided.  The other compiler, ``clang``, has been
 | 
|---|
| 84 |           undergoing rapid development.  While it appears to have become
 | 
|---|
| 85 |           production-ready in the most recent Xcode 4 releases (Xcode 4.5.x
 | 
|---|
| 86 |           as of this writing), there are still some open issues when
 | 
|---|
| 87 |           building Python and there has not yet been the level of exposure in
 | 
|---|
| 88 |           production environments that the Xcode 3 gcc-4.2 compiler has had.
 | 
|---|
| 89 | 
 | 
|---|
| 90 | 
 | 
|---|
| 91 | General Prerequisites
 | 
|---|
| 92 | ---------------------
 | 
|---|
| 93 | 
 | 
|---|
| 94 | * No Fink (in ``/sw``) or MacPorts (in ``/opt/local``) or other local
 | 
|---|
| 95 |   libraries or utilities (in ``/usr/local``) as they could
 | 
|---|
| 96 |   interfere with the build.
 | 
|---|
| 97 | 
 | 
|---|
| 98 | * The documentation for the release is built using Sphinx
 | 
|---|
| 99 |   because it is included in the installer.
 | 
|---|
| 100 | 
 | 
|---|
| 101 | * It is safest to start each variant build with an empty source directory
 | 
|---|
| 102 |   populated with a fresh copy of the untarred source.
 | 
|---|
| 103 | 
 | 
|---|
| 104 | * It is recommended that you remove any existing installed version of the
 | 
|---|
| 105 |   Python being built::
 | 
|---|
| 106 | 
 | 
|---|
| 107 |       sudo rm -rf /Library/Frameworks/Python.framework/Versions/n.n
 | 
|---|
| 108 | 
 | 
|---|
| 109 | 
 | 
|---|
| 110 | The Recipe
 | 
|---|
| 111 | ----------
 | 
|---|
| 112 | 
 | 
|---|
| 113 | Here are the steps you need to follow to build a Python installer:
 | 
|---|
| 114 | 
 | 
|---|
| 115 | * Run ``build-installer.py``. Optionally you can pass a number of arguments
 | 
|---|
| 116 |   to specify locations of various files. Please see the top of
 | 
|---|
| 117 |   ``build-installer.py`` for its usage.
 | 
|---|
| 118 | 
 | 
|---|
| 119 |   Running this script takes some time, it will not only build Python itself
 | 
|---|
| 120 |   but also some 3th-party libraries that are needed for extensions.
 | 
|---|
| 121 | 
 | 
|---|
| 122 | * When done the script will tell you where the DMG image is (by default
 | 
|---|
| 123 |   somewhere in ``/tmp/_py``).
 | 
|---|
| 124 | 
 | 
|---|
| 125 | Building other universal installers
 | 
|---|
| 126 | ...................................
 | 
|---|
| 127 | 
 | 
|---|
| 128 | It is also possible to build a 4-way universal installer that runs on 
 | 
|---|
| 129 | OS X 10.5 Leopard or later::
 | 
|---|
| 130 | 
 | 
|---|
| 131 |     /usr/bin/python /build-installer.py \
 | 
|---|
| 132 |         --dep-target=10.5
 | 
|---|
| 133 |         --universal-archs=all
 | 
|---|
| 134 |         --sdk-path=/Developer/SDKs/MacOSX10.5.sdk
 | 
|---|
| 135 | 
 | 
|---|
| 136 | This requires that the deployment target is 10.5, and hence
 | 
|---|
| 137 | also that you are building on at least OS X 10.5.  4-way includes
 | 
|---|
| 138 | ``i386``, ``x86_64``, ``ppc``, and ``ppc64`` (G5).  ``ppc64`` executable
 | 
|---|
| 139 | variants can only be run on G5 machines running 10.5.  Note that,
 | 
|---|
| 140 | while OS X 10.6 is only supported on Intel-based machines, it is possible
 | 
|---|
| 141 | to run ``ppc`` (32-bit) executables unmodified thanks to the Rosetta ppc
 | 
|---|
| 142 | emulation in OS X 10.5 and 10.6.  The 4-way installer variant must be
 | 
|---|
| 143 | built with Xcode 3.  It is not regularly built or tested.
 | 
|---|
| 144 | 
 | 
|---|
| 145 | Other ``--universal-archs`` options are ``64-bit`` (``x86_64``, ``ppc64``),
 | 
|---|
| 146 | and ``3-way`` (``ppc``, ``i386``, ``x86_64``).  None of these options
 | 
|---|
| 147 | are regularly exercised; use at your own risk.
 | 
|---|
| 148 | 
 | 
|---|
| 149 | 
 | 
|---|
| 150 | Testing
 | 
|---|
| 151 | -------
 | 
|---|
| 152 | 
 | 
|---|
| 153 | Ideally, the resulting binaries should be installed and the test suite run
 | 
|---|
| 154 | on all supported OS X releases and architectures.  As a practical matter,
 | 
|---|
| 155 | that is generally not possible.  At a minimum, variant 1 should be run on
 | 
|---|
| 156 | a PPC G4 system with OS X 10.5 and at least one Intel system running OS X
 | 
|---|
| 157 | 10.8, 10.7, 10.6, or 10.5.  Variant 2 should be run on 10.8, 10.7, and 10.6
 | 
|---|
| 158 | systems in both 32-bit and 64-bit modes.::
 | 
|---|
| 159 | 
 | 
|---|
| 160 |     /usr/local/bin/pythonn.n -m test -w -u all,-largefile
 | 
|---|
| 161 |     /usr/local/bin/pythonn.n-32 -m test -w -u all
 | 
|---|
| 162 |     
 | 
|---|
| 163 | Certain tests will be skipped and some cause the interpreter to fail
 | 
|---|
| 164 | which will likely generate ``Python quit unexpectedly`` alert messages
 | 
|---|
| 165 | to be generated at several points during a test run.  These are normal
 | 
|---|
| 166 | during testing and can be ignored.
 | 
|---|
| 167 | 
 | 
|---|
| 168 | It is also recommend to launch IDLE and verify that it is at least
 | 
|---|
| 169 | functional.  Double-click on the IDLE app icon in ``/Applications/Pythonn.n``.
 | 
|---|
| 170 | It should also be tested from the command line::
 | 
|---|
| 171 | 
 | 
|---|
| 172 |     /usr/local/bin/idlen.n
 | 
|---|
| 173 | 
 | 
|---|