Index: configure
--- configure.orig	2010-11-01 02:47:19.000000000 +0100
+++ configure	2010-12-05 18:07:39.000000000 +0100
@@ -3904,9 +3904,9 @@
   CFLAGS=$ac_save_CFLAGS
 elif test $ac_cv_prog_cc_g = yes; then
   if test "$GCC" = yes; then
-    CFLAGS="-g -O2"
+    CFLAGS="-O2"
   else
-    CFLAGS="-g"
+    CFLAGS=""
   fi
 else
   if test "$GCC" = yes; then
@@ -5352,7 +5352,7 @@
 		# debug builds.
 		OPT="-g -O0 -Wall $STRICT_PROTO"
 	    else
-		OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
+		OPT="$WRAP -O3 -Wall $STRICT_PROTO"
 	    fi
 	    ;;
 	*)
@@ -7627,24 +7627,24 @@
 	FreeBSD*)
 		if [ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]
 		then
-			LDSHARED='$(CC) -shared ${LDFLAGS}'
-			LDCXXSHARED='$(CXX) -shared ${LDFLAGS}'
+			LDSHARED="\$(CC) -shared ${LDFLAGS}"
+			LDCXXSHARED="\$(CXX) -shared ${LDFLAGS}"
 		else
 			LDSHARED="ld -Bshareable ${LDFLAGS}"
 		fi;;
 	OpenBSD*)
 		if [ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]
 		then
-				LDSHARED='$(CC) -shared $(CCSHARED) ${LDFLAGS}'
-				LDCXXSHARED='$(CXX) -shared $(CCSHARED) ${LDFLAGS}'
+				LDSHARED="\$(CC) -shared \$(CCSHARED) ${LDFLAGS}"
+				LDCXXSHARED="\$(CXX) -shared \$(CCSHARED) ${LDFLAGS}"
 		else
 				case `uname -r` in
 				[01].* | 2.[0-7] | 2.[0-7].*)
 				   LDSHARED="ld -Bshareable ${LDFLAGS}"
 				   ;;
 				*)
-				   LDSHARED='$(CC) -shared $(CCSHARED) ${LDFLAGS}'
-				   LDCXXSHARED='$(CXX) -shared $(CCSHARED) ${LDFLAGS}'
+				   LDSHARED="\$(CC) -shared \$(CCSHARED) ${LDFLAGS}"
+				   LDCXXSHARED="\$(CXX) -shared \$(CCSHARED) ${LDFLAGS}"
 				   ;;
 				esac
 		fi;;
@@ -7751,7 +7751,7 @@
 		then
 			LINKFORSHARED="-Wl,--export-dynamic"
 		fi;;
-	SunOS/5*) case $CC in
+	SunOS/5*) case gcc in
 		  *gcc*)
 		    if $CC -Xlinker --help 2>&1 | grep export-dynamic >/dev/null
 		    then
Index: setup.py
--- setup.py.orig	2010-10-31 17:40:21.000000000 +0100
+++ setup.py	2010-12-05 18:05:56.000000000 +0100
@@ -347,8 +347,8 @@
 
     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, '@l_prefix@/lib')
+        add_dir_to_list(self.compiler.include_dirs, '@l_prefix@/include')
 
         # Add paths specified in the environment variables LDFLAGS and
         # CPPFLAGS for header and library files.
@@ -680,8 +680,6 @@
                                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/'
                              ]
         ssl_incs = find_file('openssl/ssl.h', inc_dirs,
                              search_for_ssl_incs_in
@@ -692,8 +690,7 @@
             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/'
+                                     ['@l_prefix@/lib'
                                      ] )
 
         if (ssl_incs is not None and
@@ -813,14 +810,8 @@
         # 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',
         ]
         # 4.x minor number specific paths
         for x in gen_db_minor_ver_nums(4):
@@ -1708,6 +1699,7 @@
                 dotversion = dotversion[:-1] + '.' + dotversion[-1]
             tcl_include_sub = []
             tk_include_sub = []
+            dotversion = ''
             for dir in inc_dirs:
                 tcl_include_sub += [dir + os.sep + "tcl" + dotversion]
                 tk_include_sub += [dir + os.sep + "tk" + dotversion]
