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