We now use pg_config in setup.py (closes: #70).

This commit is contained in:
Federico Di Gregorio 2006-01-05 04:19:01 +00:00
parent c79e92e928
commit d5674253ca
3 changed files with 40 additions and 22 deletions

View File

@ -1,3 +1,8 @@
2006-01-05 Federico Di Gregorio <fog@initd.org>
* setup.{cfg,py}: we now use pg_config to locate PostgreSQL libraries
and headers (modified patch from lbruno, see #70.)
2006-01-01 Federico Di Gregorio <fog@initd.org>
* Preparing release 2 beta 7.

View File

@ -20,16 +20,23 @@ use_decimal=0
# uncommenting the following line and setting its value to the right path.
#mx_include_dir=
# "include_dirs" is the preferred method for locating postgresql headers,
# but some extra checks on sys.platform will still be done in setup.py.
# "pg_config" is the preferred method to locate PostgreSQL headers and
# libraries needed to build psycopg2. If pg_config is not in the path or
# is installed under a different name uncomment the following option and
# set it to the pg_config full path.
#pg_config=
# If "pg_config" is not available, "include_dirs" can be used to locate
# postgresql headers and libraries. Some extra checks on sys.platform will
# still be done in setup.py.
# The next line is the default as used on psycopg author Debian laptop:
include_dirs=.:/usr/include/postgresql:/usr/include/postgresql/server
#include_dirs=/usr/include/postgresql:/usr/include/postgresql/server
# Uncomment next line on Mandrake 10.x (and comment previous ones):
#include_dirs=.:/usr/include/pgsql/8.0:/usr/include/pgsql/8.0/server
#include_dirs=/usr/include/pgsql/8.0:/usr/include/pgsql/8.0/server
# Uncomment next line on SUSE 9.3 (and comment previous ones):
#include_dirs=.:/usr/include/pgsql:/usr/include/pgsql/server
#include_dirs=/usr/include/pgsql:/usr/include/pgsql/server
# If postgresql is installed somewhere weird (i.e., not in your runtime library
# path like /usr/lib), just add the right path in "library_dirs" and any extra

View File

@ -49,6 +49,7 @@ Operating System :: Unix
import os
import sys
import shutil
import popen2
from distutils.core import setup, Extension
from distutils.errors import DistutilsFileError
from distutils.command.build_ext import build_ext
@ -82,6 +83,8 @@ class psycopg_build_ext(build_ext):
"Build against libpq.dll (win32 only)"),
('use-pydatetime', None,
"Use Python datatime objects for date and time representation."),
('pg_config=', None,
"The name of the pg_config binary and/or full path to find it"),
])
boolean_options = build_ext.boolean_options[:]
@ -95,6 +98,14 @@ class psycopg_build_ext(build_ext):
self.use_pydatetime = 1
self.use_pg_dll = 1
self.pgdir = None
self.pg_config = "pg_config"
def get_pg_config(self, kind):
p = popen2.popen3(self.pg_config + " --" + kind, mode="r")
r = p[0].readline().strip()
if not r:
raise Warning(p[2].readline().strip())
return r
def get_compiler(self):
"""Return the c compiler to compile extensions.
@ -164,19 +175,7 @@ class psycopg_build_ext(build_ext):
self.libraries.append(self.get_lib("pq"))
def finalize_darwin(self):
"""Finalize build system configuration on darwin platform.
fink installs lots of goodies in /sw/... - make sure we check there
"""
self.include_dirs.append("/sw/include")
self.include_dirs.append("/sw/include/postgresql")
self.include_dirs.append("/sw/include/postgresql/server")
self.library_dirs.append("/sw/lib")
self.include_dirs.append("/opt/local/include")
self.include_dirs.append("/opt/local/include/postgresql")
self.include_dirs.append("/opt/local/include/postgresql/server")
self.library_dirs.append("/opt/local/lib")
self.library_dirs.append("/usr/lib")
"""Finalize build system configuration on darwin platform."""
self.libraries.append('ssl')
self.libraries.append('crypto')
@ -184,8 +183,13 @@ class psycopg_build_ext(build_ext):
"""Complete the build system configuation."""
build_ext.finalize_options(self)
self.include_dirs.append(".")
self.libraries.append("pq")
self.library_dirs.append(self.get_pg_config("libdir"))
self.include_dirs.append(self.get_pg_config("includedir"))
self.include_dirs.append(self.get_pg_config("includedir-server"))
if hasattr(self, "finalize_" + sys.platform):
getattr(self, "finalize_" + sys.platform)()
@ -198,6 +202,8 @@ class psycopg_build_ext(build_ext):
if sys.platform == 'win32' and self.use_pg_dll:
shutil.copy(self.find_libpq_dll(), "lib")
## win32-specific stuff ##
def build_from_src(self):
"""Detect if building from postgres source or bin on w32 platform"""
return os.path.exists(os.path.join(self.pgdir, "src"))