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.
diff --git a/configure b/configure
index f6010ef..cded3b5 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 63545 .
+# From configure.in Revision: 63690 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 2.6.
 #
@@ -703,6 +703,7 @@
 LN
 OPT
 BASECFLAGS
+UNIVERSAL_ARCH_FLAGS
 OTHER_LIBTOOL_OPT
 LIBTOOL_CRUFT
 SO
@@ -1328,6 +1329,9 @@
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-universal-archs=ARCH
+                          select architectures for universal build ("32-bit",
+                          "64-bit" or "all")
   --with-framework-name=FRAMEWORK
                           specify an alternate name of the framework built
                           with --enable-framework
@@ -1850,6 +1854,16 @@
 _ACEOF
 
 
+# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
+# certain features on Mac OS X, so we need _DARWIN_C_SOURCE to re-enable
+# them.
+
+cat >>confdefs.h <<\_ACEOF
+#define _DARWIN_C_SOURCE 1
+_ACEOF
+
+
+
 define_xopen_source=yes
 
 # Arguments passed to configure.
@@ -1883,6 +1897,27 @@
 
 
 
+UNIVERSAL_ARCHS="32-bit"
+{ echo "$as_me:$LINENO: checking for --with-universal-archs" >&5
+echo $ECHO_N "checking for --with-universal-archs... $ECHO_C" >&6; }
+
+# Check whether --with-universal-archs was given.
+if test "${with_universal_archs+set}" = set; then
+  withval=$with_universal_archs;
+	{ echo "$as_me:$LINENO: result: $withval" >&5
+echo "${ECHO_T}$withval" >&6; }
+	UNIVERSAL_ARCHS="$withval"
+
+else
+
+ 	{ echo "$as_me:$LINENO: result: 32-bit" >&5
+echo "${ECHO_T}32-bit" >&6; }
+
+fi
+
+
+
+
 
 # Check whether --with-framework-name was given.
 if test "${with_framework_name+set}" = set; then
@@ -1927,9 +1962,14 @@
 		PYTHONFRAMEWORKPREFIX=$enableval
 		PYTHONFRAMEWORKINSTALLDIR=$PYTHONFRAMEWORKPREFIX/$PYTHONFRAMEWORKDIR
 		FRAMEWORKINSTALLFIRST="frameworkinstallstructure"
-		FRAMEWORKINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools"
-		FRAMEWORKALTINSTALLFIRST="${FRAMEWORKINSTALLFIRST} bininstall maninstall"
-		FRAMEWORKALTINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkaltinstallunixtools"
+		FRAMEWORKALTINSTALLFIRST="frameworkinstallstructure bininstall maninstall"
+		if test "$UNIVERSAL_ARCHS" = "all"
+		then
+			FRAMEWORKINSTALLLAST="frameworkinstallmaclib frameworkinstallapps4way frameworkinstallunixtools4way"
+		else
+			FRAMEWORKALTINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkaltinstallunixtools"
+		fi
+
 		if test "x${prefix}" = "xNONE" ; then
 			FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}"
 		else
@@ -1968,6 +2008,12 @@
 	fi
 	enable_framework=
 
+	if test "$UNIVERSAL_ARCHS" = "all"
+	then
+		FRAMEWORKINSTALLLAST=update4wayuniversal
+		FRAMEWORKALTINSTALLLAST=update4wayuniversal
+	fi
+
 fi
 
 
@@ -4509,6 +4555,11 @@
 fi
 
 
+
+# The -arch flags for universal builds on OSX
+UNIVERSAL_ARCH_FLAGS=
+
+
 # tweak BASECFLAGS based on compiler and platform
 case $GCC in
 yes)
@@ -4589,7 +4640,25 @@
 	    # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd
 	    # used to be here, but non-Apple gcc doesn't accept them.
 	    if test "${enable_universalsdk}"; then
