diff -ru Python-3.1.4.orig/Lib/ctypes/macholib/dyld.py Python-3.1.4/Lib/ctypes/macholib/dyld.py
--- Python-3.1.4.orig/Lib/ctypes/macholib/dyld.py	2011-06-11 11:48:49.000000000 -0400
+++ Python-3.1.4/Lib/ctypes/macholib/dyld.py	2011-12-29 18:55:36.000000000 -0500
@@ -23,6 +23,7 @@
 
 DEFAULT_LIBRARY_FALLBACK = [
     os.path.expanduser("~/lib"),
+    "@PREFIX@/lib",
     "/usr/local/lib",
     "/lib",
     "/usr/lib",
diff -ru Python-3.1.4.orig/Makefile.pre.in Python-3.1.4/Makefile.pre.in
--- Python-3.1.4.orig/Makefile.pre.in	2011-06-11 11:48:51.000000000 -0400
+++ Python-3.1.4/Makefile.pre.in	2011-12-29 18:54:50.000000000 -0500
@@ -445,8 +445,7 @@
 	fi
 
 libpython$(VERSION).dylib: $(LIBRARY_OBJS)
-	 $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
-		 
+	$(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) @LIBTOOL_CRUFT@ -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LDLAST)
 
 libpython$(VERSION).sl: $(LIBRARY_OBJS)
 	$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
@@ -789,7 +788,7 @@
 # Install the interpreter with $(VERSION) affixed
 # This goes into $(exec_prefix)
 altbininstall: $(BUILDPYTHON)
-	@for i in $(BINDIR) $(LIBDIR); \
+	@for i in $(BINDIR) $(LIBDIR) $(LIBPL); \
 	do \
 		if test ! -d $(DESTDIR)$$i; then \
 			echo "Creating directory $$i"; \
@@ -802,9 +801,9 @@
 		if test -n "$(DLLLIBRARY)" ; then \
 			$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
 		else \
-			$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
+			$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBPL)/$(INSTSONAME); \
 			if test $(LDLIBRARY) != $(INSTSONAME); then \
-				(cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \
+				(cd $(DESTDIR)$(LIBPL); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \
 			fi \
 		fi; \
 	else	true; \
@@ -815,7 +814,7 @@
 	then rm -f $(DESTDIR)$(BINDIR)/$(PYTHON)3$(EXE); \
 	else true; \
 	fi
-	(cd $(DESTDIR)$(BINDIR); $(LN) python$(VERSION)$(EXE) $(PYTHON)3$(EXE))
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) $(PYTHON)3$(EXE))
 	-rm -f $(DESTDIR)$(BINDIR)/python3-config
 	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-config python3-config)
 	-rm -f $(DESTDIR)$(LIBPC)/python3.pc
diff -ru Python-3.1.4.orig/Misc/python-config.in Python-3.1.4/Misc/python-config.in
--- Python-3.1.4.orig/Misc/python-config.in	2011-06-11 11:48:51.000000000 -0400
+++ Python-3.1.4/Misc/python-config.in	2011-12-29 18:54:50.000000000 -0500
@@ -45,9 +45,9 @@
 elif opt in ('--libs', '--ldflags'):
     libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
     libs.append('-lpython'+pyver)
-    # add the prefix/lib/pythonX.Y/config dir, but only if there is no
-    # shared library in prefix/lib/.
-    if opt == '--ldflags' and not getvar('Py_ENABLE_SHARED'):
+    # add the prefix/lib/pythonX.Y/config dir (fink keeps shared
+    # library there too)
+    if opt == '--ldflags':
         libs.insert(0, '-L' + getvar('LIBPL'))
     print(' '.join(libs))
 
diff -ru Python-3.1.4.orig/Misc/python.pc.in Python-3.1.4/Misc/python.pc.in
--- Python-3.1.4.orig/Misc/python.pc.in	2011-06-11 11:48:51.000000000 -0400
+++ Python-3.1.4/Misc/python.pc.in	2011-12-29 18:54:50.000000000 -0500
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=@exec_prefix@
-libdir=@libdir@
+libdir=@libdir@/python@VERSION@/config
 includedir=@includedir@
 
 Name: Python
diff -ru Python-3.1.4.orig/Modules/_dbmmodule.c Python-3.1.4/Modules/_dbmmodule.c
--- Python-3.1.4.orig/Modules/_dbmmodule.c	2011-06-11 11:48:51.000000000 -0400
+++ Python-3.1.4/Modules/_dbmmodule.c	2011-12-29 18:54:50.000000000 -0500
@@ -20,7 +20,7 @@
 static char *which_dbm = "GNU gdbm";  /* EMX port of GDBM */
 #endif
 #elif defined(HAVE_GDBM_NDBM_H)
