annotate Mac/Tools/fixapplepython23.py @ 43203:b5f535cf135f

Fix Mac build, patch #1091 by Humberto Diogenes.
author Georg Brandl <georg@python.org>
date Mon, 03 Sep 2007 07:27:49 +0000
parents dcedd32f06de
children acdffb5b4352
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1 #!/usr/bin/python
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2 """fixapplepython23 - Fix Apple-installed Python 2.3 (on Mac OS X 10.3)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
3
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
4 Python 2.3 (and 2.3.X for X<5) have the problem that building an extension
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
5 for a framework installation may accidentally pick up the framework
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
6 of a newer Python, in stead of the one that was used to build the extension.
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
7
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
8 This script modifies the Makefile (in .../lib/python2.3/config) to use
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
9 the newer method of linking extensions with "-undefined dynamic_lookup"
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
10 which fixes this problem.
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
11
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
12 The script will first check all prerequisites, and return a zero exit
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
13 status also when nothing needs to be fixed.
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
14 """
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
15 import sys
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
16 import os
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
17 import gestalt
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
18
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
19 MAKEFILE='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/Makefile'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
20 CHANGES=((
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
21 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n',
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
22 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
23 ),(
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
24 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n',
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
25 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
26 ),(
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
27 'CC=\t\tgcc\n',
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
28 'CC=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc\n'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
29 ),(
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
30 'CXX=\t\tc++\n',
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
31 'CXX=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++\n'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
32 ))
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
33
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
34 GCC_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
35 GXX_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++'
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
36 SCRIPT="""#!/bin/sh
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
37 export MACOSX_DEPLOYMENT_TARGET=10.3
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
38 exec %s "${@}"
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
39 """
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
40
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
41 def findline(lines, start):
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
42 """return line starting with given string or -1"""
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
43 for i in range(len(lines)):
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
44 if lines[i][:len(start)] == start:
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
45 return i
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
46 return -1
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
47
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
48 def fix(makefile, do_apply):
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
49 """Fix the Makefile, if required."""
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
50 fixed = False
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
51 lines = open(makefile).readlines()
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
52
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
53 for old, new in CHANGES:
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
54 i = findline(lines, new)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
55 if i >= 0:
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
56 # Already fixed
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
57 continue
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
58 i = findline(lines, old)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
59 if i < 0:
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
60 print('fixapplepython23: Python installation not fixed (appears broken)')
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
61 print('fixapplepython23: missing line:', old)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
62 return 2
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
63 lines[i] = new
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
64 fixed = True
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
65
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
66 if fixed:
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
67 if do_apply:
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
68 print('fixapplepython23: Fix to Apple-installed Python 2.3 applied')
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
69 os.rename(makefile, makefile + '~')
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
70 open(makefile, 'w').writelines(lines)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
71 return 0
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
72 else:
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
73 print('fixapplepython23: Fix to Apple-installed Python 2.3 should be applied')
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
74 return 1
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
75 else:
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
76 print('fixapplepython23: No fix needed, appears to have been applied before')
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
77 return 0
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
78
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
79 def makescript(filename, compiler):
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
80 """Create a wrapper script for a compiler"""
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
81 dirname = os.path.split(filename)[0]
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
82 if not os.access(dirname, os.X_OK):
43203
b5f535cf135f Fix Mac build, patch #1091 by Humberto Diogenes.
Georg Brandl <georg@python.org>
parents: 43077
diff changeset
83 os.mkdir(dirname, 0o755)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
84 fp = open(filename, 'w')
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
85 fp.write(SCRIPT % compiler)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
86 fp.close()
43203
b5f535cf135f Fix Mac build, patch #1091 by Humberto Diogenes.
Georg Brandl <georg@python.org>
parents: 43077
diff changeset
87 os.chmod(filename, 0o755)
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
88 print('fixapplepython23: Created', filename)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
89
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
90 def main():
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
91 # Check for -n option
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
92 if len(sys.argv) > 1 and sys.argv[1] == '-n':
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
93 do_apply = False
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
94 else:
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
95 do_apply = True
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
96 # First check OS version
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
97 if sys.byteorder == 'little':
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
98 # All intel macs are fine
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
99 print("fixapplypython23: no fix is needed on MacOSX on Intel")
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
100 sys.exit(0)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
101
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
102 if gestalt.gestalt('sysv') < 0x1030:
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
103 print('fixapplepython23: no fix needed on MacOSX < 10.3')
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
104 sys.exit(0)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
105
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
106 if gestalt.gestalt('sysv') >= 0x1040:
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
107 print('fixapplepython23: no fix needed on MacOSX >= 10.4')
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
108 sys.exit(0)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
109
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
110 # Test that a framework Python is indeed installed
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
111 if not os.path.exists(MAKEFILE):
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
112 print('fixapplepython23: Python framework does not appear to be installed (?), nothing fixed')
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
113 sys.exit(0)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
114 # Check that we can actually write the file
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
115 if do_apply and not os.access(MAKEFILE, os.W_OK):
43077
dcedd32f06de Run 2to3's print fixer over some places that had been missed.
Collin Winter <collinw@gmail.com>
parents: 40450
diff changeset
116 print('fixapplepython23: No write permission, please run with "sudo"')
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
117 sys.exit(2)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
118 # Create the shell scripts
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
119 if do_apply:
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
120 if not os.access(GCC_SCRIPT, os.X_OK):
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
121 makescript(GCC_SCRIPT, "gcc")
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
122 if not os.access(GXX_SCRIPT, os.X_OK):
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
123 makescript(GXX_SCRIPT, "g++")
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
124 # Finally fix the makefile
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
125 rv = fix(MAKEFILE, do_apply)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
126 #sys.exit(rv)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
127 sys.exit(0)
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
128
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
129 if __name__ == '__main__':
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
diff changeset
130 main()