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/Include/Python.h b/Include/Python.h
index 612bfb7..35a8bca 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -1,11 +1,11 @@
-#ifndef Py_PYTHON_H
-#define Py_PYTHON_H
+#ifndef Py_PYTHON_H #define Py_PYTHON_H
 /* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
 
 /* Include nearly all Python header files */
 
 #include "patchlevel.h"
 #include "pyconfig.h"
+#include "pymacconfig.h"
 
 /* Cyclic gc is always enabled, starting with release 2.3a1.  Supply the
  * old symbol for the benefit of extension modules written before then
diff --git a/Include/pymacconfig.h b/Include/pymacconfig.h
new file mode 100644
index 0000000..e864e72
--- /dev/null
+++ b/Include/pymacconfig.h
@@ -0,0 +1,59 @@
+#ifndef PYMACCONFIG_H
+#define PYMACCONFIG_H
+     /*
+      * This file moves some of the autoconf magic to compile-time
+      * when building on MacOSX. This is needed for building 4-way
+      * universal binaries and for 64-bit universal binaries because
+      * the values redefined below aren't configure-time constant but 
+      * only compile-time constant in these scenarios.
+      */
+
+#if defined(__APPLE__)
+
+# undef SIZEOF_LONG
+# undef SIZEOF_PTHREAD_T
+# undef SIZEOF_SIZE_T
+# undef SIZEOF_TIME_T
+# undef SIZEOF_VOID_P
+
+#    undef VA_LIST_IS_ARRAY
+#    if defined(__LP64__) && defined(__x86_64__)
+#        define VA_LIST_IS_ARRAY 1
+#    endif
+
+#    undef HAVE_LARGEFILE_SUPPORT
+#    ifndef __LP64__
+#         define HAVE_LARGEFILE_SUPPORT 1
+#    endif
+
+#    undef SIZEOF_LONG
+#    ifdef __LP64__
+#        define SIZEOF_LONG 		8
+#        define SIZEOF_PTHREAD_T 	8
+#        define SIZEOF_SIZE_T 		8
+#        define SIZEOF_TIME_T 		8
+#        define SIZEOF_VOID_P 		8
+#    else
+#        define SIZEOF_LONG 		4
+#        define SIZEOF_PTHREAD_T 	4
+#        define SIZEOF_SIZE_T 		4
+#        define SIZEOF_TIME_T 		4
+#        define SIZEOF_VOID_P 		4
+#    endif
+
+#    if defined(__LP64__)
+	 /* MacOSX 10.4 (the first release to suppport 64-bit code
+	  * at all) only supports 64-bit in the UNIX layer. 
+	  * Therefore surpress the toolbox-glue in 64-bit mode.
+	  */
+
+	/* In 64-bit mode setpgrp always has no argments, in 32-bit
+	 * mode that depends on the compilation environment
+	 */
+#	undef SETPGRP_HAVE_ARG
+
+#    endif
+
+#endif /* defined(_APPLE__) */
+
+#endif /* PYMACCONFIG_H */
diff --git a/Include/pymactoolbox.h b/Include/pymactoolbox.h
index 92799e9..fd15975 100644
--- a/Include/pymactoolbox.h
+++ b/Include/pymactoolbox.h
@@ -8,7 +8,10 @@
 #endif
 
 #include <Carbon/Carbon.h>
+
+#ifndef __LP64__
 #include <QuickTime/QuickTime.h>
+#endif /* !__LP64__ */
 
 /*
 ** Helper routines for error codes and such.
@@ -18,8 +21,11 @@
 PyObject *PyMac_GetOSErrException(void);	/* Initialize & return it */
 PyObject *PyErr_Mac(PyObject *, int);		/* Exception with a mac error */
 PyObject *PyMac_Error(OSErr);			/* Uses PyMac_GetOSErrException */
+#ifndef __LP64__ 
 extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert
 							      fsspec->path */
+#endif /* __LP64__ */
+
 /*
 ** These conversion routines are defined in mactoolboxglue.c itself.
 */
