setup.py improvements.

This commit is contained in:
Federico Di Gregorio 2005-05-17 23:32:26 +00:00
parent e1e0b34343
commit 367f7b92f4
2 changed files with 28 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2005-05-18 Federico Di Gregorio <fog@debian.org>
* setup.py: Applied combined patch from Daniele Varrazzo and Jason
Erickson to build on win32 using MSVC or mingw.
2005-05-15 Federico Di Gregorio <fog@debian.org> 2005-05-15 Federico Di Gregorio <fog@debian.org>
* psycopg/microprotocols.c (microprotocols_adapt): fixed memory * psycopg/microprotocols.c (microprotocols_adapt): fixed memory

View File

@ -53,8 +53,9 @@ from distutils.core import setup, Extension
from distutils.errors import DistutilsFileError from distutils.errors import DistutilsFileError
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc from distutils.sysconfig import get_python_inc
from distutils.ccompiler import get_default_compiler
PSYCOPG_VERSION = '2.0b1' PSYCOPG_VERSION = '2.0b2'
version_flags = [] version_flags = []
# to work around older distutil limitations # to work around older distutil limitations
@ -95,6 +96,14 @@ class psycopg_build_ext(build_ext):
self.use_pg_dll = 1 self.use_pg_dll = 1
self.pgdir = None self.pgdir = None
def get_compiler(self):
"""Return the c compiler to compile extensions.
If a compiler was not explicitely set (on the command line, for
example), fall back on the default compiler.
"""
return self.compiler or get_default_compiler()
def finalize_win32(self): def finalize_win32(self):
"""Finalize build system configuration on win32 platform. """Finalize build system configuration on win32 platform.
@ -114,7 +123,7 @@ class psycopg_build_ext(build_ext):
self.include_dirs.append(os.path.join( self.include_dirs.append(os.path.join(
self.pgdir, "src", "include")) self.pgdir, "src", "include"))
if self.compiler == "msvc": if self.get_compiler() == "msvc":
self.libpqdir = os.path.join( self.libpqdir = os.path.join(
self.pgdir, "src", "interfaces", "libpq", "Release") self.pgdir, "src", "interfaces", "libpq", "Release")
else: else:
@ -129,11 +138,21 @@ class psycopg_build_ext(build_ext):
self.library_dirs.append(os.path.join( self.library_dirs.append(os.path.join(
self.pgdir, "lib")) self.pgdir, "lib"))
# Remove the library that was added in the finalize_options, since:
# 1) We do not need it because we are using the DLL version, or
# 2) We do need it, but it might need to be msvc'ified, and
# 3) The other benefit is that msvc needs pqdll to be the last
self.libraries.remove("pq")
if self.use_pg_dll: if self.use_pg_dll:
self.libraries.append(self.get_lib("pqdll")) self.libraries.append(self.get_lib("pqdll"))
else: else:
self.libraries.append("advapi32") self.libraries.append("advapi32")
if self.get_compiler() == "msvc":
self.libraries.append("shfolder")
self.libraries.append(self.get_lib("pq"))
def finalize_darwin(self): def finalize_darwin(self):
"""Finalize build system configuration on darwin platform. """Finalize build system configuration on darwin platform.
@ -151,7 +170,7 @@ class psycopg_build_ext(build_ext):
"""Complete the build system configuation.""" """Complete the build system configuation."""
build_ext.finalize_options(self) build_ext.finalize_options(self)
self.libraries.append(self.get_lib("pq")) self.libraries.append("pq")
if hasattr(self, "finalize_" + sys.platform): if hasattr(self, "finalize_" + sys.platform):
getattr(self, "finalize_" + sys.platform)() getattr(self, "finalize_" + sys.platform)()
@ -175,7 +194,7 @@ class psycopg_build_ext(build_ext):
MS VC compiler doesn't assume a "lib" prefix as gcc derived ones do. MS VC compiler doesn't assume a "lib" prefix as gcc derived ones do.
Return the library name as required by the compiler. Return the library name as required by the compiler.
""" """
if sys.platform == 'win32' and self.compiler == "msvc": if sys.platform == 'win32' and self.get_compiler() == "msvc":
return "lib" + name return "lib" + name
else: else:
return name return name