Skip to content

Commit fcaf910

Browse files
committed
Merged revisions 63955 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r63955 | ronald.oussoren | 2008-06-05 14:58:24 +0200 (Thu, 05 Jun 2008) | 20 lines MacOS X: Enable 4-way universal builds This patch adds a new configure argument on OSX: --with-universal-archs=[32-bit|64-bit|all] When used with the --enable-universalsdk option this controls which CPU architectures are includes in the framework. The default is 32-bit, meaning i386 and ppc. The most useful alternative is 'all', which includes all 4 CPU architectures supported by MacOS X (i386, ppc, x86_64 and ppc64). This includes limited support for the Carbon bindings in 64-bit mode as well, limited because (a) I haven't done extensive testing and (b) a large portion of the Carbon API's aren't available in 64-bit mode anyway. I've also duplicated a feature of Apple's build of python: setting the environment variable 'ARCHFLAGS' controls the '-arch' flags used for building extensions using distutils. ........
1 parent 26adf52 commit fcaf910

File tree

14 files changed

+321
-51
lines changed

14 files changed

+321
-51
lines changed

Include/Python.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "patchlevel.h"
88
#include "pyconfig.h"
9+
#include "pymacconfig.h"
910

1011
#include <limits.h>
1112

Include/pymacconfig.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef PYMACCONFIG_H
2+
#define PYMACCONFIG_H
3+
/*
4+
* This file moves some of the autoconf magic to compile-time
5+
* when building on MacOSX. This is needed for building 4-way
6+
* universal binaries and for 64-bit universal binaries because
7+
* the values redefined below aren't configure-time constant but
8+
* only compile-time constant in these scenarios.
9+
*/
10+
11+
#if defined(__APPLE__)
12+
13+
# undef SIZEOF_LONG
14+
# undef SIZEOF_PTHREAD_T
15+
# undef SIZEOF_SIZE_T
16+
# undef SIZEOF_TIME_T
17+
# undef SIZEOF_VOID_P
18+
19+
# undef VA_LIST_IS_ARRAY
20+
# if defined(__LP64__) && defined(__x86_64__)
21+
# define VA_LIST_IS_ARRAY 1
22+
# endif
23+
24+
# undef HAVE_LARGEFILE_SUPPORT
25+
# ifndef __LP64__
26+
# define HAVE_LARGEFILE_SUPPORT 1
27+
# endif
28+
29+
# undef SIZEOF_LONG
30+
# ifdef __LP64__
31+
# define SIZEOF_LONG 8
32+
# define SIZEOF_PTHREAD_T 8
33+
# define SIZEOF_SIZE_T 8
34+
# define SIZEOF_TIME_T 8
35+
# define SIZEOF_VOID_P 8
36+
# else
37+
# define SIZEOF_LONG 4
38+
# define SIZEOF_PTHREAD_T 4
39+
# define SIZEOF_SIZE_T 4
40+
# define SIZEOF_TIME_T 4
41+
# define SIZEOF_VOID_P 4
42+
# endif
43+
44+
# if defined(__LP64__)
45+
/* MacOSX 10.4 (the first release to suppport 64-bit code
46+
* at all) only supports 64-bit in the UNIX layer.
47+
* Therefore surpress the toolbox-glue in 64-bit mode.
48+
*/
49+
50+
/* In 64-bit mode setpgrp always has no argments, in 32-bit
51+
* mode that depends on the compilation environment
52+
*/
53+
# undef SETPGRP_HAVE_ARG
54+
55+
# endif
56+
57+
#endif /* defined(_APPLE__) */
58+
59+
#endif /* PYMACCONFIG_H */

Lib/distutils/sysconfig.py

+20
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,26 @@ def get_config_vars(*args):
516516
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
517517
_config_vars[key] = flags
518518