-		BASECFLAGS="-arch ppc -arch i386 -isysroot ${UNIVERSALSDK} ${BASECFLAGS}"
+		UNIVERSAL_ARCH_FLAGS=""
+	        if test "$UNIVERSAL_ARCHS" = "32-bit" ; then
+		   UNIVERSAL_ARCH_FLAGS="-arch ppc -arch i386"
+
+	         elif test "$UNIVERSAL_ARCHS" = "64-bit" ; then
+		   UNIVERSAL_ARCH_FLAGS="-arch ppc64 -arch x86_64"
+
+	         elif test "$UNIVERSAL_ARCHS" = "all" ; then
+		   UNIVERSAL_ARCH_FLAGS="-arch i386 -arch ppc -arch ppc64 -arch x86_64"
+
+		 else
+	           { { echo "$as_me:$LINENO: error: proper usage is --with-universalarch=32-bit|64-bit|all" >&5
+echo "$as_me: error: proper usage is --with-universalarch=32-bit|64-bit|all" >&2;}
+   { (exit 1); exit 1; }; }
+
+		 fi
+
+
+		BASECFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${BASECFLAGS}"
 	    fi
 
 	    ;;
@@ -12500,6 +12569,12 @@
 		if test ${cur_target} '>' 10.2; then
 			cur_target=10.3
 		fi
+		if test "${UNIVERSAL_ARCHS}" = "all"; then
+			# Ensure that the default platform for a 4-way
+			# universal build is OSX 10.5, that's the first
+			# OS release where 4-way builds make sense.
+			cur_target='10.5'
+		fi
 		CONFIGURE_MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET-${cur_target}}
 
 		# Make sure that MACOSX_DEPLOYMENT_TARGET is set in the
@@ -12510,10 +12585,10 @@
 		export MACOSX_DEPLOYMENT_TARGET
 
 		EXPORT_MACOSX_DEPLOYMENT_TARGET=''
-		if test ${MACOSX_DEPLOYMENT_TARGET-${cur_target}} '>' 10.2
+		if test ${MACOSX_DEPLOYMENT_TARGET} '>' 10.2
 		then
 			if test "${enable_universalsdk}"; then
-				LDFLAGS="-arch i386 -arch ppc -isysroot ${UNIVERSALSDK} ${LDFLAGS}"
+				LDFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${LDFLAGS}"
 			fi
 			LDSHARED='$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup'
 			BLDSHARED="$LDSHARED"
@@ -22212,8 +22287,6 @@
 esac
 
 
-
-
 # Check whether right shifting a negative integer extends the sign bit
 # or fills with zeros (like the Cray J90, according to Tim Peters).
 { echo "$as_me:$LINENO: checking whether right shift extends the sign bit" >&5
@@ -24771,6 +24844,7 @@
 LN!$LN$ac_delim
 OPT!$OPT$ac_delim
 BASECFLAGS!$BASECFLAGS$ac_delim
+UNIVERSAL_ARCH_FLAGS!$UNIVERSAL_ARCH_FLAGS$ac_delim
 OTHER_LIBTOOL_OPT!$OTHER_LIBTOOL_OPT$ac_delim
 LIBTOOL_CRUFT!$LIBTOOL_CRUFT$ac_delim
 SO!$SO$ac_delim
@@ -24780,7 +24854,6 @@
 LINKFORSHARED!$LINKFORSHARED$ac_delim
 CFLAGSFORSHARED!$CFLAGSFORSHARED$ac_delim
 SHLIBS!$SHLIBS$ac_delim
-USE_SIGNAL_MODULE!$USE_SIGNAL_MODULE$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -24822,6 +24895,7 @@
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+USE_SIGNAL_MODULE!$USE_SIGNAL_MODULE$ac_delim
 SIGNAL_OBJS!$SIGNAL_OBJS$ac_delim
 USE_THREAD_MODULE!$USE_THREAD_MODULE$ac_delim
 LDLAST!$LDLAST$ac_delim
@@ -24844,7 +24918,7 @@
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 20; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 21; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5