-#include <gdbm/ndbm.h>
+#include <ndbm.h>
 static char *which_dbm = "GNU gdbm";
 #elif defined(HAVE_GDBM_DASH_NDBM_H)
 #include <gdbm-ndbm.h>
diff -ru Python-3.1.4.orig/Modules/posixmodule.c Python-3.1.4/Modules/posixmodule.c
--- Python-3.1.4.orig/Modules/posixmodule.c	2011-06-11 11:48:52.000000000 -0400
+++ Python-3.1.4/Modules/posixmodule.c	2011-12-29 18:54:50.000000000 -0500
@@ -445,7 +445,7 @@
 #endif
 
 /* Return a dictionary corresponding to the POSIX environment table */
-#ifdef WITH_NEXT_FRAMEWORK
+#ifdef __APPLE__
 /* On Darwin/MacOSX a shared library or framework has no access to
 ** environ directly, we must obtain it with _NSGetEnviron().
 */
@@ -472,7 +472,7 @@
     d = PyDict_New();
     if (d == NULL)
         return NULL;
-#ifdef WITH_NEXT_FRAMEWORK
+#ifdef __APPLE__
     if (environ == NULL)
         environ = *_NSGetEnviron();
 #endif
diff -ru Python-3.1.4.orig/configure Python-3.1.4/configure
--- Python-3.1.4.orig/configure	2011-06-11 11:48:52.000000000 -0400
+++ Python-3.1.4/configure	2011-12-29 18:54:50.000000000 -0500
@@ -4883,7 +4883,7 @@
 	  ;;
     Darwin*)
     	LDLIBRARY='libpython$(VERSION).dylib'
-	BLDLIBRARY='-L. -lpython$(VERSION)'
+	BLDLIBRARY="$LDLIBRARY"
 	RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}'
 	;;
     AIX*)
@@ -7451,8 +7451,8 @@
 	#ARCH_RUN_32BIT="true"
     fi
 
-    LIBTOOL_CRUFT=$LIBTOOL_CRUFT" -lSystem -lSystemStubs -arch_only ${MACOSX_DEFAULT_ARCH}"
-    LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
+    LIBTOOL_CRUFT=$LIBTOOL_CRUFT" -lSystem -lSystemStubs"
+    LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(BINLIBDEST)/config/$(INSTSONAME)'
     LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -compatibility_version $(VERSION) -current_version $(VERSION)';;
 esac
 
@@ -7586,14 +7586,6 @@
 		# Use -undefined dynamic_lookup whenever possible (10.3 and later).
 		# This allows an extension to be used in any Python
 
-		if test ${MACOSX_DEPLOYMENT_TARGET} '>' 10.2
-		then
-			if test "${enable_universalsdk}"; then
-				LDFLAGS="${UNIVERSAL_ARCH_FLAGS} -isysroot ${UNIVERSALSDK} ${LDFLAGS}"
-			fi
-			LDSHARED='$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup'
-			BLDSHARED="$LDSHARED"
-		else
 			LDSHARED='$(CC) $(LDFLAGS) -bundle'
 			if test "$enable_framework" ; then
 				# Link against the framework. All externals should be defined.
@@ -7601,10 +7593,9 @@
 				LDSHARED="$LDSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
 			else
 				# No framework, use the Python app as bundle-loader
-				BLDSHARED="$LDSHARED "'-bundle_loader $(BUILDPYTHON)'
-				LDSHARED="$LDSHARED "'-bundle_loader $(BINDIR)/python$(VERSION)$(EXE)'
+				BLDSHARED="$LDSHARED "'$(BLDLIBRARY)'
+				LDSHARED="$LDSHARED "'-L$(BINLIBDEST)/config -lpython$(VERSION)'
 			fi
-		fi
 		;;
 	Linux*|GNU*|QNX*) LDSHARED='$(CC) -shared';;
 	BSD/OS*/4*) LDSHARED="gcc -shared";;
@@ -13443,7 +13434,7 @@
 
 if test $ac_sys_system = Darwin
 then
-	LIBS="$LIBS -framework CoreFoundation"
+	LIBS="$LIBS -Wl,-framework,CoreFoundation"
 fi
 
 
diff -ru Python-3.1.4.orig/setup.py Python-3.1.4/setup.py
--- Python-3.1.4.orig/setup.py	2011-06-11 11:48:52.000000000 -0400
+++ Python-3.1.4/setup.py	2011-12-29 18:54:50.000000000 -0500
@@ -238,13 +238,17 @@
                                               longest, g))
 
         if missing:
+            num_missing=len(missing)
             print()
             print("Python build finished, but the necessary bits to build "
                    "these modules were not found:")
             print_three_column(missing)
             print("To find the necessary bits, look in setup.py in"
                   " detect_modules() for the module's name.")
+            print ("(Fink package build should have 2 missing)")
             print()
+            if num_missing != 2:
+                sys.exit(1)
 
         if self.failed:
             failed = self.failed[:]