519+
else:
520+
521+
# Allow the user to override the architecture flags using
522+
# an environment variable.
523+
# NOTE: This name was introduced by Apple in OSX 10.5 and
524+
# is used by several scripting languages distributed with
525+
# that OS release.
526+
527+
if 'ARCHFLAGS' in os.environ:
528+
arch = os.environ['ARCHFLAGS']
529+
for key in ('LDFLAGS', 'BASECFLAGS',
530+
# a number of derived variables. These need to be
531+
# patched up as well.
532+
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
533+
534+
flags = _config_vars[key]
535+
flags = re.sub('-arch\s+\w+\s', ' ', flags)
536+
flags = flags + ' ' + arch
537+
_config_vars[key] = flags
538+
519539
if args:
520540
vals = []
521541
for name in args:

Lib/distutils/unixccompiler.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
6363
stripArch = '-arch' in cc_args
6464
stripSysroot = '-isysroot' in cc_args
6565

66-
if stripArch:
66+
if stripArch or 'ARCHFLAGS' in os.environ:
6767
while True:
6868
try:
6969
index = compiler_so.index('-arch')
@@ -72,6 +72,12 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
7272
except ValueError:
7373
break
7474

75+
if 'ARCHFLAGS' in os.environ and not stripArch:
76+
# User specified different -arch flags in the environ,
77+
# see also distutils.sysconfig
78+
compiler_so = compiler_so + ' ' + os.environ['ARCHFLAGS']
79+
80+
7581
if stripSysroot:
7682
try:
7783
index = compiler_so.index('-isysroot')

Lib/distutils/util.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,19 @@ def get_platform ():
124124
osname = "macosx"
125125

126126

127-
if (release + '.') < '10.4.' and \
128-
get_config_vars().get('UNIVERSALSDK', '').strip():
127+
if (release + '.') >= '10.4.' and \
128+
'-arch' in get_config_vars().get('CFLAGS', '').strip():
129129
# The universal build will build fat binaries, but not on
130130
# systems before 10.4
131+
#
132+
# Try to detect 4-way universal builds, those have machine-type
133+
# 'universal' instead of 'fat'.
134+
131135
machine = 'fat'
132136

137+
if '-arch x86_64' in get_config_vars().get('CFLAGS'):
138+
machine = 'universal'
139+
133140
elif machine in ('PowerPC', 'Power_Macintosh'):
134141
# Pick a sane name for the PPC architecture.
135142
machine = 'ppc'

Lib/test/test_macos.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
import MacOS
3+
import Carbon.File
4+
from test import test_support
5+
import os
6+
7+
TESTFN2 = test_support.TESTFN + '2'
8+
9+
class TestMacOS(unittest.TestCase):
10+
11+
def testOpenRF(self):
12+
try:
13+
fp = open(test_support.TESTFN, 'w')
14+
fp.write('hello world\n')
15+
fp.close()
16+
17+
rfp = MacOS.openrf(test_support.TESTFN, '*wb')
18+
rfp.write('goodbye world\n')
19+
rfp.close()
20+
21+
22+
fp = open(test_support.TESTFN, 'r')
23+
data = fp.read()
24+
fp.close()
25+
self.assertEquals(data, 'hello world\n')
26+
27+
rfp = MacOS.openrf(test_support.TESTFN, '*rb')
28+
data = rfp.read(100)
29+
data2 = rfp.read(100)
30+
rfp.close()
31+
self.assertEquals(data, 'goodbye world\n')
32+
self.assertEquals(data2, '')
33+
34+
35+
finally:
36+
os.unlink(test_support.TESTFN)
37+
38+
def test_main():
39+
test_support.run_unittest(TestMacOS)
40+
41+
42+
if __name__ == '__main__':
43+
test_main()

Mac/IDLE/idlemain.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# Make sure sys.executable points to the python interpreter inside the
1414
# framework, instead of at the helper executable inside the application
1515
# bundle (the latter works, but doesn't allow access to the window server)
16-
sys.executable = os.path.join(sys.prefix, 'bin', 'python')
16+
if sys.executable.endswith('-32'):
17+
sys.executable = os.path.join(sys.prefix, 'bin', 'python-32')
18+
else:
19+
sys.executable = os.path.join(sys.prefix, 'bin', 'python')
1720

1821
# Look for the -psn argument that the launcher adds and remove it, it will
1922
# only confuse the IDLE startup code.

Mac/Makefile.in

+57-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,42 @@ compileall=$(srcdir)/../Lib/compileall.py
4848
installapps: install_PythonLauncher install_IDLE checkapplepython install_pythonw \
4949
install_versionedtools
5050

51+
installapps4way: install_Python4way install_BuildApplet install_PythonLauncher install_IDLE install_pythonw4way install_versionedtools
52+
53+
5154
install_pythonw: pythonw
5255
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)"
5356
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/python$(VERSION)"
5457
ln -sf python$(VERSION) "$(DESTDIR)$(prefix)/bin/python"
5558
ln -sf pythonw$(VERSION) "$(DESTDIR)$(prefix)/bin/pythonw"
5659