@@ -83,8 +89,10 @@
 #endif /* USE_TOOLBOX_OBJECT_GLUE */
 
 /* macfs exports */
+#ifndef __LP64__
 int PyMac_GetFSSpec(PyObject *, FSSpec *);	/* argument parser for FSSpec */
 PyObject *PyMac_BuildFSSpec(FSSpec *);		/* Convert FSSpec to PyObject */
+#endif /* !__LP64__ */
 
 int PyMac_GetFSRef(PyObject *, FSRef *);	/* argument parser for FSRef */
 PyObject *PyMac_BuildFSRef(FSRef *);		/* Convert FSRef to PyObject */
@@ -101,39 +109,54 @@
 extern int CmpInstObj_Convert(PyObject *, ComponentInstance *);
 
 /* Ctl exports */
+#ifndef __LP64__
 extern PyObject *CtlObj_New(ControlHandle);
 extern int CtlObj_Convert(PyObject *, ControlHandle *);
+#endif /* !__LP64__ */
 
 /* Dlg exports */
+#ifndef __LP64__
 extern PyObject *DlgObj_New(DialogPtr);
 extern int DlgObj_Convert(PyObject *, DialogPtr *);
 extern PyObject *DlgObj_WhichDialog(DialogPtr);
+#endif /* !__LP64__ */
 
 /* Drag exports */
+#ifndef __LP64__
 extern PyObject *DragObj_New(DragReference);
 extern int DragObj_Convert(PyObject *, DragReference *);
+#endif /* !__LP64__ */
 
 /* List exports */
+#ifndef __LP64__
 extern PyObject *ListObj_New(ListHandle);
 extern int ListObj_Convert(PyObject *, ListHandle *);
+#endif /* !__LP64__ */
 
 /* Menu exports */
+#ifndef __LP64__
 extern PyObject *MenuObj_New(MenuHandle);
 extern int MenuObj_Convert(PyObject *, MenuHandle *);
+#endif /* !__LP64__ */
 
 /* Qd exports */
+#ifndef __LP64__
 extern PyObject *GrafObj_New(GrafPtr);
 extern int GrafObj_Convert(PyObject *, GrafPtr *);
 extern PyObject *BMObj_New(BitMapPtr);
 extern int BMObj_Convert(PyObject *, BitMapPtr *);
 extern PyObject *QdRGB_New(RGBColor *);
 extern int QdRGB_Convert(PyObject *, RGBColor *);
+#endif /* !__LP64__ */
 
 /* Qdoffs exports */
+#ifndef __LP64__
 extern PyObject *GWorldObj_New(GWorldPtr);
 extern int GWorldObj_Convert(PyObject *, GWorldPtr *);
+#endif /* !__LP64__ */
 
 /* Qt exports */
+#ifndef __LP64__
 extern PyObject *TrackObj_New(Track);
 extern int TrackObj_Convert(PyObject *, Track *);
 extern PyObject *MovieObj_New(Movie);
@@ -146,6 +169,7 @@
 extern int UserDataObj_Convert(PyObject *, UserData *);
 extern PyObject *MediaObj_New(Media);
 extern int MediaObj_Convert(PyObject *, Media *);
+#endif /* !__LP64__ */
 
 /* Res exports */
 extern PyObject *ResObj_New(Handle);
@@ -154,13 +178,17 @@
 extern int OptResObj_Convert(PyObject *, Handle *);
 
 /* TE exports */
+#ifndef __LP64__
 extern PyObject *TEObj_New(TEHandle);
 extern int TEObj_Convert(PyObject *, TEHandle *);
+#endif /* !__LP64__ */
 
 /* Win exports */
+#ifndef __LP64__
 extern PyObject *WinObj_New(WindowPtr);
 extern int WinObj_Convert(PyObject *, WindowPtr *);
 extern PyObject *WinObj_WhichWindow(WindowPtr);
+#endif /* !__LP64__ */
 
 /* CF exports */
 extern PyObject *CFObj_New(CFTypeRef);