diff -Nurd -x'*~' Python-2.6.7.orig/Lib/bsddb/test/test_basics.py Python-2.6.7/Lib/bsddb/test/test_basics.py
--- Python-2.6.7.orig/Lib/bsddb/test/test_basics.py	2010-08-02 16:19:21.000000000 -0400
+++ Python-2.6.7/Lib/bsddb/test/test_basics.py	2011-06-29 13:25:48.000000000 -0400
@@ -1000,11 +1000,12 @@
     #    # See http://bugs.python.org/issue3307
     #    self.assertRaises(db.DBInvalidArgError, db.DB, None, 65535)
 
-    def test02_DBEnv_dealloc(self):
-        # http://bugs.python.org/issue3885
-        import gc
-        self.assertRaises(db.DBInvalidArgError, db.DBEnv, ~db.DB_RPCCLIENT)
-        gc.collect()
+    if db.version() < (4, 8) :
+        def test02_DBEnv_dealloc(self):
+            # http://bugs.python.org/issue3885
+            import gc
+            self.assertRaises(db.DBInvalidArgError, db.DBEnv, ~db.DB_RPCCLIENT)
+            gc.collect()
 
 
 #----------------------------------------------------------------------
diff -Nurd -x'*~' Python-2.6.7.orig/Lib/bsddb/test/test_distributed_transactions.py Python-2.6.7/Lib/bsddb/test/test_distributed_transactions.py
--- Python-2.6.7.orig/Lib/bsddb/test/test_distributed_transactions.py	2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.7/Lib/bsddb/test/test_distributed_transactions.py	2011-06-29 13:25:48.000000000 -0400
@@ -35,7 +35,7 @@
                 db.DB_INIT_TXN | db.DB_INIT_LOG | db.DB_INIT_MPOOL |
                 db.DB_INIT_LOCK, 0666)
         self.db = db.DB(self.dbenv)
-        self.db.set_re_len(db.DB_XIDDATASIZE)
+        self.db.set_re_len(db.DB_GID_SIZE)
         if must_open_db :
             if db.version() > (4,1) :
                 txn=self.dbenv.txn_begin()
@@ -76,7 +76,7 @@
     # let them be garbage collected.
         for i in xrange(self.num_txns) :
             txn = self.dbenv.txn_begin()
-            gid = "%%%dd" %db.DB_XIDDATASIZE
+            gid = "%%%dd" %db.DB_GID_SIZE
             gid = adapt(gid %i)
             self.db.put(i, gid, txn=txn, flags=db.DB_APPEND)
             txns.add(gid)