60+
61+
# Install 3 variants of python/pythonw:
62+
# - 32-bit (i386 and ppc)
63+
# - 64-bit (x86_64 and ppc64)
64+
# - all (all four architectures)
65+
# - Make 'python' and 'pythonw' aliases for the 32-bit variant
66+
install_pythonw4way: pythonw-32 pythonw-64 pythonw
67+
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-64 "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)-64"
68+
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-64 "$(DESTDIR)$(prefix)/bin/python$(VERSION)-64"
69+
ln -sf python$(VERSION)-64 "$(DESTDIR)$(prefix)/bin/python-64"
70+
ln -sf pythonw$(VERSION)-64 "$(DESTDIR)$(prefix)/bin/pythonw-64"
71+
72+
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-32 "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)-32"
73+
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-32 "$(DESTDIR)$(prefix)/bin/python$(VERSION)-32"
74+
ln -sf python$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/python-32"
75+
ln -sf pythonw$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/pythonw-32"
76+
77+
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)-all"
78+
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/python$(VERSION)-all"
79+
ln -sf python$(VERSION)-all "$(DESTDIR)$(prefix)/bin/python-all"
80+
ln -sf pythonw$(VERSION)-all "$(DESTDIR)$(prefix)/bin/pythonw-all"
81+
82+
ln -sf pythonw$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)"
83+
ln -sf python$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/python$(VERSION)"
84+
ln -sf pythonw$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/pythonw"
85+
ln -sf python$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/python"
86+
5787
#
5888
# Install unix tools in /usr/local/bin. These are just aliases for the
5989
# actual installation inside the framework.
@@ -64,11 +94,16 @@ installunixtools:
6494
fi
6595
for fn in python pythonw idle pydoc python-config smtpd.py \
6696
python$(VERSION) pythonw$(VERSION) idle$(VERSION) \
67-
pydoc$(VERSION) python-config$(VERSION) smtpd$(VERSION).py ;\
97+
pydoc$(VERSION) python$(VERSION)-config smtpd$(VERSION).py ;\
6898
do \
6999
ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\
70100
done
71101

102+
103+
# TODO: install symlinks for -32, -64 and -all as well
104+
installunixtools4way: installunixtools
105+
106+
72107
#
73108
# Like installunixtools, but only install links to the versioned binaries.
74109
#
@@ -77,25 +112,31 @@ altinstallunixtools:
77112
$(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ;\
78113
fi
79114
for fn in python$(VERSION) pythonw$(VERSION) idle$(VERSION) \
80-
pydoc$(VERSION) python-config$(VERSION) smtpd$(VERSION).py ;\
115+
pydoc$(VERSION) python$(VERSION)-config) smtpd$(VERSION).py ;\
81116
do \
82117
ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\
83118
done
84119

120+
# TODO: -32, -64 and -all variants
121+
altinstallunixtools4way: altinstallunixtools
85122

86123
# By default most tools are installed without a version in their basename, to
87124
# make it easier to install (and use) several python versions side-by-side move
88125
# the tools to a version-specific name and add the non-versioned name as an
89126
# alias.
90127
install_versionedtools:
91-
for fn in idle pydoc python-config ;\
128+
for fn in idle pydoc ;\
92129
do \
93130
if [ -h "$(DESTDIR)$(prefix)/bin/$${fn}" ]; then \
94131
continue ;\
95132
fi ;\
96133
mv "$(DESTDIR)$(prefix)/bin/$${fn}" "$(DESTDIR)$(prefix)/bin/$${fn}$(VERSION)" ;\
97134
ln -sf "$${fn}$(VERSION)" "$(DESTDIR)$(prefix)/bin/$${fn}" ;\
98135
done
136+
if [ ! -h "$(DESTDIR)$(prefix)/bin/python-config" ]; then \
137+
mv "$(DESTDIR)$(prefix)/bin/python-config" "$(DESTDIR)$(prefix)/bin/python$(VERSION)-config" ;\
138+
ln -sf "python$(VERSION)-config" "$(DESTDIR)$(prefix)/bin/python-config" ; \
139+
fi
99140
if [ ! -h "$(DESTDIR)$(prefix)/bin/smtpd.py" ]; then \
100141
mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py" ;\
101142
ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py" ;\
@@ -106,6 +147,13 @@ pythonw: $(srcdir)/Tools/pythonw.c Makefile
106147
$(CC) $(LDFLAGS) -o $@ $(srcdir)/Tools/pythonw.c \
107148
-DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"'
108149