@@ -252,6 +256,7 @@
             print("Failed to build these modules:")
             print_three_column(failed)
             print()
+            sys.exit(1)
 
     def build_extension(self, ext):
 
@@ -362,10 +367,8 @@
             os.unlink(tmpfile)
 
     def detect_modules(self):
-        # Ensure that /usr/local is always used
-        add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
-        add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
-        self.add_multiarch_paths()
+        add_dir_to_list(self.compiler.library_dirs, '@PREFIX@/lib')
+        add_dir_to_list(self.compiler.include_dirs, '@PREFIX@/include')
 
         # Add paths specified in the environment variables LDFLAGS and
         # CPPFLAGS for header and library files.
@@ -938,12 +939,7 @@
         # We hunt for #define SQLITE_VERSION "n.n.n"
         # We need to find >= sqlite version 3.0.8
         sqlite_incdir = sqlite_libdir = None
-        sqlite_inc_paths = [ '/usr/include',
-                             '/usr/include/sqlite',
-                             '/usr/include/sqlite3',
-                             '/usr/local/include',
-                             '/usr/local/include/sqlite',
-                             '/usr/local/include/sqlite3',
+        sqlite_inc_paths = [ '@PREFIX@/include'
                            ]
         MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
         MIN_SQLITE_VERSION = ".".join([str(x)
@@ -955,7 +951,7 @@
         if sys.platform == 'darwin':
             sysroot = macosx_sdk_root()
 
-        for d in inc_dirs + sqlite_inc_paths:
+        for d in sqlite_inc_paths:
             f = os.path.join(d, "sqlite3.h")
 
             if sys.platform == 'darwin' and is_macosx_sdk_path(d):
@@ -987,11 +983,9 @@
             sqlite_dirs_to_check = [
                 os.path.join(sqlite_incdir, '..', 'lib64'),
                 os.path.join(sqlite_incdir, '..', 'lib'),
-                os.path.join(sqlite_incdir, '..', '..', 'lib64'),
-                os.path.join(sqlite_incdir, '..', '..', 'lib'),
             ]
             sqlite_libfile = self.compiler.find_library_file(
-                                sqlite_dirs_to_check + lib_dirs, 'sqlite3')
+                                sqlite_dirs_to_check, 'sqlite3')
             if sqlite_libfile:
                 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
 
@@ -1067,7 +1061,7 @@
                         gdbm_libs = ['gdbm']
                         if self.compiler.find_library_file(lib_dirs, 'gdbm_compat'):
                             gdbm_libs.append('gdbm_compat')
-                        if find_file("gdbm/ndbm.h", inc_dirs, []) is not None:
+                        if find_file("ndbm.h", inc_dirs, []) is not None:
                             print("building dbm using gdbm")
                             dbmext = Extension(
                                 '_dbm', ['_dbmmodule.c'],
@@ -1145,6 +1139,7 @@
                 panel_library = 'panelw'
             curses_libs = [curses_library]
             exts.append( Extension('_curses', ['_cursesmodule.c'],
+                                   include_dirs=["@PREFIX@/include/ncursesw"],
                                    libraries = curses_libs) )
         elif curses_library == 'curses' and platform != 'darwin':
                 # OSX has an old Berkeley curses, not good enough for
@@ -1165,6 +1160,7 @@
         if (module_enabled(exts, '_curses') and
             self.compiler.find_library_file(lib_dirs, panel_library)):
             exts.append( Extension('_curses_panel', ['_curses_panel.c'],
+                                   include_dirs=["@PREFIX@/include/ncursesw"],
                                    libraries = [panel_library] + curses_libs) )
         else:
             missing.append('_curses_panel')
@@ -1470,16 +1466,12 @@
         # AquaTk is a separate method. Only one Tkinter will be built on
         # Darwin - either AquaTk, if it is found, or X11 based Tk.
         platform = self.get_platform()
-        if (platform == 'darwin' and
-            self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
-            return
 
         # Assume we haven't found any of the libraries or include files
         # The versions with dots are used on Unix, and the versions without
         # dots on Windows, for detection by cygwin.
         tcllib = tklib = tcl_includes = tk_includes = None
-        for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
-                        '8.2', '82', '8.1', '81', '8.0', '80']:
+        for version in ['8.4']:
             tklib = self.compiler.find_library_file(lib_dirs, 'tk' + version)
             tcllib = self.compiler.find_library_file(lib_dirs, 'tcl' + version)
             if tklib and tcllib:
@@ -1701,7 +1693,8 @@
                         sources=sources,
                         depends=depends)
         ext_test = Extension('_ctypes_test',
-                             sources=['_ctypes/_ctypes_test.c'])
+                             sources=['_ctypes/_ctypes_test.c'],
+                             extra_compile_args=['-O0'])
         self.extensions.extend([ext, ext_test])
 
         if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
