Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 2 | """ |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 3 | This script is used to build "official" universal installers on Mac OS X. |
Ned Deily | dfca8c9 | 2012-08-06 06:34:00 -0700 | [diff] [blame] | 4 | It requires at least Mac OS X 10.5, Xcode 3, and the 10.4u SDK for |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 5 | 32-bit builds. 64-bit or four-way universal builds require at least |
| 6 | OS X 10.5 and the 10.5 SDK. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 7 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 8 | Please ensure that this script keeps working with Python 2.5, to avoid |
| 9 | bootstrap issues (/usr/bin/python is Python 2.5 on OSX 10.5). Sphinx, |
| 10 | which is used to build the documentation, currently requires at least |
| 11 | Python 2.4. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 12 | |
Ned Deily | dfca8c9 | 2012-08-06 06:34:00 -0700 | [diff] [blame] | 13 | In addition to what is supplied with OS X 10.5+ and Xcode 3+, the script |
| 14 | requires an installed version of hg and a third-party version of |
| 15 | Tcl/Tk 8.4 (for OS X 10.4 and 10.5 deployment targets) or Tcl/TK 8.5 |
| 16 | (for 10.6 or later) installed in /Library/Frameworks. When installed, |
| 17 | the Python built by this script will attempt to dynamically link first to |
| 18 | Tcl and Tk frameworks in /Library/Frameworks if available otherwise fall |
| 19 | back to the ones in /System/Library/Framework. For the build, we recommend |
| 20 | installing the most recent ActiveTcl 8.4 or 8.5 version. |
| 21 | |
| 22 | 32-bit-only installer builds are still possible on OS X 10.4 with Xcode 2.5 |
| 23 | and the installation of additional components, such as a newer Python |
| 24 | (2.5 is needed for Python parser updates), hg, and svn (for the documentation |
| 25 | build). |
| 26 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 27 | Usage: see USAGE variable in the script. |
| 28 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 29 | import platform, os, sys, getopt, textwrap, shutil, stat, time, pwd, grp |
| 30 | try: |
| 31 | import urllib2 as urllib_request |
| 32 | except ImportError: |
| 33 | import urllib.request as urllib_request |
| 34 | |
| 35 | STAT_0o755 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 36 | | stat.S_IRGRP | stat.S_IXGRP |
| 37 | | stat.S_IROTH | stat.S_IXOTH ) |
| 38 | |
| 39 | STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
| 40 | | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |
| 41 | | stat.S_IROTH | stat.S_IXOTH ) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 42 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 43 | INCLUDE_TIMESTAMP = 1 |
| 44 | VERBOSE = 1 |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 45 | |
| 46 | from plistlib import Plist |
| 47 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 48 | try: |
| 49 | from plistlib import writePlist |
| 50 | except ImportError: |
| 51 | # We're run using python2.3 |
| 52 | def writePlist(plist, path): |
| 53 | plist.write(path) |
| 54 | |
| 55 | def shellQuote(value): |
| 56 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 57 | Return the string value in a form that can safely be inserted into |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 58 | a shell command. |
| 59 | """ |
| 60 | return "'%s'"%(value.replace("'", "'\"'\"'")) |
| 61 | |
| 62 | def grepValue(fn, variable): |
| 63 | variable = variable + '=' |
| 64 | for ln in open(fn, 'r'): |
| 65 | if ln.startswith(variable): |
| 66 | value = ln[len(variable):].strip() |
| 67 | return value[1:-1] |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 68 | raise RuntimeError("Cannot find variable %s" % variable[:-1]) |
| 69 | |
| 70 | _cache_getVersion = None |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 71 | |
| 72 | def getVersion(): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 73 | global _cache_getVersion |
| 74 | if _cache_getVersion is None: |
| 75 | _cache_getVersion = grepValue( |
| 76 | os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') |
| 77 | return _cache_getVersion |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 78 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 79 | def getVersionTuple(): |
| 80 | return tuple([int(n) for n in getVersion().split('.')]) |
| 81 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 82 | def getVersionMajorMinor(): |
| 83 | return tuple([int(n) for n in getVersion().split('.', 2)]) |
| 84 | |
| 85 | _cache_getFullVersion = None |
| 86 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 87 | def getFullVersion(): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 88 | global _cache_getFullVersion |
| 89 | if _cache_getFullVersion is not None: |
| 90 | return _cache_getFullVersion |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 91 | fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') |
| 92 | for ln in open(fn): |
| 93 | if 'PY_VERSION' in ln: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 94 | _cache_getFullVersion = ln.split()[-1][1:-1] |
| 95 | return _cache_getFullVersion |
| 96 | raise RuntimeError("Cannot find full version??") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 97 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 98 | # The directory we'll use to create the build (will be erased and recreated) |
| 99 | WORKDIR = "/tmp/_py" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 100 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 101 | # The directory we'll use to store third-party sources. Set this to something |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 102 | # else if you don't want to re-fetch required libraries every time. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 103 | DEPSRC = os.path.join(WORKDIR, 'third-party') |
| 104 | DEPSRC = os.path.expanduser('~/Universal/other-sources') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 105 | |
| 106 | # Location of the preferred SDK |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 107 | |
| 108 | ### There are some issues with the SDK selection below here, |
| 109 | ### The resulting binary doesn't work on all platforms that |
| 110 | ### it should. Always default to the 10.4u SDK until that |
| 111 | ### isue is resolved. |
| 112 | ### |
| 113 | ##if int(os.uname()[2].split('.')[0]) == 8: |
| 114 | ## # Explicitly use the 10.4u (universal) SDK when |
| 115 | ## # building on 10.4, the system headers are not |
| 116 | ## # useable for a universal build |
| 117 | ## SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" |
| 118 | ##else: |
| 119 | ## SDKPATH = "/" |
| 120 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 121 | SDKPATH = "/Developer/SDKs/MacOSX10.4u.sdk" |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 122 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 123 | universal_opts_map = { '32-bit': ('i386', 'ppc',), |
| 124 | '64-bit': ('x86_64', 'ppc64',), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 125 | 'intel': ('i386', 'x86_64'), |
| 126 | '3-way': ('ppc', 'i386', 'x86_64'), |
| 127 | 'all': ('i386', 'ppc', 'x86_64', 'ppc64',) } |
| 128 | default_target_map = { |
| 129 | '64-bit': '10.5', |
| 130 | '3-way': '10.5', |
| 131 | 'intel': '10.5', |
| 132 | 'all': '10.5', |
| 133 | } |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 134 | |
| 135 | UNIVERSALOPTS = tuple(universal_opts_map.keys()) |
| 136 | |
| 137 | UNIVERSALARCHS = '32-bit' |
| 138 | |
| 139 | ARCHLIST = universal_opts_map[UNIVERSALARCHS] |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 140 | |
Ezio Melotti | 42da663 | 2011-03-15 05:18:48 +0200 | [diff] [blame] | 141 | # Source directory (assume we're in Mac/BuildScript) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 142 | SRCDIR = os.path.dirname( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 143 | os.path.dirname( |
| 144 | os.path.dirname( |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 145 | os.path.abspath(__file__ |
| 146 | )))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 147 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 148 | # $MACOSX_DEPLOYMENT_TARGET -> minimum OS X level |
| 149 | DEPTARGET = '10.3' |
| 150 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 151 | target_cc_map = { |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 152 | '10.3': ('gcc-4.0', 'g++-4.0'), |
| 153 | '10.4': ('gcc-4.0', 'g++-4.0'), |
| 154 | '10.5': ('gcc-4.2', 'g++-4.2'), |
| 155 | '10.6': ('gcc-4.2', 'g++-4.2'), |
| 156 | '10.7': ('clang', 'clang++'), |
| 157 | '10.8': ('clang', 'clang++'), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 160 | CC, CXX = target_cc_map[DEPTARGET] |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 161 | |
| 162 | PYTHON_3 = getVersionTuple() >= (3, 0) |
| 163 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 164 | USAGE = textwrap.dedent("""\ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 165 | Usage: build_python [options] |
| 166 | |
| 167 | Options: |
| 168 | -? or -h: Show this message |
| 169 | -b DIR |
| 170 | --build-dir=DIR: Create build here (default: %(WORKDIR)r) |
| 171 | --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r) |
| 172 | --sdk-path=DIR: Location of the SDK (default: %(SDKPATH)r) |
| 173 | --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 174 | --dep-target=10.n OS X deployment target (default: %(DEPTARGET)r) |
| 175 | --universal-archs=x universal architectures (options: %(UNIVERSALOPTS)r, default: %(UNIVERSALARCHS)r) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 176 | """)% globals() |
| 177 | |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 178 | # Dict of object file names with shared library names to check after building. |
| 179 | # This is to ensure that we ended up dynamically linking with the shared |
| 180 | # library paths and versions we expected. For example: |
| 181 | # EXPECTED_SHARED_LIBS['_tkinter.so'] = [ |
| 182 | # '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl', |
| 183 | # '/Library/Frameworks/Tk.framework/Versions/8.5/Tk'] |
| 184 | EXPECTED_SHARED_LIBS = {} |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 185 | |
| 186 | # Instructions for building libraries that are necessary for building a |
| 187 | # batteries included python. |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 188 | # [The recipes are defined here for convenience but instantiated later after |
| 189 | # command line options have been processed.] |
| 190 | def library_recipes(): |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 191 | result = [] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 192 | |
Ned Deily | 20416a2 | 2012-08-07 03:10:57 -0700 | [diff] [blame] | 193 | LT_10_5 = bool(DEPTARGET < '10.5') |
| 194 | |
Ned Deily | 4d4c0ee | 2012-04-01 00:17:33 -0700 | [diff] [blame] | 195 | result.extend([ |
| 196 | dict( |
| 197 | name="XZ 5.0.3", |
| 198 | url="http://tukaani.org/xz/xz-5.0.3.tar.gz", |
| 199 | checksum='fefe52f9ecd521de2a8ce38c21a27574', |
| 200 | configure_pre=[ |
| 201 | '--disable-dependency-tracking', |
| 202 | ] |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 203 | ), |
| 204 | dict( |
| 205 | name="NCurses 5.9", |
| 206 | url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz", |
| 207 | checksum='8cb9c412e5f2d96bc6f459aa8c6282a1', |
| 208 | configure_pre=[ |
| 209 | "--enable-widec", |
| 210 | "--without-cxx", |
| 211 | "--without-cxx-binding", |
| 212 | "--without-ada", |
| 213 | "--without-curses-h", |
| 214 | "--enable-shared", |
| 215 | "--with-shared", |
| 216 | "--without-debug", |
| 217 | "--without-normal", |
| 218 | "--without-termlib", |
| 219 | "--without-ticlib", |
| 220 | "--without-tests", |
| 221 | "--without-manpages", |
| 222 | "--datadir=/usr/share", |
| 223 | "--sysconfdir=/etc", |
| 224 | "--sharedstatedir=/usr/com", |
| 225 | "--with-terminfo-dirs=/usr/share/terminfo", |
| 226 | "--with-default-terminfo-dir=/usr/share/terminfo", |
| 227 | "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), |
| 228 | ], |
| 229 | patchscripts=[ |
| 230 | ("ftp://invisible-island.net/ncurses//5.9/ncurses-5.9-20120616-patch.sh.bz2", |
| 231 | "f54bf02a349f96a7c4f0d00922f3a0d4"), |
| 232 | ], |
| 233 | useLDFlags=False, |
| 234 | install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( |
| 235 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 236 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 237 | getVersion(), |
| 238 | ), |
| 239 | ), |
Ned Deily | 20416a2 | 2012-08-07 03:10:57 -0700 | [diff] [blame] | 240 | dict( |
| 241 | name="SQLite 3.7.13", |
| 242 | url="http://www.sqlite.org/sqlite-autoconf-3071300.tar.gz", |
| 243 | checksum='c97df403e8a3d5b67bb408fcd6aabd8e', |
| 244 | extra_cflags=('-Os ' |
| 245 | '-DSQLITE_ENABLE_FTS4 ' |
| 246 | '-DSQLITE_ENABLE_FTS3_PARENTHESIS ' |
| 247 | '-DSQLITE_ENABLE_RTREE ' |
| 248 | '-DSQLITE_TCL=0 ' |
| 249 | '%s' % ('','-DSQLITE_WITHOUT_ZONEMALLOC ')[LT_10_5]), |
| 250 | configure_pre=[ |
| 251 | '--enable-threadsafe', |
| 252 | '--enable-shared=no', |
| 253 | '--enable-static=yes', |
| 254 | '--disable-readline', |
| 255 | '--disable-dependency-tracking', |
| 256 | ] |
| 257 | ), |
| 258 | ]) |
Ned Deily | 4d4c0ee | 2012-04-01 00:17:33 -0700 | [diff] [blame] | 259 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 260 | if DEPTARGET < '10.5': |
| 261 | result.extend([ |
| 262 | dict( |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 263 | name="Bzip2 1.0.6", |
| 264 | url="http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz", |
| 265 | checksum='00b516f4704d4a7cb50a1d97e6e8e15b', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 266 | configure=None, |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 267 | install='make install CC=%s CXX=%s, PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( |
| 268 | CC, CXX, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 269 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 270 | ' -arch '.join(ARCHLIST), |
| 271 | SDKPATH, |
| 272 | ), |
| 273 | ), |
| 274 | dict( |
| 275 | name="ZLib 1.2.3", |
| 276 | url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz", |
| 277 | checksum='debc62758716a169df9f62e6ab2bc634', |
| 278 | configure=None, |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 279 | install='make install CC=%s CXX=%s, prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( |
| 280 | CC, CXX, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 281 | shellQuote(os.path.join(WORKDIR, 'libraries')), |
| 282 | ' -arch '.join(ARCHLIST), |
| 283 | SDKPATH, |
| 284 | ), |
| 285 | ), |
| 286 | dict( |
| 287 | # Note that GNU readline is GPL'd software |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 288 | name="GNU Readline 6.1.2", |
| 289 | url="http://ftp.gnu.org/pub/gnu/readline/readline-6.1.tar.gz" , |
| 290 | checksum='fc2f7e714fe792db1ce6ddc4c9fb4ef3', |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 291 | patchlevel='0', |
| 292 | patches=[ |
| 293 | # The readline maintainers don't do actual micro releases, but |
| 294 | # just ship a set of patches. |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 295 | ('http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-001', |
| 296 | 'c642f2e84d820884b0bf9fd176bc6c3f'), |
| 297 | ('http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-002', |
| 298 | '1a76781a1ea734e831588285db7ec9b1'), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 299 | ] |
| 300 | ), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 301 | ]) |
| 302 | |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 303 | if not PYTHON_3: |
| 304 | result.extend([ |
| 305 | dict( |
| 306 | name="Sleepycat DB 4.7.25", |
| 307 | url="http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz", |
| 308 | checksum='ec2b87e833779681a0c3a814aa71359e', |
| 309 | buildDir="build_unix", |
| 310 | configure="../dist/configure", |
| 311 | configure_pre=[ |
| 312 | '--includedir=/usr/local/include/db4', |
| 313 | ] |
| 314 | ), |
| 315 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 316 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 317 | return result |
| 318 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 319 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 320 | # Instructions for building packages inside the .mpkg. |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 321 | def pkg_recipes(): |
| 322 | unselected_for_python3 = ('selected', 'unselected')[PYTHON_3] |
| 323 | result = [ |
| 324 | dict( |
| 325 | name="PythonFramework", |
| 326 | long_name="Python Framework", |
| 327 | source="/Library/Frameworks/Python.framework", |
| 328 | readme="""\ |
| 329 | This package installs Python.framework, that is the python |
| 330 | interpreter and the standard library. This also includes Python |
| 331 | wrappers for lots of Mac OS X API's. |
| 332 | """, |
| 333 | postflight="scripts/postflight.framework", |
| 334 | selected='selected', |
| 335 | ), |
| 336 | dict( |
| 337 | name="PythonApplications", |
| 338 | long_name="GUI Applications", |
| 339 | source="/Applications/Python %(VER)s", |
| 340 | readme="""\ |
| 341 | This package installs IDLE (an interactive Python IDE), |
| 342 | Python Launcher and Build Applet (create application bundles |
| 343 | from python scripts). |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 344 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 345 | It also installs a number of examples and demos. |
| 346 | """, |
| 347 | required=False, |
| 348 | selected='selected', |
| 349 | ), |
| 350 | dict( |
| 351 | name="PythonUnixTools", |
| 352 | long_name="UNIX command-line tools", |
| 353 | source="/usr/local/bin", |
| 354 | readme="""\ |
| 355 | This package installs the unix tools in /usr/local/bin for |
| 356 | compatibility with older releases of Python. This package |
| 357 | is not necessary to use Python. |
| 358 | """, |
| 359 | required=False, |
| 360 | selected='selected', |
| 361 | ), |
| 362 | dict( |
| 363 | name="PythonDocumentation", |
| 364 | long_name="Python Documentation", |
| 365 | topdir="/Library/Frameworks/Python.framework/Versions/%(VER)s/Resources/English.lproj/Documentation", |
| 366 | source="/pydocs", |
| 367 | readme="""\ |
| 368 | This package installs the python documentation at a location |
Ned Deily | dfca8c9 | 2012-08-06 06:34:00 -0700 | [diff] [blame] | 369 | that is useable for pydoc and IDLE. |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 370 | """, |
| 371 | postflight="scripts/postflight.documentation", |
| 372 | required=False, |
| 373 | selected='selected', |
| 374 | ), |
| 375 | dict( |
| 376 | name="PythonProfileChanges", |
| 377 | long_name="Shell profile updater", |
| 378 | readme="""\ |
| 379 | This packages updates your shell profile to make sure that |
| 380 | the Python tools are found by your shell in preference of |
| 381 | the system provided Python tools. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 382 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 383 | If you don't install this package you'll have to add |
| 384 | "/Library/Frameworks/Python.framework/Versions/%(VER)s/bin" |
| 385 | to your PATH by hand. |
| 386 | """, |
| 387 | postflight="scripts/postflight.patch-profile", |
| 388 | topdir="/Library/Frameworks/Python.framework", |
| 389 | source="/empty-dir", |
| 390 | required=False, |
| 391 | selected=unselected_for_python3, |
| 392 | ), |
| 393 | ] |
| 394 | |
Ned Deily | 430d7a3 | 2012-06-24 00:19:31 -0700 | [diff] [blame] | 395 | if DEPTARGET < '10.4' and not PYTHON_3: |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 396 | result.append( |
| 397 | dict( |
| 398 | name="PythonSystemFixes", |
| 399 | long_name="Fix system Python", |
| 400 | readme="""\ |
| 401 | This package updates the system python installation on |
| 402 | Mac OS X 10.3 to ensure that you can build new python extensions |
| 403 | using that copy of python after installing this version. |
| 404 | """, |
| 405 | postflight="../Tools/fixapplepython23.py", |
| 406 | topdir="/Library/Frameworks/Python.framework", |
| 407 | source="/empty-dir", |
| 408 | required=False, |
| 409 | selected=unselected_for_python3, |
| 410 | ) |
| 411 | ) |
| 412 | return result |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 413 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 414 | def fatal(msg): |
| 415 | """ |
| 416 | A fatal error, bail out. |
| 417 | """ |
| 418 | sys.stderr.write('FATAL: ') |
| 419 | sys.stderr.write(msg) |
| 420 | sys.stderr.write('\n') |
| 421 | sys.exit(1) |
| 422 | |
| 423 | def fileContents(fn): |
| 424 | """ |
| 425 | Return the contents of the named file |
| 426 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 427 | return open(fn, 'r').read() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 428 | |
| 429 | def runCommand(commandline): |
| 430 | """ |
Ezio Melotti | 1392500 | 2011-03-16 11:05:33 +0200 | [diff] [blame] | 431 | Run a command and raise RuntimeError if it fails. Output is suppressed |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 432 | unless the command fails. |
| 433 | """ |
| 434 | fd = os.popen(commandline, 'r') |
| 435 | data = fd.read() |
| 436 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 437 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 438 | sys.stdout.write(data) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 439 | raise RuntimeError("command failed: %s"%(commandline,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 440 | |
| 441 | if VERBOSE: |
| 442 | sys.stdout.write(data); sys.stdout.flush() |
| 443 | |
| 444 | def captureCommand(commandline): |
| 445 | fd = os.popen(commandline, 'r') |
| 446 | data = fd.read() |
| 447 | xit = fd.close() |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 448 | if xit is not None: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 449 | sys.stdout.write(data) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 450 | raise RuntimeError("command failed: %s"%(commandline,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 451 | |
| 452 | return data |
| 453 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 454 | def getTclTkVersion(configfile, versionline): |
| 455 | """ |
| 456 | search Tcl or Tk configuration file for version line |
| 457 | """ |
| 458 | try: |
| 459 | f = open(configfile, "r") |
| 460 | except: |
| 461 | fatal("Framework configuration file not found: %s" % configfile) |
| 462 | |
| 463 | for l in f: |
| 464 | if l.startswith(versionline): |
| 465 | f.close() |
| 466 | return l |
| 467 | |
| 468 | fatal("Version variable %s not found in framework configuration file: %s" |
| 469 | % (versionline, configfile)) |
| 470 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 471 | def checkEnvironment(): |
| 472 | """ |
| 473 | Check that we're running on a supported system. |
| 474 | """ |
| 475 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 476 | if sys.version_info[0:2] < (2, 4): |
| 477 | fatal("This script must be run with Python 2.4 or later") |
| 478 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 479 | if platform.system() != 'Darwin': |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 480 | fatal("This script should be run on a Mac OS X 10.4 (or later) system") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 481 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 482 | if int(platform.release().split('.')[0]) < 8: |
| 483 | fatal("This script should be run on a Mac OS X 10.4 (or later) system") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 484 | |
| 485 | if not os.path.exists(SDKPATH): |
| 486 | fatal("Please install the latest version of Xcode and the %s SDK"%( |
| 487 | os.path.basename(SDKPATH[:-4]))) |
| 488 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 489 | # Because we only support dynamic load of only one major/minor version of |
| 490 | # Tcl/Tk, ensure: |
| 491 | # 1. there are no user-installed frameworks of Tcl/Tk with version |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 492 | # higher than the Apple-supplied system version in |
| 493 | # SDKROOT/System/Library/Frameworks |
| 494 | # 2. there is a user-installed framework (usually ActiveTcl) in (or linked |
| 495 | # in) SDKROOT/Library/Frameworks with the same version as the system |
| 496 | # version. This allows users to choose to install a newer patch level. |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 497 | |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 498 | frameworks = {} |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 499 | for framework in ['Tcl', 'Tk']: |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 500 | fwpth = 'Library/Frameworks/%s.framework/Versions/Current' % framework |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 501 | sysfw = os.path.join(SDKPATH, 'System', fwpth) |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 502 | libfw = os.path.join(SDKPATH, fwpth) |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 503 | usrfw = os.path.join(os.getenv('HOME'), fwpth) |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 504 | frameworks[framework] = os.readlink(sysfw) |
| 505 | if not os.path.exists(libfw): |
| 506 | fatal("Please install a link to a current %s %s as %s so " |
| 507 | "the user can override the system framework." |
| 508 | % (framework, frameworks[framework], libfw)) |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 509 | if os.readlink(libfw) != os.readlink(sysfw): |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 510 | fatal("Version of %s must match %s" % (libfw, sysfw) ) |
| 511 | if os.path.exists(usrfw): |
| 512 | fatal("Please rename %s to avoid possible dynamic load issues." |
| 513 | % usrfw) |
| 514 | |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 515 | if frameworks['Tcl'] != frameworks['Tk']: |
| 516 | fatal("The Tcl and Tk frameworks are not the same version.") |
| 517 | |
| 518 | # add files to check after build |
| 519 | EXPECTED_SHARED_LIBS['_tkinter.so'] = [ |
| 520 | "/Library/Frameworks/Tcl.framework/Versions/%s/Tcl" |
| 521 | % frameworks['Tcl'], |
| 522 | "/Library/Frameworks/Tk.framework/Versions/%s/Tk" |
| 523 | % frameworks['Tk'], |
| 524 | ] |
| 525 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 526 | # Remove inherited environment variables which might influence build |
| 527 | environ_var_prefixes = ['CPATH', 'C_INCLUDE_', 'DYLD_', 'LANG', 'LC_', |
| 528 | 'LD_', 'LIBRARY_', 'PATH', 'PYTHON'] |
| 529 | for ev in list(os.environ): |
| 530 | for prefix in environ_var_prefixes: |
| 531 | if ev.startswith(prefix) : |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 532 | print("INFO: deleting environment variable %s=%s" % ( |
| 533 | ev, os.environ[ev])) |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 534 | del os.environ[ev] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 535 | |
Ned Deily | dfca8c9 | 2012-08-06 06:34:00 -0700 | [diff] [blame] | 536 | base_path = '/bin:/sbin:/usr/bin:/usr/sbin' |
| 537 | if 'SDK_TOOLS_BIN' in os.environ: |
| 538 | base_path = os.environ['SDK_TOOLS_BIN'] + ':' + base_path |
| 539 | # Xcode 2.5 on OS X 10.4 does not include SetFile in its usr/bin; |
| 540 | # add its fixed location here if it exists |
| 541 | OLD_DEVELOPER_TOOLS = '/Developer/Tools' |
| 542 | if os.path.isdir(OLD_DEVELOPER_TOOLS): |
| 543 | base_path = base_path + ':' + OLD_DEVELOPER_TOOLS |
| 544 | os.environ['PATH'] = base_path |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 545 | print("Setting default PATH: %s"%(os.environ['PATH'])) |
Ronald Oussoren | 1e99be7 | 2010-04-20 06:36:47 +0000 | [diff] [blame] | 546 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 547 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 548 | def parseOptions(args=None): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 549 | """ |
| 550 | Parse arguments and update global settings. |
| 551 | """ |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 552 | global WORKDIR, DEPSRC, SDKPATH, SRCDIR, DEPTARGET |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 553 | global UNIVERSALOPTS, UNIVERSALARCHS, ARCHLIST, CC, CXX |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 554 | |
| 555 | if args is None: |
| 556 | args = sys.argv[1:] |
| 557 | |
| 558 | try: |
| 559 | options, args = getopt.getopt(args, '?hb', |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 560 | [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=', |
| 561 | 'dep-target=', 'universal-archs=', 'help' ]) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 562 | except getopt.GetoptError: |
| 563 | print(sys.exc_info()[1]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 564 | sys.exit(1) |
| 565 | |
| 566 | if args: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 567 | print("Additional arguments") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 568 | sys.exit(1) |
| 569 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 570 | deptarget = None |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 571 | for k, v in options: |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 572 | if k in ('-h', '-?', '--help'): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 573 | print(USAGE) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 574 | sys.exit(0) |
| 575 | |
| 576 | elif k in ('-d', '--build-dir'): |
| 577 | WORKDIR=v |
| 578 | |
| 579 | elif k in ('--third-party',): |
| 580 | DEPSRC=v |
| 581 | |
| 582 | elif k in ('--sdk-path',): |
| 583 | SDKPATH=v |
| 584 | |
| 585 | elif k in ('--src-dir',): |
| 586 | SRCDIR=v |
| 587 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 588 | elif k in ('--dep-target', ): |
| 589 | DEPTARGET=v |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 590 | deptarget=v |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 591 | |
| 592 | elif k in ('--universal-archs', ): |
| 593 | if v in UNIVERSALOPTS: |
| 594 | UNIVERSALARCHS = v |
| 595 | ARCHLIST = universal_opts_map[UNIVERSALARCHS] |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 596 | if deptarget is None: |
| 597 | # Select alternate default deployment |
| 598 | # target |
| 599 | DEPTARGET = default_target_map.get(v, '10.3') |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 600 | else: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 601 | raise NotImplementedError(v) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 602 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 603 | else: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 604 | raise NotImplementedError(k) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 605 | |
| 606 | SRCDIR=os.path.abspath(SRCDIR) |
| 607 | WORKDIR=os.path.abspath(WORKDIR) |
| 608 | SDKPATH=os.path.abspath(SDKPATH) |
| 609 | DEPSRC=os.path.abspath(DEPSRC) |
| 610 | |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 611 | CC, CXX=target_cc_map[DEPTARGET] |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 612 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 613 | print("Settings:") |
| 614 | print(" * Source directory:", SRCDIR) |
| 615 | print(" * Build directory: ", WORKDIR) |
| 616 | print(" * SDK location: ", SDKPATH) |
| 617 | print(" * Third-party source:", DEPSRC) |
| 618 | print(" * Deployment target:", DEPTARGET) |
| 619 | print(" * Universal architectures:", ARCHLIST) |
| 620 | print(" * C compiler:", CC) |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 621 | print(" * C++ compiler:", CXX) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 622 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | def extractArchive(builddir, archiveName): |
| 628 | """ |
| 629 | Extract a source archive into 'builddir'. Returns the path of the |
| 630 | extracted archive. |
| 631 | |
| 632 | XXX: This function assumes that archives contain a toplevel directory |
| 633 | that is has the same name as the basename of the archive. This is |
| 634 | save enough for anything we use. |
| 635 | """ |
| 636 | curdir = os.getcwd() |
| 637 | try: |
| 638 | os.chdir(builddir) |
| 639 | if archiveName.endswith('.tar.gz'): |
| 640 | retval = os.path.basename(archiveName[:-7]) |
| 641 | if os.path.exists(retval): |
| 642 | shutil.rmtree(retval) |
| 643 | fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 644 | |
| 645 | elif archiveName.endswith('.tar.bz2'): |
| 646 | retval = os.path.basename(archiveName[:-8]) |
| 647 | if os.path.exists(retval): |
| 648 | shutil.rmtree(retval) |
| 649 | fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 650 | |
| 651 | elif archiveName.endswith('.tar'): |
| 652 | retval = os.path.basename(archiveName[:-4]) |
| 653 | if os.path.exists(retval): |
| 654 | shutil.rmtree(retval) |
| 655 | fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 656 | |
| 657 | elif archiveName.endswith('.zip'): |
| 658 | retval = os.path.basename(archiveName[:-4]) |
| 659 | if os.path.exists(retval): |
| 660 | shutil.rmtree(retval) |
| 661 | fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') |
| 662 | |
| 663 | data = fp.read() |
| 664 | xit = fp.close() |
| 665 | if xit is not None: |
| 666 | sys.stdout.write(data) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 667 | raise RuntimeError("Cannot extract %s"%(archiveName,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 668 | |
| 669 | return os.path.join(builddir, retval) |
| 670 | |
| 671 | finally: |
| 672 | os.chdir(curdir) |
| 673 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 674 | def downloadURL(url, fname): |
| 675 | """ |
| 676 | Download the contents of the url into the file. |
| 677 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 678 | fpIn = urllib_request.urlopen(url) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 679 | fpOut = open(fname, 'wb') |
| 680 | block = fpIn.read(10240) |
| 681 | try: |
| 682 | while block: |
| 683 | fpOut.write(block) |
| 684 | block = fpIn.read(10240) |
| 685 | fpIn.close() |
| 686 | fpOut.close() |
| 687 | except: |
| 688 | try: |
| 689 | os.unlink(fname) |
| 690 | except: |
| 691 | pass |
| 692 | |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 693 | def verifyThirdPartyFile(url, checksum, fname): |
| 694 | """ |
| 695 | Download file from url to filename fname if it does not already exist. |
| 696 | Abort if file contents does not match supplied md5 checksum. |
| 697 | """ |
| 698 | name = os.path.basename(fname) |
| 699 | if os.path.exists(fname): |
| 700 | print("Using local copy of %s"%(name,)) |
| 701 | else: |
| 702 | print("Did not find local copy of %s"%(name,)) |
| 703 | print("Downloading %s"%(name,)) |
| 704 | downloadURL(url, fname) |
| 705 | print("Archive for %s stored as %s"%(name, fname)) |
| 706 | if os.system( |
| 707 | 'MD5=$(openssl md5 %s) ; test "${MD5##*= }" = "%s"' |
| 708 | % (shellQuote(fname), checksum) ): |
| 709 | fatal('MD5 checksum mismatch for file %s' % fname) |
| 710 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 711 | def buildRecipe(recipe, basedir, archList): |
| 712 | """ |
| 713 | Build software using a recipe. This function does the |
| 714 | 'configure;make;make install' dance for C software, with a possibility |
| 715 | to customize this process, basically a poor-mans DarwinPorts. |
| 716 | """ |
| 717 | curdir = os.getcwd() |
| 718 | |
| 719 | name = recipe['name'] |
| 720 | url = recipe['url'] |
| 721 | configure = recipe.get('configure', './configure') |
| 722 | install = recipe.get('install', 'make && make install DESTDIR=%s'%( |
| 723 | shellQuote(basedir))) |
| 724 | |
| 725 | archiveName = os.path.split(url)[-1] |
| 726 | sourceArchive = os.path.join(DEPSRC, archiveName) |
| 727 | |
| 728 | if not os.path.exists(DEPSRC): |
| 729 | os.mkdir(DEPSRC) |
| 730 | |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 731 | verifyThirdPartyFile(url, recipe['checksum'], sourceArchive) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 732 | print("Extracting archive for %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 733 | buildDir=os.path.join(WORKDIR, '_bld') |
| 734 | if not os.path.exists(buildDir): |
| 735 | os.mkdir(buildDir) |
| 736 | |
| 737 | workDir = extractArchive(buildDir, sourceArchive) |
| 738 | os.chdir(workDir) |
| 739 | if 'buildDir' in recipe: |
| 740 | os.chdir(recipe['buildDir']) |
| 741 | |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 742 | for patch in recipe.get('patches', ()): |
| 743 | if isinstance(patch, tuple): |
| 744 | url, checksum = patch |
| 745 | fn = os.path.join(DEPSRC, os.path.basename(url)) |
| 746 | verifyThirdPartyFile(url, checksum, fn) |
| 747 | else: |
| 748 | # patch is a file in the source directory |
| 749 | fn = os.path.join(curdir, patch) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 750 | runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), |
| 751 | shellQuote(fn),)) |
| 752 | |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 753 | for patchscript in recipe.get('patchscripts', ()): |
| 754 | if isinstance(patchscript, tuple): |
| 755 | url, checksum = patchscript |
| 756 | fn = os.path.join(DEPSRC, os.path.basename(url)) |
| 757 | verifyThirdPartyFile(url, checksum, fn) |
| 758 | else: |
| 759 | # patch is a file in the source directory |
| 760 | fn = os.path.join(curdir, patchscript) |
| 761 | if fn.endswith('.bz2'): |
| 762 | runCommand('bunzip2 -fk %s' % shellQuote(fn)) |
| 763 | fn = fn[:-4] |
| 764 | runCommand('sh %s' % shellQuote(fn)) |
| 765 | os.unlink(fn) |
| 766 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 767 | if configure is not None: |
| 768 | configure_args = [ |
| 769 | "--prefix=/usr/local", |
| 770 | "--enable-static", |
| 771 | "--disable-shared", |
| 772 | #"CPP=gcc -arch %s -E"%(' -arch '.join(archList,),), |
| 773 | ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 774 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 775 | if 'configure_pre' in recipe: |
| 776 | args = list(recipe['configure_pre']) |
| 777 | if '--disable-static' in args: |
| 778 | configure_args.remove('--enable-static') |
| 779 | if '--enable-shared' in args: |
| 780 | configure_args.remove('--disable-shared') |
| 781 | configure_args.extend(args) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 782 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 783 | if recipe.get('useLDFlags', 1): |
| 784 | configure_args.extend([ |
Ned Deily | 20416a2 | 2012-08-07 03:10:57 -0700 | [diff] [blame] | 785 | "CFLAGS=%s-mmacosx-version-min=%s -arch %s -isysroot %s " |
| 786 | "-I%s/usr/local/include"%( |
| 787 | recipe.get('extra_cflags', ''), |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 788 | DEPTARGET, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 789 | ' -arch '.join(archList), |
| 790 | shellQuote(SDKPATH)[1:-1], |
| 791 | shellQuote(basedir)[1:-1],), |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 792 | "LDFLAGS=-mmacosx-version-min=%s -syslibroot,%s -L%s/usr/local/lib -arch %s"%( |
| 793 | DEPTARGET, |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 794 | shellQuote(SDKPATH)[1:-1], |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 795 | shellQuote(basedir)[1:-1], |
| 796 | ' -arch '.join(archList)), |
| 797 | ]) |
| 798 | else: |
| 799 | configure_args.extend([ |
Ned Deily | 20416a2 | 2012-08-07 03:10:57 -0700 | [diff] [blame] | 800 | "CFLAGS=%s-mmacosx-version-min=%s -arch %s -isysroot %s " |
| 801 | "-I%s/usr/local/include"%( |
| 802 | recipe.get('extra_cflags', ''), |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 803 | DEPTARGET, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 804 | ' -arch '.join(archList), |
| 805 | shellQuote(SDKPATH)[1:-1], |
| 806 | shellQuote(basedir)[1:-1],), |
| 807 | ]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 808 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 809 | if 'configure_post' in recipe: |
Ned Deily | a0abb44 | 2012-08-06 06:40:48 -0700 | [diff] [blame] | 810 | configure_args = configure_args + list(recipe['configure_post']) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 811 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 812 | configure_args.insert(0, configure) |
| 813 | configure_args = [ shellQuote(a) for a in configure_args ] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 814 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 815 | print("Running configure for %s"%(name,)) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 816 | runCommand(' '.join(configure_args) + ' 2>&1') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 817 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 818 | print("Running install for %s"%(name,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 819 | runCommand('{ ' + install + ' ;} 2>&1') |
| 820 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 821 | print("Done %s"%(name,)) |
| 822 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 823 | |
| 824 | os.chdir(curdir) |
| 825 | |
| 826 | def buildLibraries(): |
| 827 | """ |
| 828 | Build our dependencies into $WORKDIR/libraries/usr/local |
| 829 | """ |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 830 | print("") |
| 831 | print("Building required libraries") |
| 832 | print("") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 833 | universal = os.path.join(WORKDIR, 'libraries') |
| 834 | os.mkdir(universal) |
| 835 | os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) |
| 836 | os.makedirs(os.path.join(universal, 'usr', 'local', 'include')) |
| 837 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 838 | for recipe in library_recipes(): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 839 | buildRecipe(recipe, universal, ARCHLIST) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 840 | |
| 841 | |
| 842 | |
| 843 | def buildPythonDocs(): |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 844 | # This stores the documentation as Resources/English.lproj/Documentation |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 845 | # inside the framwork. pydoc and IDLE will pick it up there. |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 846 | print("Install python documentation") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 847 | rootDir = os.path.join(WORKDIR, '_root') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 848 | buildDir = os.path.join('../../Doc') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 849 | docdir = os.path.join(rootDir, 'pydocs') |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 850 | curDir = os.getcwd() |
| 851 | os.chdir(buildDir) |
| 852 | runCommand('make update') |
Martin v. Löwis | 6120ddb | 2010-04-22 13:16:44 +0000 | [diff] [blame] | 853 | runCommand("make html PYTHON='%s'" % os.path.abspath(sys.executable)) |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 854 | os.chdir(curDir) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 855 | if not os.path.exists(docdir): |
| 856 | os.mkdir(docdir) |
Ronald Oussoren | f84d7e9 | 2009-05-19 11:27:25 +0000 | [diff] [blame] | 857 | os.rename(os.path.join(buildDir, 'build', 'html'), docdir) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 858 | |
| 859 | |
| 860 | def buildPython(): |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 861 | print("Building a universal python for %s architectures" % UNIVERSALARCHS) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 862 | |
| 863 | buildDir = os.path.join(WORKDIR, '_bld', 'python') |
| 864 | rootDir = os.path.join(WORKDIR, '_root') |
| 865 | |
| 866 | if os.path.exists(buildDir): |
| 867 | shutil.rmtree(buildDir) |
| 868 | if os.path.exists(rootDir): |
| 869 | shutil.rmtree(rootDir) |
Ned Deily | 4f7ff78 | 2011-01-15 05:29:12 +0000 | [diff] [blame] | 870 | os.makedirs(buildDir) |
| 871 | os.makedirs(rootDir) |
| 872 | os.makedirs(os.path.join(rootDir, 'empty-dir')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 873 | curdir = os.getcwd() |
| 874 | os.chdir(buildDir) |
| 875 | |
| 876 | # Not sure if this is still needed, the original build script |
| 877 | # claims that parts of the install assume python.exe exists. |
| 878 | os.symlink('python', os.path.join(buildDir, 'python.exe')) |
| 879 | |
| 880 | # Extract the version from the configure file, needed to calculate |
| 881 | # several paths. |
| 882 | version = getVersion() |
| 883 | |
Ronald Oussoren | ac4b39f | 2009-03-30 20:05:35 +0000 | [diff] [blame] | 884 | # Since the extra libs are not in their installed framework location |
| 885 | # during the build, augment the library path so that the interpreter |
| 886 | # will find them during its extension import sanity checks. |
| 887 | os.environ['DYLD_LIBRARY_PATH'] = os.path.join(WORKDIR, |
| 888 | 'libraries', 'usr', 'local', 'lib') |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 889 | print("Running configure...") |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 890 | runCommand("%s -C --enable-framework --enable-universalsdk=%s " |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 891 | "--with-universal-archs=%s " |
| 892 | "%s " |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 893 | "LDFLAGS='-g -L%s/libraries/usr/local/lib' " |
| 894 | "OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( |
| 895 | shellQuote(os.path.join(SRCDIR, 'configure')), shellQuote(SDKPATH), |
| 896 | UNIVERSALARCHS, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 897 | (' ', '--with-computed-gotos ')[PYTHON_3], |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 898 | shellQuote(WORKDIR)[1:-1], |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 899 | shellQuote(WORKDIR)[1:-1])) |
| 900 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 901 | print("Running make") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 902 | runCommand("make") |
| 903 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 904 | print("Running make install") |
Ronald Oussoren | f84d7e9 | 2009-05-19 11:27:25 +0000 | [diff] [blame] | 905 | runCommand("make install DESTDIR=%s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 906 | shellQuote(rootDir))) |
| 907 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 908 | print("Running make frameworkinstallextras") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 909 | runCommand("make frameworkinstallextras DESTDIR=%s"%( |
| 910 | shellQuote(rootDir))) |
| 911 | |
Ronald Oussoren | ac4b39f | 2009-03-30 20:05:35 +0000 | [diff] [blame] | 912 | del os.environ['DYLD_LIBRARY_PATH'] |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 913 | print("Copying required shared libraries") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 914 | if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): |
| 915 | runCommand("mv %s/* %s"%( |
| 916 | shellQuote(os.path.join( |
| 917 | WORKDIR, 'libraries', 'Library', 'Frameworks', |
| 918 | 'Python.framework', 'Versions', getVersion(), |
| 919 | 'lib')), |
| 920 | shellQuote(os.path.join(WORKDIR, '_root', 'Library', 'Frameworks', |
| 921 | 'Python.framework', 'Versions', getVersion(), |
| 922 | 'lib')))) |
| 923 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 924 | print("Fix file modes") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 925 | frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 926 | gid = grp.getgrnam('admin').gr_gid |
| 927 | |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 928 | shared_lib_error = False |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 929 | for dirpath, dirnames, filenames in os.walk(frmDir): |
| 930 | for dn in dirnames: |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 931 | os.chmod(os.path.join(dirpath, dn), STAT_0o775) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 932 | os.chown(os.path.join(dirpath, dn), -1, gid) |
| 933 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 934 | for fn in filenames: |
| 935 | if os.path.islink(fn): |
| 936 | continue |
| 937 | |
| 938 | # "chmod g+w $fn" |
| 939 | p = os.path.join(dirpath, fn) |
| 940 | st = os.stat(p) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 941 | os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IWGRP) |
| 942 | os.chown(p, -1, gid) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 943 | |
Ned Deily | 2910a7b | 2012-07-30 02:35:58 -0700 | [diff] [blame] | 944 | if fn in EXPECTED_SHARED_LIBS: |
| 945 | # check to see that this file was linked with the |
| 946 | # expected library path and version |
| 947 | data = captureCommand("otool -L %s" % shellQuote(p)) |
| 948 | for sl in EXPECTED_SHARED_LIBS[fn]: |
| 949 | if ("\t%s " % sl) not in data: |
| 950 | print("Expected shared lib %s was not linked with %s" |
| 951 | % (sl, p)) |
| 952 | shared_lib_error = True |
| 953 | |
| 954 | if shared_lib_error: |
| 955 | fatal("Unexpected shared library errors.") |
| 956 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 957 | if PYTHON_3: |
| 958 | LDVERSION=None |
| 959 | VERSION=None |
| 960 | ABIFLAGS=None |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 961 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 962 | fp = open(os.path.join(buildDir, 'Makefile'), 'r') |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 963 | for ln in fp: |
| 964 | if ln.startswith('VERSION='): |
| 965 | VERSION=ln.split()[1] |
| 966 | if ln.startswith('ABIFLAGS='): |
| 967 | ABIFLAGS=ln.split()[1] |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 968 | if ln.startswith('LDVERSION='): |
| 969 | LDVERSION=ln.split()[1] |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 970 | fp.close() |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 971 | |
Ned Deily | e59e4c5 | 2011-01-29 18:56:28 +0000 | [diff] [blame] | 972 | LDVERSION = LDVERSION.replace('$(VERSION)', VERSION) |
| 973 | LDVERSION = LDVERSION.replace('$(ABIFLAGS)', ABIFLAGS) |
| 974 | config_suffix = '-' + LDVERSION |
| 975 | else: |
| 976 | config_suffix = '' # Python 2.x |
Ronald Oussoren | 0499d0b | 2010-12-07 14:41:05 +0000 | [diff] [blame] | 977 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 978 | # We added some directories to the search path during the configure |
| 979 | # phase. Remove those because those directories won't be there on |
Ned Deily | a606aef | 2012-07-21 10:48:09 -0700 | [diff] [blame] | 980 | # the end-users system. Also remove the directories from _sysconfigdata.py |
| 981 | # (added in 3.3) if it exists. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 982 | |
Ned Deily | a606aef | 2012-07-21 10:48:09 -0700 | [diff] [blame] | 983 | path_to_lib = os.path.join(rootDir, 'Library', 'Frameworks', |
| 984 | 'Python.framework', 'Versions', |
| 985 | version, 'lib', 'python%s'%(version,)) |
| 986 | paths = [os.path.join(path_to_lib, 'config' + config_suffix, 'Makefile'), |
| 987 | os.path.join(path_to_lib, '_sysconfigdata.py')] |
| 988 | for path in paths: |
| 989 | if not os.path.exists(path): |
| 990 | continue |
| 991 | fp = open(path, 'r') |
| 992 | data = fp.read() |
| 993 | fp.close() |
| 994 | |
Ned Deily | 2c80e12 | 2012-07-22 00:46:46 -0700 | [diff] [blame] | 995 | data = data.replace(' -L%s/libraries/usr/local/lib'%(WORKDIR,), '') |
| 996 | data = data.replace(' -I%s/libraries/usr/local/include'%(WORKDIR,), '') |
Ned Deily | a606aef | 2012-07-21 10:48:09 -0700 | [diff] [blame] | 997 | fp = open(path, 'w') |
| 998 | fp.write(data) |
| 999 | fp.close() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1000 | |
| 1001 | # Add symlinks in /usr/local/bin, using relative links |
| 1002 | usr_local_bin = os.path.join(rootDir, 'usr', 'local', 'bin') |
| 1003 | to_framework = os.path.join('..', '..', '..', 'Library', 'Frameworks', |
| 1004 | 'Python.framework', 'Versions', version, 'bin') |
| 1005 | if os.path.exists(usr_local_bin): |
| 1006 | shutil.rmtree(usr_local_bin) |
| 1007 | os.makedirs(usr_local_bin) |
| 1008 | for fn in os.listdir( |
| 1009 | os.path.join(frmDir, 'Versions', version, 'bin')): |
| 1010 | os.symlink(os.path.join(to_framework, fn), |
| 1011 | os.path.join(usr_local_bin, fn)) |
| 1012 | |
| 1013 | os.chdir(curdir) |
| 1014 | |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1015 | if PYTHON_3: |
| 1016 | # Remove the 'Current' link, that way we don't accidently mess |
| 1017 | # with an already installed version of python 2 |
| 1018 | os.unlink(os.path.join(rootDir, 'Library', 'Frameworks', |
| 1019 | 'Python.framework', 'Versions', 'Current')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1020 | |
| 1021 | def patchFile(inPath, outPath): |
| 1022 | data = fileContents(inPath) |
| 1023 | data = data.replace('$FULL_VERSION', getFullVersion()) |
| 1024 | data = data.replace('$VERSION', getVersion()) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1025 | data = data.replace('$MACOSX_DEPLOYMENT_TARGET', ''.join((DEPTARGET, ' or later'))) |
Ronald Oussoren | d010329 | 2010-10-20 12:56:56 +0000 | [diff] [blame] | 1026 | data = data.replace('$ARCHITECTURES', ", ".join(universal_opts_map[UNIVERSALARCHS])) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1027 | data = data.replace('$INSTALL_SIZE', installSize()) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1028 | |
| 1029 | # This one is not handy as a template variable |
| 1030 | data = data.replace('$PYTHONFRAMEWORKINSTALLDIR', '/Library/Frameworks/Python.framework') |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1031 | fp = open(outPath, 'w') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1032 | fp.write(data) |
| 1033 | fp.close() |
| 1034 | |
| 1035 | def patchScript(inPath, outPath): |
| 1036 | data = fileContents(inPath) |
| 1037 | data = data.replace('@PYVER@', getVersion()) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1038 | fp = open(outPath, 'w') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1039 | fp.write(data) |
| 1040 | fp.close() |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1041 | os.chmod(outPath, STAT_0o755) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1042 | |
| 1043 | |
| 1044 | |
| 1045 | def packageFromRecipe(targetDir, recipe): |
| 1046 | curdir = os.getcwd() |
| 1047 | try: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1048 | # The major version (such as 2.5) is included in the package name |
| 1049 | # because having two version of python installed at the same time is |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1050 | # common. |
| 1051 | pkgname = '%s-%s'%(recipe['name'], getVersion()) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1052 | srcdir = recipe.get('source') |
| 1053 | pkgroot = recipe.get('topdir', srcdir) |
| 1054 | postflight = recipe.get('postflight') |
| 1055 | readme = textwrap.dedent(recipe['readme']) |
| 1056 | isRequired = recipe.get('required', True) |
| 1057 | |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1058 | print("- building package %s"%(pkgname,)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1059 | |
| 1060 | # Substitute some variables |
| 1061 | textvars = dict( |
| 1062 | VER=getVersion(), |
| 1063 | FULLVER=getFullVersion(), |
| 1064 | ) |
| 1065 | readme = readme % textvars |
| 1066 | |
| 1067 | if pkgroot is not None: |
| 1068 | pkgroot = pkgroot % textvars |
| 1069 | else: |
| 1070 | pkgroot = '/' |
| 1071 | |
| 1072 | if srcdir is not None: |
| 1073 | srcdir = os.path.join(WORKDIR, '_root', srcdir[1:]) |
| 1074 | srcdir = srcdir % textvars |
| 1075 | |
| 1076 | if postflight is not None: |
| 1077 | postflight = os.path.abspath(postflight) |
| 1078 | |
| 1079 | packageContents = os.path.join(targetDir, pkgname + '.pkg', 'Contents') |
| 1080 | os.makedirs(packageContents) |
| 1081 | |
| 1082 | if srcdir is not None: |
| 1083 | os.chdir(srcdir) |
| 1084 | runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 1085 | runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) |
| 1086 | runCommand("mkbom . %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.bom')),)) |
| 1087 | |
| 1088 | fn = os.path.join(packageContents, 'PkgInfo') |
| 1089 | fp = open(fn, 'w') |
| 1090 | fp.write('pmkrpkg1') |
| 1091 | fp.close() |
| 1092 | |
| 1093 | rsrcDir = os.path.join(packageContents, "Resources") |
| 1094 | os.mkdir(rsrcDir) |
| 1095 | fp = open(os.path.join(rsrcDir, 'ReadMe.txt'), 'w') |
| 1096 | fp.write(readme) |
| 1097 | fp.close() |
| 1098 | |
| 1099 | if postflight is not None: |
| 1100 | patchScript(postflight, os.path.join(rsrcDir, 'postflight')) |
| 1101 | |
| 1102 | vers = getFullVersion() |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1103 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1104 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1105 | CFBundleGetInfoString="Python.%s %s"%(pkgname, vers,), |
| 1106 | CFBundleIdentifier='org.python.Python.%s'%(pkgname,), |
| 1107 | CFBundleName='Python.%s'%(pkgname,), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1108 | CFBundleShortVersionString=vers, |
| 1109 | IFMajorVersion=major, |
| 1110 | IFMinorVersion=minor, |
| 1111 | IFPkgFormatVersion=0.10000000149011612, |
| 1112 | IFPkgFlagAllowBackRev=False, |
| 1113 | IFPkgFlagAuthorizationAction="RootAuthorization", |
| 1114 | IFPkgFlagDefaultLocation=pkgroot, |
| 1115 | IFPkgFlagFollowLinks=True, |
| 1116 | IFPkgFlagInstallFat=True, |
| 1117 | IFPkgFlagIsRequired=isRequired, |
| 1118 | IFPkgFlagOverwritePermissions=False, |
| 1119 | IFPkgFlagRelocatable=False, |
| 1120 | IFPkgFlagRestartAction="NoRestart", |
| 1121 | IFPkgFlagRootVolumeOnly=True, |
| 1122 | IFPkgFlagUpdateInstalledLangauges=False, |
| 1123 | ) |
| 1124 | writePlist(pl, os.path.join(packageContents, 'Info.plist')) |
| 1125 | |
| 1126 | pl = Plist( |
| 1127 | IFPkgDescriptionDescription=readme, |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1128 | IFPkgDescriptionTitle=recipe.get('long_name', "Python.%s"%(pkgname,)), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1129 | IFPkgDescriptionVersion=vers, |
| 1130 | ) |
| 1131 | writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist')) |
| 1132 | |
| 1133 | finally: |
| 1134 | os.chdir(curdir) |
| 1135 | |
| 1136 | |
| 1137 | def makeMpkgPlist(path): |
| 1138 | |
| 1139 | vers = getFullVersion() |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1140 | major, minor = getVersionMajorMinor() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1141 | |
| 1142 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1143 | CFBundleGetInfoString="Python %s"%(vers,), |
| 1144 | CFBundleIdentifier='org.python.Python', |
| 1145 | CFBundleName='Python', |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1146 | CFBundleShortVersionString=vers, |
| 1147 | IFMajorVersion=major, |
| 1148 | IFMinorVersion=minor, |
| 1149 | IFPkgFlagComponentDirectory="Contents/Packages", |
| 1150 | IFPkgFlagPackageList=[ |
| 1151 | dict( |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1152 | IFPkgFlagPackageLocation='%s-%s.pkg'%(item['name'], getVersion()), |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1153 | IFPkgFlagPackageSelection=item.get('selected', 'selected'), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1154 | ) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1155 | for item in pkg_recipes() |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1156 | ], |
| 1157 | IFPkgFormatVersion=0.10000000149011612, |
| 1158 | IFPkgFlagBackgroundScaling="proportional", |
| 1159 | IFPkgFlagBackgroundAlignment="left", |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1160 | IFPkgFlagAuthorizationAction="RootAuthorization", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1161 | ) |
| 1162 | |
| 1163 | writePlist(pl, path) |
| 1164 | |
| 1165 | |
| 1166 | def buildInstaller(): |
| 1167 | |
| 1168 | # Zap all compiled files |
| 1169 | for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): |
| 1170 | for fn in filenames: |
| 1171 | if fn.endswith('.pyc') or fn.endswith('.pyo'): |
| 1172 | os.unlink(os.path.join(dirpath, fn)) |
| 1173 | |
| 1174 | outdir = os.path.join(WORKDIR, 'installer') |
| 1175 | if os.path.exists(outdir): |
| 1176 | shutil.rmtree(outdir) |
| 1177 | os.mkdir(outdir) |
| 1178 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1179 | pkgroot = os.path.join(outdir, 'Python.mpkg', 'Contents') |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1180 | pkgcontents = os.path.join(pkgroot, 'Packages') |
| 1181 | os.makedirs(pkgcontents) |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1182 | for recipe in pkg_recipes(): |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1183 | packageFromRecipe(pkgcontents, recipe) |
| 1184 | |
| 1185 | rsrcDir = os.path.join(pkgroot, 'Resources') |
| 1186 | |
| 1187 | fn = os.path.join(pkgroot, 'PkgInfo') |
| 1188 | fp = open(fn, 'w') |
| 1189 | fp.write('pmkrpkg1') |
| 1190 | fp.close() |
| 1191 | |
| 1192 | os.mkdir(rsrcDir) |
| 1193 | |
| 1194 | makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) |
| 1195 | pl = Plist( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1196 | IFPkgDescriptionTitle="Python", |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1197 | IFPkgDescriptionVersion=getVersion(), |
| 1198 | ) |
| 1199 | |
| 1200 | writePlist(pl, os.path.join(pkgroot, 'Resources', 'Description.plist')) |
| 1201 | for fn in os.listdir('resources'): |
| 1202 | if fn == '.svn': continue |
| 1203 | if fn.endswith('.jpg'): |
| 1204 | shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 1205 | else: |
| 1206 | patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) |
| 1207 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1208 | shutil.copy("../../LICENSE", os.path.join(rsrcDir, 'License.txt')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1209 | |
| 1210 | |
| 1211 | def installSize(clear=False, _saved=[]): |
| 1212 | if clear: |
| 1213 | del _saved[:] |
| 1214 | if not _saved: |
| 1215 | data = captureCommand("du -ks %s"%( |
| 1216 | shellQuote(os.path.join(WORKDIR, '_root')))) |
| 1217 | _saved.append("%d"%((0.5 + (int(data.split()[0]) / 1024.0)),)) |
| 1218 | return _saved[0] |
| 1219 | |
| 1220 | |
| 1221 | def buildDMG(): |
| 1222 | """ |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1223 | Create DMG containing the rootDir. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1224 | """ |
| 1225 | outdir = os.path.join(WORKDIR, 'diskimage') |
| 1226 | if os.path.exists(outdir): |
| 1227 | shutil.rmtree(outdir) |
| 1228 | |
| 1229 | imagepath = os.path.join(outdir, |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1230 | 'python-%s-macosx%s'%(getFullVersion(),DEPTARGET)) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1231 | if INCLUDE_TIMESTAMP: |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1232 | imagepath = imagepath + '-%04d-%02d-%02d'%(time.localtime()[:3]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1233 | imagepath = imagepath + '.dmg' |
| 1234 | |
| 1235 | os.mkdir(outdir) |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1236 | volname='Python %s'%(getFullVersion()) |
| 1237 | runCommand("hdiutil create -format UDRW -volname %s -srcfolder %s %s"%( |
| 1238 | shellQuote(volname), |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1239 | shellQuote(os.path.join(WORKDIR, 'installer')), |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1240 | shellQuote(imagepath + ".tmp.dmg" ))) |
| 1241 | |
| 1242 | |
| 1243 | if not os.path.exists(os.path.join(WORKDIR, "mnt")): |
| 1244 | os.mkdir(os.path.join(WORKDIR, "mnt")) |
| 1245 | runCommand("hdiutil attach %s -mountroot %s"%( |
| 1246 | shellQuote(imagepath + ".tmp.dmg"), shellQuote(os.path.join(WORKDIR, "mnt")))) |
| 1247 | |
| 1248 | # Custom icon for the DMG, shown when the DMG is mounted. |
| 1249 | shutil.copy("../Icons/Disk Image.icns", |
| 1250 | os.path.join(WORKDIR, "mnt", volname, ".VolumeIcon.icns")) |
Ned Deily | dfca8c9 | 2012-08-06 06:34:00 -0700 | [diff] [blame] | 1251 | runCommand("SetFile -a C %s/"%( |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1252 | shellQuote(os.path.join(WORKDIR, "mnt", volname)),)) |
| 1253 | |
| 1254 | runCommand("hdiutil detach %s"%(shellQuote(os.path.join(WORKDIR, "mnt", volname)))) |
| 1255 | |
| 1256 | setIcon(imagepath + ".tmp.dmg", "../Icons/Disk Image.icns") |
| 1257 | runCommand("hdiutil convert %s -format UDZO -o %s"%( |
| 1258 | shellQuote(imagepath + ".tmp.dmg"), shellQuote(imagepath))) |
| 1259 | setIcon(imagepath, "../Icons/Disk Image.icns") |
| 1260 | |
| 1261 | os.unlink(imagepath + ".tmp.dmg") |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1262 | |
| 1263 | return imagepath |
| 1264 | |
| 1265 | |
| 1266 | def setIcon(filePath, icnsPath): |
| 1267 | """ |
| 1268 | Set the custom icon for the specified file or directory. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1269 | """ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1270 | |
Ronald Oussoren | 7005067 | 2010-04-30 15:00:26 +0000 | [diff] [blame] | 1271 | dirPath = os.path.normpath(os.path.dirname(__file__)) |
| 1272 | toolPath = os.path.join(dirPath, "seticon.app/Contents/MacOS/seticon") |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1273 | if not os.path.exists(toolPath) or os.stat(toolPath).st_mtime < os.stat(dirPath + '/seticon.m').st_mtime: |
| 1274 | # NOTE: The tool is created inside an .app bundle, otherwise it won't work due |
| 1275 | # to connections to the window server. |
Ronald Oussoren | 7005067 | 2010-04-30 15:00:26 +0000 | [diff] [blame] | 1276 | appPath = os.path.join(dirPath, "seticon.app/Contents/MacOS") |
| 1277 | if not os.path.exists(appPath): |
| 1278 | os.makedirs(appPath) |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1279 | runCommand("cc -o %s %s/seticon.m -framework Cocoa"%( |
| 1280 | shellQuote(toolPath), shellQuote(dirPath))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1281 | |
Ronald Oussoren | 207b4c2 | 2009-03-30 17:20:30 +0000 | [diff] [blame] | 1282 | runCommand("%s %s %s"%(shellQuote(os.path.abspath(toolPath)), shellQuote(icnsPath), |
| 1283 | shellQuote(filePath))) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1284 | |
| 1285 | def main(): |
| 1286 | # First parse options and check if we can perform our work |
| 1287 | parseOptions() |
| 1288 | checkEnvironment() |
| 1289 | |
Ronald Oussoren | 1943f86 | 2009-03-30 19:39:14 +0000 | [diff] [blame] | 1290 | os.environ['MACOSX_DEPLOYMENT_TARGET'] = DEPTARGET |
Benjamin Peterson | d9b7d48 | 2010-03-19 21:42:45 +0000 | [diff] [blame] | 1291 | os.environ['CC'] = CC |
Ned Deily | bbd3437 | 2012-08-22 23:34:50 -0700 | [diff] [blame^] | 1292 | os.environ['CXX'] = CXX |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1293 | |
| 1294 | if os.path.exists(WORKDIR): |
| 1295 | shutil.rmtree(WORKDIR) |
| 1296 | os.mkdir(WORKDIR) |
| 1297 | |
Ronald Oussoren | c45c3d9 | 2010-04-18 15:24:17 +0000 | [diff] [blame] | 1298 | os.environ['LC_ALL'] = 'C' |
| 1299 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1300 | # Then build third-party libraries such as sleepycat DB4. |
| 1301 | buildLibraries() |
| 1302 | |
| 1303 | # Now build python itself |
| 1304 | buildPython() |
Ronald Oussoren | 6bf6367 | 2009-03-31 13:25:17 +0000 | [diff] [blame] | 1305 | |
| 1306 | # And then build the documentation |
| 1307 | # Remove the Deployment Target from the shell |
| 1308 | # environment, it's no longer needed and |
| 1309 | # an unexpected build target can cause problems |
| 1310 | # when Sphinx and its dependencies need to |
| 1311 | # be (re-)installed. |
| 1312 | del os.environ['MACOSX_DEPLOYMENT_TARGET'] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1313 | buildPythonDocs() |
Ronald Oussoren | 6bf6367 | 2009-03-31 13:25:17 +0000 | [diff] [blame] | 1314 | |
| 1315 | |
| 1316 | # Prepare the applications folder |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1317 | fn = os.path.join(WORKDIR, "_root", "Applications", |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1318 | "Python %s"%(getVersion(),), "Update Shell Profile.command") |
Ronald Oussoren | bc44866 | 2009-02-12 16:08:14 +0000 | [diff] [blame] | 1319 | patchScript("scripts/postflight.patch-profile", fn) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1320 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1321 | folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1322 | getVersion(),)) |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1323 | os.chmod(folder, STAT_0o755) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1324 | setIcon(folder, "../Icons/Python Folder.icns") |
| 1325 | |
| 1326 | # Create the installer |
| 1327 | buildInstaller() |
| 1328 | |
| 1329 | # And copy the readme into the directory containing the installer |
| 1330 | patchFile('resources/ReadMe.txt', os.path.join(WORKDIR, 'installer', 'ReadMe.txt')) |
| 1331 | |
| 1332 | # Ditto for the license file. |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1333 | shutil.copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1334 | |
| 1335 | fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') |
Ned Deily | 7d9cf83 | 2010-11-27 16:42:15 -0800 | [diff] [blame] | 1336 | fp.write("# BUILD INFO\n") |
| 1337 | fp.write("# Date: %s\n" % time.ctime()) |
| 1338 | fp.write("# By: %s\n" % pwd.getpwuid(os.getuid()).pw_gecos) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1339 | fp.close() |
| 1340 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1341 | # And copy it to a DMG |
| 1342 | buildDMG() |
| 1343 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1344 | if __name__ == "__main__": |
| 1345 | main() |