source: trunk/essentials/dev-lang/python/Mac/Tools/fixapplepython23.py@ 3390

Last change on this file since 3390 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 4.5 KB
Line 
1#!/usr/bin/python
2"""fixapplepython23 - Fix Apple-installed Python 2.3 (on Mac OS X 10.3)
3
4Python 2.3 (and 2.3.X for X<5) have the problem that building an extension
5for a framework installation may accidentally pick up the framework
6of a newer Python, in stead of the one that was used to build the extension.
7
8This script modifies the Makefile (in .../lib/python2.3/config) to use
9the newer method of linking extensions with "-undefined dynamic_lookup"
10which fixes this problem.
11
12The script will first check all prerequisites, and return a zero exit
13status also when nothing needs to be fixed.
14"""
15import sys
16import os
17import gestalt
18
19MAKEFILE='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/Makefile'
20CHANGES=((
21 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n',
22 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n'
23 ),(
24 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n',
25 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n'
26 ),(
27 'CC=\t\tgcc\n',
28 'CC=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc\n'
29 ),(
30 'CXX=\t\tc++\n',
31 'CXX=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++\n'
32))
33
34GCC_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc'
35GXX_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++'
36SCRIPT="""#!/bin/sh
37export MACOSX_DEPLOYMENT_TARGET=10.3
38exec %s "${@}"
39"""
40
41def findline(lines, start):
42 """return line starting with given string or -1"""
43 for i in range(len(lines)):
44 if lines[i][:len(start)] == start:
45 return i
46 return -1
47
48def fix(makefile, do_apply):
49 """Fix the Makefile, if required."""
50 fixed = False
51 lines = open(makefile).readlines()
52
53 for old, new in CHANGES:
54 i = findline(lines, new)
55 if i >= 0:
56 # Already fixed
57 continue
58 i = findline(lines, old)
59 if i < 0:
60 print 'fixapplepython23: Python installation not fixed (appears broken)'
61 print 'fixapplepython23: missing line:', old
62 return 2
63 lines[i] = new
64 fixed = True
65
66 if fixed:
67 if do_apply:
68 print 'fixapplepython23: Fix to Apple-installed Python 2.3 applied'