--- setup.py	Thu Jan  8 10:57:53 2004
+++ setup_better.py	Thu Jan  8 10:59:25 2004
@@ -20,18 +20,44 @@
 name = "MySQL-%s" % os.path.basename(sys.executable)
 version = "0.9.2"
 
-mysqlclient = thread_safe_library and "mysqlclient_r" or "mysqlclient"
+mysqlclient = thread_safe_library and "mysqlclient"
 
 # include files and library locations should cover most platforms
-include_dirs = [
-    '/usr/include/mysql', '/usr/local/include/mysql',
-    '/usr/local/mysql/include/mysql'
-    ]
-library_dirs = [
-    '/usr/lib/mysql', '/usr/local/lib/mysql',
-    '/usr/local/mysql/lib/mysql'
-    ]
 
+dir_given = 0
+
+include_dirs = []
+library_dirs = []
+
+args = sys.argv[:]
+if len(args) > 2:
+	for y in args:
+			found = y.find('--prefix=')
+			if(found > -1):
+				found = found + len('--prefix=')
+				z = y[found:]
+				include_dirs = [os.path.join(z, 'include')]
+				library_dirs = [os.path.join(z, 'lib')]
+				dir_given = 1    
+				sys.argv.remove(y)
+			found = y.find('--includedir=')
+			if (found > -1):
+				found = found + len('--includedir=')
+				z = y[found:]
+				include_dirs = [z]
+				dir_given = 1
+				sys.argv.remove(y)
+			found = y.find('--libdir=')
+			if (found > -1 ):
+				found = found + len('--libdir=')
+				z = y[found:]
+				library_dirs = [z]
+				dir_given = 1
+				sys.argv.remove(y)
+else:
+    include_dirs = ['/usr/include/mysql', '/usr/local/include/mysql','/usr/local/mysql/include/mysql']
+    library_dirs = ['/usr/lib/mysql', '/usr/local/lib/mysql','/usr/local/mysql/lib/mysql']
+    
 # MySQL-3.23 and newer need libz
 libraries = [mysqlclient, "z"]
 
@@ -48,37 +74,41 @@
 extra_compile_args = []
 extra_link_args = []
 
-if sys.platform == "netbsd1":
-    include_dirs = ['/usr/pkg/include/mysql']
-    library_dirs = ['/usr/pkg/lib/mysql']
-elif sys.platform in ("freebsd4", "openbsd3"):
-    LOCALBASE = os.environ.get('LOCALBASE', '/usr/local')
-    include_dirs = ['%s/include/mysql' % LOCALBASE]
-    library_dirs = ['%s/lib/mysql' % LOCALBASE]
-elif sys.platform == "sunos5": # Solaris 2.8 + gcc
-    runtime_library_dirs.append('/usr/local/lib:/usr/openwin/lib:/usr/dt/lib') 
-    extra_compile_args.append("-fPIC")
-elif sys.platform == "win32": # Ugh
-    include_dirs = [r'c:\mysql\include']
-    library_dirs = [r'c:\mysql\lib\opt']
-    libraries = [mysqlclient, 'zlib', 'msvcrt', 'libcmt',
-                 'wsock32', 'advapi32']
-    extra_objects = [r'c:\mysql\lib\opt\mysqlclient.lib']
-elif sys.platform == "cygwin":
-    include_dirs = ['/c/mysql/include']
-    library_dirs = ['/c/mysql/lib']
-    extra_compile_args.append('-DMS_WIN32')
-elif sys.platform[:6] == "darwin": # Mac OS X
-    include_dirs.append('/sw/include')
-    library_dirs.append('/sw/lib')
-    extra_link_args.append('-flat_namespace')
-elif sys.platform == 'linux2' and os.environ.get('HOSTTYPE') == 'alpha':
-    libraries.extend(['ots', 'cpml'])
-elif os.name == "posix": # UNIX-ish platforms not covered above
-    pass # default should work
+if(dir_given == 0):
+    if sys.platform == "netbsd1":
+        include_dirs = ['/usr/pkg/include/mysql']
+        library_dirs = ['/usr/pkg/lib/mysql']
+    elif sys.platform in ("freebsd4", "openbsd3"):
+        LOCALBASE = os.environ.get('LOCALBASE', '/usr/local')
+        include_dirs = ['%s/include/mysql' % LOCALBASE]
+        library_dirs = ['%s/lib/mysql' % LOCALBASE]
+    elif sys.platform == "sunos5": # Solaris 2.8 + gcc
+        runtime_library_dirs.append('/usr/local/lib:/usr/openwin/lib:/usr/dt/lib') 
+        extra_compile_args.append("-fPIC")
+    elif sys.platform == "win32": # Ugh
+        include_dirs = [r'c:\mysql\include']
+        library_dirs = [r'c:\mysql\lib\opt']
+        libraries = [mysqlclient, 'zlib', 'msvcrt', 'libcmt',
+                     'wsock32', 'advapi32']
+        extra_objects = [r'c:\mysql\lib\opt\mysqlclient.lib']
+    elif sys.platform == "cygwin":
+        include_dirs = ['/c/mysql/include']
+        library_dirs = ['/c/mysql/lib']
+        extra_compile_args.append('-DMS_WIN32')
+    elif sys.platform[:6] == "darwin": # Mac OS X
+        include_dirs.append('/sw/include')
+        library_dirs.append('/sw/lib')
+        extra_link_args.append('-flat_namespace')
+    elif sys.platform == 'linux2' and os.environ.get('HOSTTYPE') == 'alpha':
+        libraries.extend(['ots', 'cpml'])
+    elif os.name == "posix": # UNIX-ish platforms not covered above
+        pass # default should work
+    else:
+        raise "UnknownPlatform", "sys.platform=%s, os.name=%s" % \
+              (sys.platform, os.name)
 else:
-    raise "UnknownPlatform", "sys.platform=%s, os.name=%s" % \
-          (sys.platform, os.name)
+    if (sys.platform[:6] == "darwin"): # Mac OS X
+        extra_link_args.append('-flat_namespace')
     
 long_description = \
 """Python interface to MySQL-3.23