150+
pythonw-32: $(srcdir)/Tools/pythonw.c Makefile
151+
$(CC) $(LDFLAGS) -o $@ -arch i386 -arch ppc $(srcdir)/Tools/pythonw.c \
152+
-DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-32"'
153+
154+
pythonw-64: $(srcdir)/Tools/pythonw.c Makefile
155+
$(CC) $(LDFLAGS) -o $@ -arch x86_64 -arch ppc64 $(srcdir)/Tools/pythonw.c \
156+
-DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-64"'
109157

110158
install_PythonLauncher:
111159
cd PythonLauncher && make install DESTDIR=$(DESTDIR)
@@ -158,6 +206,12 @@ install_Python:
158206
done
159207
$(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
160208

209+
install_Python4way: install_Python
210+
lipo -extract i386 -extract ppc7400 -output "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-32" "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
211+
lipo -extract x86_64 -extract ppc64 -output "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-64" "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
212+
213+
214+
161215
install_IDLE:
162216
test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)"
163217
-test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app"

Makefile.pre.in

+11-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
428428
$(RESSRCDIR)/Info.plist
429429
$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)
430430
if test "${UNIVERSALSDK}"; then \
431-
$(CC) -o $(LDLIBRARY) -arch i386 -arch ppc -dynamiclib \
431+
$(CC) -o $(LDLIBRARY) @UNIVERSAL_ARCH_FLAGS@ -dynamiclib \
432432
-isysroot "${UNIVERSALSDK}" \
433433
-all_load $(LIBRARY) -Wl,-single_module \
434434
-install_name $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK) \
@@ -1031,13 +1031,22 @@ frameworkinstallmaclib:
10311031
frameworkinstallapps:
10321032
cd Mac && $(MAKE) installapps DESTDIR="$(DESTDIR)"
10331033

1034+
frameworkinstallapps4way:
1035+
cd Mac && $(MAKE) installapps4way DESTDIR="$(DESTDIR)"
1036+
10341037
# This install the unix python and pythonw tools in /usr/local/bin
10351038
frameworkinstallunixtools:
10361039
cd Mac && $(MAKE) installunixtools DESTDIR="$(DESTDIR)"
10371040

1041+
frameworkinstallunixtools4way:
1042+
cd Mac && $(MAKE) installunixtools4way DESTDIR="$(DESTDIR)"
1043+
10381044
frameworkaltinstallunixtools:
10391045
cd Mac && $(MAKE) altinstallunixtools DESTDIR="$(DESTDIR)"
10401046

1047+
frameworkaltinstallunixtools4way:
1048+
cd Mac && $(MAKE) altinstallunixtools4way DESTDIR="$(DESTDIR)"
1049+
10411050
# This installs the Demos and Tools into the applications directory.
10421051
# It is not part of a normal frameworkinstall
10431052
frameworkinstallextras:
@@ -1182,7 +1191,7 @@ funny:
11821191

11831192
# Perform some verification checks on any modified files.
11841193
check:
1185-
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/patchcheck.py
1194+
$(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/patchcheck.py
11861195

11871196
# Dependencies
11881197

Modules/_ctypes/cfield.c

+1
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,7 @@ ffi_type ffi_type_double = { sizeof(double), DOUBLE_ALIGN, FFI_TYPE_DOUBLE };
17781778
#ifdef ffi_type_longdouble
17791779
#undef ffi_type_longdouble
17801780
#endif
1781+
/* This is already defined on OSX */
17811782
ffi_type ffi_type_longdouble = { sizeof(long double), LONGDOUBLE_ALIGN,
17821783
FFI_TYPE_LONGDOUBLE };
17831784

Modules/_ctypes/libffi_osx/x86/x86-darwin.S

+1-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ epilogue:
179179
movl %ebp,%esp
180180
popl %ebp
181181
ret
182-
.LFE1:
183182
.ffi_call_SYSV_end:
184183
#if 0
185184
.size ffi_call_SYSV,.ffi_call_SYSV_end-ffi_call_SYSV
@@ -220,7 +219,7 @@ epilogue:
220219
#else
221220
.long .LFB1 /* FDE initial location */
222221
#endif
223-
.long .LFE1-.LFB1 /* FDE address range */
222+
.long .ffi_call_SYSV_end-.LFB1 /* FDE address range */
224223
#ifdef __PIC__
225224
.byte 0x0 /* .uleb128 0x0; Augmentation size */
226225
#endif

0 commit comments

Comments
 (0)