mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
rewrote the bsddb module BerkeleyDB library and include file locating
code. This version is much cleaner and makes a proper attempt at pairing up the correct header file and library.
This commit is contained in:
parent
57ee770df1
commit
e76c8c0383
1 changed files with 91 additions and 70 deletions
149
setup.py
149
setup.py
|
@ -497,92 +497,113 @@ class PyBuildExt(build_ext):
|
||||||
#
|
#
|
||||||
# http://www.sleepycat.com/update/index.html
|
# http://www.sleepycat.com/update/index.html
|
||||||
|
|
||||||
# when sorted in reverse order, keys for this dict must appear in the
|
max_db_ver = (4, 3)
|
||||||
# order you wish to search - e.g., search for db4 before db3
|
min_db_ver = (3, 2)
|
||||||
db_try_this = {
|
db_setup_debug = False # verbose debug prints from this script?
|
||||||
'db4': {'libs': ('db-4.3', 'db43', 'db-4.2', 'db42', 'db-4.1', 'db41', 'db-4.0', 'db4',),
|
|
||||||
'libdirs': ('/usr/local/BerkeleyDB.4.3/lib',
|
# construct a list of paths to look for the header file in on
|
||||||
'/usr/local/BerkeleyDB.4.2/lib',
|
# top of the normal inc_dirs.
|
||||||
'/usr/local/BerkeleyDB.4.1/lib',
|
db_inc_paths = [
|
||||||
'/usr/local/BerkeleyDB.4.0/lib',
|
'/usr/include/db4',
|
||||||
'/usr/local/lib',
|
|
||||||
'/opt/sfw',
|
|
||||||
'/sw/lib',
|
|
||||||
),
|
|
||||||
'incdirs': ('/usr/local/BerkeleyDB.4.3/include',
|
|
||||||
'/usr/local/include/db43',
|
|
||||||
'/usr/local/BerkeleyDB.4.2/include',
|
|
||||||
'/usr/local/include/db42',
|
|
||||||
'/usr/local/BerkeleyDB.4.1/include',
|
|
||||||
'/usr/local/include/db41',
|
|
||||||
'/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/db3',
|
||||||
)},
|
|
||||||
'db3': {'libs': ('db-3.3', 'db-3.2', 'db3',),
|
|
||||||
'libdirs': ('/usr/local/BerkeleyDB.3.3/lib',
|
|
||||||
'/usr/local/BerkeleyDB.3.2/lib',
|
|
||||||
'/usr/local/lib',
|
|
||||||
'/opt/sfw/lib',
|
|
||||||
'/sw/lib',
|
|
||||||
),
|
|
||||||
'incdirs': ('/usr/local/BerkeleyDB.3.3/include',
|
|
||||||
'/usr/local/BerkeleyDB.3.2/include',
|
|
||||||
'/usr/local/include/db3',
|
'/usr/local/include/db3',
|
||||||
'/opt/sfw/include/db3',
|
'/opt/sfw/include/db3',
|
||||||
'/sw/include/db3',
|
'/sw/include/db3',
|
||||||
'/usr/include/db3',
|
]
|
||||||
)},
|
# 4.x minor number specific paths
|
||||||
}
|
for x in (0,1,2,3):
|
||||||
|
db_inc_paths.append('/usr/include/db4%d' % x)
|
||||||
|
db_inc_paths.append('/usr/local/BerkeleyDB.4.%d/include' % x)
|
||||||
|
db_inc_paths.append('/usr/local/include/db4%d' % x)
|
||||||
|
db_inc_paths.append('/pkg/db-4.%d/include' % x)
|
||||||
|
# 3.x minor number specific paths
|
||||||
|
for x in (2,3):
|
||||||
|
db_inc_paths.append('/usr/include/db3%d' % x)
|
||||||
|
db_inc_paths.append('/usr/local/BerkeleyDB.3.%d/include' % x)
|
||||||
|
db_inc_paths.append('/usr/local/include/db3%d' % x)
|
||||||
|
db_inc_paths.append('/pkg/db-3.%d/include' % x)
|
||||||
|
|
||||||
db_search_order = db_try_this.keys()
|
db_ver_inc_map = {}
|
||||||
db_search_order.sort()
|
|
||||||
db_search_order.reverse()
|
|
||||||
|
|
||||||
class found(Exception): pass
|
class db_found(Exception): pass
|
||||||
try:
|
try:
|
||||||
# See whether there is a Sleepycat header in the standard
|
# See whether there is a Sleepycat header in the standard
|
||||||
# search path.
|
# search path.
|
||||||
std_dbinc = None
|
for d in inc_dirs + db_inc_paths:
|
||||||
for d in inc_dirs:
|
|
||||||
f = os.path.join(d, "db.h")
|
f = os.path.join(d, "db.h")
|
||||||
|
if db_setup_debug: print "db: looking for db.h in", f
|
||||||
if os.path.exists(f):
|
if os.path.exists(f):
|
||||||
f = open(f).read()
|
f = open(f).read()
|
||||||
m = re.search(r"#define\WDB_VERSION_MAJOR\W([1-9]+)", f)
|
m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f)
|
||||||
if m:
|
if m:
|
||||||
std_dbinc = 'db' + m.group(1)
|
db_major = int(m.group(1))
|
||||||
for dbkey in db_search_order:
|
m = re.search(r"#define\WDB_VERSION_MINOR\W(\d+)", f)
|
||||||
dbd = db_try_this[dbkey]
|
db_minor = int(m.group(1))
|
||||||
for dblib in dbd['libs']:
|
db_ver = (db_major, db_minor)
|
||||||
# Prefer version-specific includes over standard
|
|
||||||
# include locations.
|
if ( (not db_ver_inc_map.has_key(db_ver)) and
|
||||||
db_incs = find_file('db.h', [], dbd['incdirs'])
|
(db_ver <= max_db_ver and db_ver >= min_db_ver) ):
|
||||||
dblib_dir = find_library_file(self.compiler,
|
# save the include directory with the db.h version
|
||||||
dblib,
|
# (first occurrance only)
|
||||||
lib_dirs,
|
db_ver_inc_map[db_ver] = d
|
||||||
list(dbd['libdirs']))
|
print "db.h: found", db_ver, "in", d
|
||||||
if (db_incs or dbkey == std_dbinc) and \
|
else:
|
||||||
dblib_dir is not None:
|
# we already found a header for this library version
|
||||||
|
if db_setup_debug: print "db.h: ignoring", d
|
||||||
|
else:
|
||||||
|
# ignore this header, it didn't contain a version number
|
||||||
|
if db_setup_debug: print "db.h: unsupported version", db_ver, "in", d
|
||||||
|
|
||||||
|
db_found_vers = db_ver_inc_map.keys()
|
||||||
|
db_found_vers.sort()
|
||||||
|
|
||||||
|
while db_found_vers:
|
||||||
|
db_ver = db_found_vers.pop()
|
||||||
|
db_incdir = db_ver_inc_map[db_ver]
|
||||||
|
|
||||||
|
# check lib directories parallel to the location of the header
|
||||||
|
db_dirs_to_check = [
|
||||||
|
os.path.join(db_incdir, '..', 'lib64'),
|
||||||
|
os.path.join(db_incdir, '..', 'lib'),
|
||||||
|
os.path.join(db_incdir, '..', '..', 'lib64'),
|
||||||
|
os.path.join(db_incdir, '..', '..', 'lib'),
|
||||||
|
]
|
||||||
|
db_dirs_to_check = filter(os.path.isdir, db_dirs_to_check)
|
||||||
|
|
||||||
|
# Look for a version specific db-X.Y before an ambiguoius dbX
|
||||||
|
# XXX should we -ever- look for a dbX name? Do any
|
||||||
|
# systems really not name their library by version and
|
||||||
|
# symlink to more general names?
|
||||||
|
for dblib in (('db-%d.%d' % db_ver), ('db%d' % db_ver[0])):
|
||||||
|
dblib_file = self.compiler.find_library_file(
|
||||||
|
db_dirs_to_check + lib_dirs, dblib )
|
||||||
|
if dblib_file:
|
||||||
|
dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
|
||||||
|
raise db_found
|
||||||
|
else:
|
||||||
|
if db_setup_debug: print "db lib: ", dblib, "not found"
|
||||||
|
|
||||||
|
except db_found:
|
||||||
|
print "db lib: using", db_ver, dblib
|
||||||
|
if db_setup_debug: print "db: lib dir", dblib_dir, "inc dir", db_incdir
|
||||||
|
db_incs = [db_incdir]
|
||||||
dblibs = [dblib]
|
dblibs = [dblib]
|
||||||
raise found
|
# We add the runtime_library_dirs argument because the
|
||||||
except found:
|
# BerkeleyDB lib we're linking against often isn't in the
|
||||||
dblibs = [dblib]
|
# system dynamic library search path. This is usually
|
||||||
# A default source build puts Berkeley DB in something like
|
# correct and most trouble free, but may cause problems in
|
||||||
# /usr/local/Berkeley.3.3 and the lib dir under that isn't
|
# some unusual system configurations (e.g. the directory
|
||||||
# normally on ld.so's search path, unless the sysadmin has hacked
|
# is on an NFS server that goes away).
|
||||||
# /etc/ld.so.conf. We add the directory to runtime_library_dirs
|
|
||||||
# so the proper -R/--rpath flags get passed to the linker. This
|
|
||||||
# is usually correct and most trouble free, but may cause problems
|
|
||||||
# in some unusual system configurations (e.g. the directory is on
|
|
||||||
# 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:
|
||||||
|
if db_setup_debug: print "db: no appropriate library found"
|
||||||
db_incs = None
|
db_incs = None
|
||||||
dblibs = []
|
dblibs = []
|
||||||
dblib_dir = None
|
dblib_dir = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue