Search in standard library and include dirs for Sleepycat stuff.

Fixes #590377.
This commit is contained in:
Martin v. Löwis 2002-12-06 10:25:02 +00:00
parent 6d5f30eaed
commit 05d4d562d7
1 changed files with 34 additions and 24 deletions

View File

@ -3,7 +3,7 @@
__version__ = "$Revision$" __version__ = "$Revision$"
import sys, os, getopt, imp import sys, os, getopt, imp, re
from distutils import sysconfig from distutils import sysconfig
from distutils import text_file from distutils import text_file
from distutils.errors import * from distutils.errors import *
@ -444,13 +444,16 @@ class PyBuildExt(build_ext):
# implementation independent wrapper for these; dumbdbm.py provides # implementation independent wrapper for these; dumbdbm.py provides
# similar functionality (but slower of course) implemented in Python. # similar functionality (but slower of course) implemented in Python.
# Berkeley DB interface. # Sleepycat Berkeley DB interface.
# #
# This requires the Berkeley DB code, see # This requires the Sleepycat DB code, see
# ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz # http://www.sleepycat.com/ The earliest supported version of
# that library is 3.0, the latest supported version is 4.0
# (4.1 is specifically not supported, as that changes the
# semantics of transactional databases). A list of available
# releases can be found at
# #
# (See http://pybsddb.sourceforge.net/ for an interface to # http://www.sleepycat.com/update/index.html
# Berkeley DB 3.x.)
# when sorted in reverse order, keys for this dict must appear in the # when sorted in reverse order, keys for this dict must appear in the
# order you wish to search - e.g., search for db4 before db3 # order you wish to search - e.g., search for db4 before db3
@ -458,18 +461,15 @@ class PyBuildExt(build_ext):
'db4': {'libs': ('db-4.0',), 'db4': {'libs': ('db-4.0',),
'libdirs': ('/usr/local/BerkeleyDB.4.0/lib', 'libdirs': ('/usr/local/BerkeleyDB.4.0/lib',
'/usr/local/lib', '/usr/local/lib',
'/usr/lib',
'/opt/sfw', '/opt/sfw',
'/sw/lib', '/sw/lib',
'/lib',
), ),
'incdirs': ('/usr/local/BerkeleyDB.4.0/include', 'incdirs': ('/usr/local/BerkeleyDB.4.0/include',
'/usr/local/include/db4', '/usr/local/include/db4',
'/opt/sfw/include/db4', '/opt/sfw/include/db4',
'/sw/include/db4', '/sw/include/db4',
'/usr/include/db4', '/usr/include/db4',
), )},
'incs': ('db.h',)},
'db3': {'libs': ('db-3.3', 'db-3.2', 'db-3.1', 'db-3.0'), 'db3': {'libs': ('db-3.3', 'db-3.2', 'db-3.1', 'db-3.0'),
'libdirs': ('/usr/local/BerkeleyDB.3.3/lib', 'libdirs': ('/usr/local/BerkeleyDB.3.3/lib',
'/usr/local/BerkeleyDB.3.2/lib', '/usr/local/BerkeleyDB.3.2/lib',
@ -478,8 +478,6 @@ class PyBuildExt(build_ext):
'/usr/local/lib', '/usr/local/lib',
'/opt/sfw', '/opt/sfw',
'/sw/lib', '/sw/lib',
'/usr/lib',
'/lib',
), ),
'incdirs': ('/usr/local/BerkeleyDB.3.3/include', 'incdirs': ('/usr/local/BerkeleyDB.3.3/include',
'/usr/local/BerkeleyDB.3.2/include', '/usr/local/BerkeleyDB.3.2/include',
@ -489,27 +487,39 @@ class PyBuildExt(build_ext):
'/opt/sfw/include/db3', '/opt/sfw/include/db3',
'/sw/include/db3', '/sw/include/db3',
'/usr/include/db3', '/usr/include/db3',
), )},
'incs': ('db.h',)},
} }
db_search_order = db_try_this.keys() db_search_order = db_try_this.keys()
db_search_order.sort() db_search_order.sort()
db_search_order.reverse() db_search_order.reverse()
find_lib_file = self.compiler.find_library_file
class found(Exception): pass class found(Exception): pass
try: try:
# See whether there is a Sleepycat header in the standard
# search path.
std_dbinc = None
for d in inc_dirs:
f = os.path.join(d, "db.h")
if os.path.exists(f):
f = open(f).read()
m = re.search(r"#define\WDB_VERSION_MAJOR\W([1-9]+)", f)
if m:
std_dbinc = 'db' + m.group(1)
for dbkey in db_search_order: for dbkey in db_search_order:
dbd = db_try_this[dbkey] dbd = db_try_this[dbkey]
for dblib in dbd['libs']: for dblib in dbd['libs']:
for dbinc in dbd['incs']: # Prefer version-specific includes over standard
db_incs = find_file(dbinc, [], dbd['incdirs']) # include locations.
dblib_dir = find_lib_file(dbd['libdirs'], dblib) db_incs = find_file('db.h', [], dbd['incdirs'])
if db_incs and dblib_dir: dblib_dir = find_library_file(self.compiler,
dblib_dir = os.path.dirname(dblib_dir) dblib,
dblibs = [dblib] lib_dirs,
raise found list(dbd['libdirs']))
if (db_incs or dbkey == std_dbinc) and \
dblib_dir is not None:
dblibs = [dblib]
raise found
except found: except found:
dblibs = [dblib] dblibs = [dblib]
# A default source build puts Berkeley DB in something like # A default source build puts Berkeley DB in something like
@ -521,8 +531,8 @@ class PyBuildExt(build_ext):
# in some unusual system configurations (e.g. the directory is on # in some unusual system configurations (e.g. the directory is on
# an NFS server that goes away). # an NFS server that goes away).
exts.append(Extension('_bsddb', ['_bsddb.c'], exts.append(Extension('_bsddb', ['_bsddb.c'],
library_dirs=[dblib_dir], library_dirs=dblib_dir,
runtime_library_dirs=[dblib_dir], runtime_library_dirs=dblib_dir,
include_dirs=db_incs, include_dirs=db_incs,
libraries=dblibs)) libraries=dblibs))
else: else: