[Pythonmac-SIG] building universal binaries

Bob Ippolito bob at redivi.com
Fri Feb 3 05:23:29 CET 2006


On Jan 27, 2006, at 8:31 AM, Ronald Oussoren wrote:

>
> On 27-jan-2006, at 16:38, bear wrote:
>
>> Ronald Oussoren wrote:
>>>
>>> On 27-jan-2006, at 4:22, bear wrote:
>>>
>>>> Ronald Oussoren wrote:
>>>>> That part is easy enough. If you want a framework build you'll  
>>>>> have to patch Makefile.pre.in because it contains a hardcoded '- 
>>>>> arch ppc' in the section that builds that actual framework.  
>>>>> Otherwise it should just build (assuming you have an intel mac  
>>>>> of course, cross-building from PPC to Intel will be hard  
>>>>> because the build process assumes you'll do a native build).
>>>> ok, I found the relevant part in configure (and cofigure.in)  
>>>> that was putting -arch_only ppc into the Makefile and I've re- 
>>>> run configure and it seems happy - heck, even the compiling ran  
>>>> error free.
>>>>
>>>> But when it got to the link part - I get the following error:
>>>
>>> You must replace the -arch ppc part by -arch i386. If you want to  
>>> build a universal binary you'll have to replace the call to  
>>> libtool by something more complex. I'll see if I can produce a  
>>> patch later today.
>> Coolness - I was able to get a clean build of python for the i386  
>> arch just now.  I did have to apply a patch to Lib/plat-mac/ 
>> applesingle.py so that it would run without errors.  I got the  
>> required patch from http://www.opensource.apple.com/darwinsource/ 
>> tarballs/other/python-16.tar.gz that Kevin mentioned in an earlier  
>> post to this thread.
>>
>> Now to build the rest of our app and see how it fairs ;)
>>
>
> From my Makefile.pre.in:
---
> This is very ugly. As you have noted you can't just drop -arch ppc  
> because libtool than assumes that you want to do a 3-way universal  
> build. Probably because libSystem contains a ppc64 binary.
>
> I hope to have a script for building a "batteries included"  
> universal build of python by the end of this weekend.

I've made a private branch of python24-maint via SVK that's probably  
most of the way there.  It fixes a couple of the endian issues in the  
Mac modules (platform.mac_ver, applesingle, gestalt, and the OSType  
converter functions) and fixes enough of the configure/make/autoconf  
crap so that it cleanly builds on either ppc or i386 (with just one  
compiler, and not yet universal):

http://svn.red-bean.com/bob/python24-fat

I think removed all the -arch flags from everywhere, and it does  
intelligently build a fat library at the end (with one arch), so  
assuming you can stuff the CCFLAGS/LDFLAGS in it'll probably build  
universal properly (using CCFLAGS/LDFLAGS environment variables are  
apparently not useful for Python as-is... I'll probably try and fix  
that).

Rather than work around libtool, I went the Xcode approach and  
dropped it from the build process altogether in exchange for just cc  
and lipo.  It uses lipo to determine which architectures are in the  
static library that was built.  The Makefile.pre.in in my branch  
looks like this:

	if test -x /usr/bin/lipo; then \
		Z="" ;\
		for X in `lipo -info $(LIBRARY) | cut -f 3 -s -d :`; do \
			Z="$$Z $(LDLIBRARY).libtool.$$X" ;\
			$(CC) -o $(LDLIBRARY).libtool.$$X -arch $$X -dynamiclib \
				-all_load $(LIBRARY) -Wl,-single_module \
				-install_name $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/$ 
(VERSION)/Python \
				-compatibility_version $(VERSION) \
				-current_version $(VERSION) ;\
			LIPO_FILES="$(LIPO_FILES) $(LDLIBRARY).libtool.$(ARCH)" ;\
		done ;\
		lipo -create$$Z -output $(LDLIBRARY) ;\
		rm -f$$Z ;\
	else\
		libtool -o $(LDLIBRARY) -dynamic $(OTHER_LIBTOOL_OPT) $(LIBRARY) - 
arch_only ppc \
			@LIBTOOL_CRUFT@ ;\
	fi


-bob



More information about the Pythonmac-SIG mailing list