diff -Nurd -x'*~' Python-2.6.7.orig/Lib/ctypes/macholib/dyld.py Python-2.6.7/Lib/ctypes/macholib/dyld.py
--- Python-2.6.7.orig/Lib/ctypes/macholib/dyld.py	2008-02-21 13:52:20.000000000 -0500
+++ Python-2.6.7/Lib/ctypes/macholib/dyld.py	2012-01-02 14:40:32.000000000 -0500
@@ -26,6 +26,7 @@
 
 DEFAULT_LIBRARY_FALLBACK = [
     os.path.expanduser("~/lib"),
+    "@PREFIX@/lib",
     "/usr/local/lib",
     "/lib",
     "/usr/lib",
diff -Nurd -x'*~' Python-2.6.7.orig/Lib/locale.py Python-2.6.7/Lib/locale.py
--- Python-2.6.7.orig/Lib/locale.py	2009-05-06 09:21:17.000000000 -0400
+++ Python-2.6.7/Lib/locale.py	2011-06-29 13:25:48.000000000 -0400
@@ -522,7 +522,7 @@
     """
     _setlocale(category, _build_localename(getdefaultlocale()))
 
-if sys.platform in ('win32', 'darwin', 'mac'):
+if sys.platform in ('win32', 'mac'):
     # On Win32, this will return the ANSI code page
     # On the Mac, it should return the system encoding;
     # it might return "ascii" instead
diff -Nurd -x'*~' Python-2.6.7.orig/Lib/platform.py Python-2.6.7/Lib/platform.py
--- Python-2.6.7.orig/Lib/platform.py	2010-08-03 04:09:15.000000000 -0400
+++ Python-2.6.7/Lib/platform.py	2011-06-29 13:25:48.000000000 -0400
@@ -730,7 +730,14 @@
         import gestalt
         import MacOS
     except ImportError:
-        return None
+        import posix
+        major,minor,patch=string.split(posix.uname()[2],'.')
+        release = '%s.%s.%s' %('10',int(major)-4, minor)
+        if posix.uname()[4]=='Power Macintosh':
+            machine='PowerPC'
+        else:
+            machine='i386'
+        return release,versioninfo,machine
     # Get the infos
     sysv,sysa = _mac_ver_lookup(('sysv','sysa'))
     # Decode the infos
diff -Nurd -x'*~' Python-2.6.7.orig/Makefile.pre.in Python-2.6.7/Makefile.pre.in
--- Python-2.6.7.orig/Makefile.pre.in	2010-08-01 18:05:31.000000000 -0400
+++ Python-2.6.7/Makefile.pre.in	2011-06-29 13:25:48.000000000 -0400
@@ -419,8 +419,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 @LIBTOOL_CRUFT@ -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LDLAST)
 
 libpython$(VERSION).sl: $(LIBRARY_OBJS)
 	$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
@@ -760,14 +759,14 @@
 	then rm -f $(DESTDIR)$(BINDIR)/$(PYTHON); \
 	else true; \
 	fi
-	(cd $(DESTDIR)$(BINDIR); $(LN) python$(VERSION)$(EXE) $(PYTHON))
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) $(PYTHON))
 	-rm -f $(DESTDIR)$(BINDIR)/python-config
 	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-config python-config)
 
 # 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"; \
@@ -780,9 +779,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; \
diff -Nurd -x'*~' Python-2.6.7.orig/Misc/python-config.in Python-2.6.7/Misc/python-config.in
--- Python-2.6.7.orig/Misc/python-config.in	2007-03-31 14:56:11.000000000 -0400
+++ Python-2.6.7/Misc/python-config.in	2011-06-29 13:25:48.000000000 -0400
@@ -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 -Nurd -x'*~' Python-2.6.7.orig/Modules/_bsddb.c Python-2.6.7/Modules/_bsddb.c
--- Python-2.6.7.orig/Modules/_bsddb.c	2010-05-09 11:15:40.000000000 -0400
+++ Python-2.6.7/Modules/_bsddb.c	2011-06-29 13:25:48.000000000 -0400
@@ -215,6 +215,10 @@
 #define DB_BUFFER_SMALL         ENOMEM
 #endif
 
+#if (DBVER < 48)
+#define DB_GID_SIZE DB_XIDDATASIZE
+#endif
+
 
 /* --------------------------------------------------------------------- */
 /* Structure definitions */
@@ -4501,7 +4505,11 @@
     DBTxnObject *txn;
 #define PREPLIST_LEN 16
     DB_PREPLIST preplist[PREPLIST_LEN];
+#if (DBVER < 48)
     long retp;
+#else
+    u_int32_t retp;
+#endif
 
     CHECK_ENV_NOT_CLOSED(self);
 
@@ -4522,7 +4530,7 @@
         flags=DB_NEXT;  /* Prepare for next loop pass */
         for (i=0; i<retp; i++) {
             gid=PyBytes_FromStringAndSize((char *)(preplist[i].gid),
-                                DB_XIDDATASIZE);
+                                DB_GID_SIZE);
             if (!gid) {
                 Py_DECREF(list);
                 return NULL;
@@ -5047,6 +5055,7 @@
 }
 
 
+#if (DBVER < 48)
 static PyObject*
 DBEnv_set_rpc_server(DBEnvObject* self, PyObject* args, PyObject* kwargs)
 {
@@ -5068,6 +5077,7 @@
     RETURN_IF_ERR();
     RETURN_NONE();
 }
+#endif
 
 static PyObject*
 DBEnv_set_verbose(DBEnvObject* self, PyObject* args)
@@ -5949,9 +5959,9 @@
     if (!PyArg_ParseTuple(args, "s#:prepare", &gid, &gid_size))
         return NULL;
 
-    if (gid_size != DB_XIDDATASIZE) {
+    if (gid_size != DB_GID_SIZE) {
         PyErr_SetString(PyExc_TypeError,
-                        "gid must be DB_XIDDATASIZE bytes long");
+                        "gid must be DB_GID_SIZE bytes long");
         return NULL;
     }
 
@@ -6541,8 +6551,10 @@
 #endif
     {"set_get_returns_none",(PyCFunction)DBEnv_set_get_returns_none, METH_VARARGS},
     {"txn_recover",     (PyCFunction)DBEnv_txn_recover,       METH_NOARGS},
+#if (DBVER < 48)
     {"set_rpc_server",  (PyCFunction)DBEnv_set_rpc_server,
         METH_VARARGS||METH_KEYWORDS},
+#endif
     {"set_verbose",     (PyCFunction)DBEnv_set_verbose,       METH_VARARGS},
 #if (DBVER >= 42)
     {"get_verbose",     (PyCFunction)DBEnv_get_verbose,       METH_VARARGS},
@@ -7091,6 +7103,7 @@
     ADD_INT(d, DB_MAX_PAGES);
     ADD_INT(d, DB_MAX_RECORDS);
 
+#if (DBVER < 48)
 #if (DBVER >= 42)
     ADD_INT(d, DB_RPCCLIENT);
 #else
@@ -7098,7 +7111,11 @@
     /* allow apps to be written using DB_RPCCLIENT on older Berkeley DB */
     _addIntToDict(d, "DB_RPCCLIENT", DB_CLIENT);
 #endif
+#endif
+
+#if (DBVER < 48)
     ADD_INT(d, DB_XA_CREATE);
+#endif
 
     ADD_INT(d, DB_CREATE);
     ADD_INT(d, DB_NOMMAP);
@@ -7115,7 +7132,13 @@
     ADD_INT(d, DB_INIT_TXN);
     ADD_INT(d, DB_JOINENV);
 
+#if (DBVER >= 48)
+    ADD_INT(d, DB_GID_SIZE);
+#else
     ADD_INT(d, DB_XIDDATASIZE);
+    /* Allow new code to work in old BDB releases */
+    _addIntToDict(d, "DB_GID_SIZE", DB_XIDDATASIZE);
+#endif
 
     ADD_INT(d, DB_RECOVER);
     ADD_INT(d, DB_RECOVER_FATAL);
diff -Nurd -x'*~' Python-2.6.7.orig/Modules/_localemodule.c Python-2.6.7/Modules/_localemodule.c
--- Python-2.6.7.orig/Modules/_localemodule.c	2010-05-09 11:15:40.000000000 -0400
+++ Python-2.6.7/Modules/_localemodule.c	2011-06-29 13:25:48.000000000 -0400
@@ -32,7 +32,7 @@
 #include <wchar.h>
 #endif
 
-#if defined(__APPLE__)
+#if 0
 #include <CoreFoundation/CoreFoundation.h>
 #endif
 
@@ -412,7 +412,7 @@
 }
 #endif
 
-#if defined(__APPLE__)
+#if 0
 /*
 ** Find out what the current script is.
 ** Donated by Fredrik Lundh.
@@ -689,7 +689,7 @@
    METH_VARARGS, strcoll__doc__},
   {"strxfrm", (PyCFunction) PyLocale_strxfrm,
    METH_VARARGS, strxfrm__doc__},
-#if defined(MS_WINDOWS) || defined(__APPLE__)
+#if defined(MS_WINDOWS) || 0
   {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS},
 #endif
 #ifdef HAVE_LANGINFO_H
diff -Nurd -x'*~' Python-2.6.7.orig/Modules/posixmodule.c Python-2.6.7/Modules/posixmodule.c
--- Python-2.6.7.orig/Modules/posixmodule.c	2010-07-24 06:05:19.000000000 -0400
+++ Python-2.6.7/Modules/posixmodule.c	2011-06-29 13:25:48.000000000 -0400
@@ -361,7 +361,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().
 */
@@ -383,7 +383,7 @@
     d = PyDict_New();
     if (d == NULL)
         return NULL;
-#ifdef WITH_NEXT_FRAMEWORK
+#ifdef __APPLE__ /* need to include shared-lib build setup for apple too */
     if (environ == NULL)
         environ = *_NSGetEnviron();
 #endif
diff -Nurd -x'*~' Python-2.6.7.orig/configure Python-2.6.7/configure
--- Python-2.6.7.orig/configure	2010-05-24 22:27:03.000000000 -0400
+++ Python-2.6.7/configure	2011-06-29 13:25:48.000000000 -0400
@@ -4771,7 +4771,7 @@
 	  ;;
     Darwin*)
     	LDLIBRARY='libpython$(VERSION).dylib'
-	BLDLIBRARY='-L. -lpython$(VERSION)'
+	BLDLIBRARY="$LDLIBRARY"
 	RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}'
 	;;
 
@@ -7228,7 +7228,8 @@
     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" -Wl,-framework,CoreFoundation"
+    LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(BINLIBDEST)/config/$(INSTSONAME)'
     LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -compatibility_version $(VERSION) -current_version $(VERSION)';;
 esac
 
@@ -7366,14 +7367,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.
@@ -7381,10 +7374,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";;
@@ -12845,7 +12837,7 @@
 
 if test $ac_sys_system = Darwin
 then
-	LIBS="$LIBS -framework CoreFoundation"
+	LIBS="$LIBS -Wl,-framework,CoreFoundation"
 fi
 
 
diff -Nurd -x'*~' Python-2.6.7.orig/setup.py Python-2.6.7/setup.py
--- Python-2.6.7.orig/setup.py	2010-07-17 08:31:09.000000000 -0400
+++ Python-2.6.7/setup.py	2011-06-29 13:25:48.000000000 -0400
@@ -260,12 +260,16 @@
                                               longest, g)
 
         if missing:
+            num_missing=len(missing)
             print
             print "Failed to find the necessary bits to build these modules:"
             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 5 missing)")
             print
+            if num_missing != 5:
+                sys.exit(1)
 
         if self.failed:
             failed = self.failed[:]
@@ -273,6 +277,7 @@
             print "Failed to build these modules:"
             print_three_column(failed)
             print
+            sys.exit(1)
 
     def build_extension(self, ext):
 
@@ -355,9 +360,8 @@
         return sys.platform
 
     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')
+        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.
@@ -691,10 +695,9 @@
                                depends = ['socketmodule.h']) )
         # Detect SSL support for the socket module (via _ssl)
         search_for_ssl_incs_in = [
-                              '/usr/local/ssl/include',
-                              '/usr/contrib/ssl/include/'
+                              '@PREFIX@/lib/system-openssl/include'
                              ]
-        ssl_incs = find_file('openssl/ssl.h', inc_dirs,
+        ssl_incs = find_file('openssl/ssl.h', [],
                              search_for_ssl_incs_in
                              )
         if ssl_incs is not None:
@@ -702,9 +705,8 @@
                                ['/usr/kerberos/include'])
             if krb5_h:
                 ssl_incs += krb5_h
-        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
-                                     ['/usr/local/ssl/lib',
-                                      '/usr/contrib/ssl/lib/'
+        ssl_libs = find_library_file(self.compiler, 'ssl', [],
+                                     ['@PREFIX@/lib/system-openssl/lib'
                                      ] )
 
         if (ssl_incs is not None and
@@ -724,7 +726,7 @@
 
         # look for the openssl version header on the compiler search path.
         opensslv_h = find_file('openssl/opensslv.h', [],
-                inc_dirs + search_for_ssl_incs_in)
+                search_for_ssl_incs_in)
         if opensslv_h:
             name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
             if sys.platform == 'darwin' and is_macosx_sdk_path(name):
@@ -782,7 +784,7 @@
         # a release.  Most open source OSes come with one or more
         # versions of BerkeleyDB already installed.
 
-        max_db_ver = (4, 7)
+        max_db_ver = (4, 8)
         min_db_ver = (3, 3)
         db_setup_debug = False   # verbose debug prints from this script?
 
@@ -818,50 +820,9 @@
         # construct a list of paths to look for the header file in on
         # top of the normal inc_dirs.
         db_inc_paths = [
-            '/usr/include/db4',
-            '/usr/local/include/db4',
-            '/opt/sfw/include/db4',
-            '/usr/include/db3',
-            '/usr/local/include/db3',
-            '/opt/sfw/include/db3',
-            # Fink defaults (http://fink.sourceforge.net/)
-            '/sw/include/db4',
-            '/sw/include/db3',
+            '@PREFIX@/include/db4'
         ]
-        # 4.x minor number specific paths
-        for x in gen_db_minor_ver_nums(4):
-            db_inc_paths.append('/usr/include/db4%d' % x)
-            db_inc_paths.append('/usr/include/db4.%d' % x)
-            db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
-            db_inc_paths.append('/usr/local/include/db4%d' % x)
-            db_inc_paths.append('/pkg/db-4.%d/include' % x)
-            db_inc_paths.append('/opt/db-4.%d/include' % x)
-            # MacPorts default (http://www.macports.org/)
-            db_inc_paths.append('/opt/local/include/db4%d' % x)
-        # 3.x minor number specific paths
-        for x in gen_db_minor_ver_nums(3):
-            db_inc_paths.append('/usr/include/db3%d' % x)
-            db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
-            db_inc_paths.append('/usr/local/include/db3%d' % x)
-            db_inc_paths.append('/pkg/db-3.%d/include' % x)
-            db_inc_paths.append('/opt/db-3.%d/include' % x)
-
-        # Add some common subdirectories for Sleepycat DB to the list,
-        # based on the standard include directories. This way DB3/4 gets
-        # picked up when it is installed in a non-standard prefix and
-        # the user has added that prefix into inc_dirs.
-        std_variants = []
-        for dn in inc_dirs:
-            std_variants.append(os.path.join(dn, 'db3'))
-            std_variants.append(os.path.join(dn, 'db4'))
-            for x in gen_db_minor_ver_nums(4):
-                std_variants.append(os.path.join(dn, "db4%d"%x))
-                std_variants.append(os.path.join(dn, "db4.%d"%x))
-            for x in gen_db_minor_ver_nums(3):
-                std_variants.append(os.path.join(dn, "db3%d"%x))
-                std_variants.append(os.path.join(dn, "db3.%d"%x))
 
-        db_inc_paths = std_variants + db_inc_paths
         db_inc_paths = [p for p in db_inc_paths if os.path.exists(p)]
 
         db_ver_inc_map = {}
@@ -987,12 +948,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)
@@ -1004,7 +960,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):
@@ -1036,11 +992,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))]
 
@@ -1199,6 +1153,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
@@ -1219,6 +1174,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')
@@ -1667,16 +1623,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.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:
@@ -1894,7 +1846,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"):
