@@ -497,92 +497,113 @@ def detect_modules(self):
497497 #
498498 # http://www.sleepycat.com/update/index.html
499499
500- # when sorted in reverse order, keys for this dict must appear in the
501- # order you wish to search - e.g., search for db4 before db3
502- db_try_this = {
503- 'db4' : {'libs' : ('db-4.3' , 'db43' , 'db-4.2' , 'db42' , 'db-4.1' , 'db41' , 'db-4.0' , 'db4' ,),
504- 'libdirs' : ('/usr/local/BerkeleyDB.4.3/lib' ,
505- '/usr/local/BerkeleyDB.4.2/lib' ,
506- '/usr/local/BerkeleyDB.4.1/lib' ,
507- '/usr/local/BerkeleyDB.4.0/lib' ,
508- '/usr/local/lib' ,
509- '/opt/sfw' ,
510- '/sw/lib' ,
511- ),
512- 'incdirs' : ('/usr/local/BerkeleyDB.4.3/include' ,
513- '/usr/local/include/db43' ,
514- '/usr/local/BerkeleyDB.4.2/include' ,
515- '/usr/local/include/db42' ,
516- '/usr/local/BerkeleyDB.4.1/include' ,
517- '/usr/local/include/db41' ,
518- '/usr/local/BerkeleyDB.4.0/include' ,
519- '/usr/local/include/db4' ,
520- '/opt/sfw/include/db4' ,
521- '/sw/include/db4' ,
522- '/usr/include/db4' ,
523- )},
524- 'db3' : {'libs' : ('db-3.3' , 'db-3.2' , 'db3' ,),
525- 'libdirs' : ('/usr/local/BerkeleyDB.3.3/lib' ,
526- '/usr/local/BerkeleyDB.3.2/lib' ,
527- '/usr/local/lib' ,
528- '/opt/sfw/lib' ,
529- '/sw/lib' ,
530- ),
531- 'incdirs' : ('/usr/local/BerkeleyDB.3.3/include' ,
532- '/usr/local/BerkeleyDB.3.2/include' ,
533- '/usr/local/include/db3' ,
534- '/opt/sfw/include/db3' ,
535- '/sw/include/db3' ,
536- '/usr/include/db3' ,
537- )},
538- }
539-
540- db_search_order = db_try_this .keys ()
541- db_search_order .sort ()
542- db_search_order .reverse ()
543-
544- class found (Exception ): pass
500+ max_db_ver = (4 , 3 )
501+ min_db_ver = (3 , 2 )
502+ db_setup_debug = False # verbose debug prints from this script?
503+
504+ # construct a list of paths to look for the header file in on
505+ # top of the normal inc_dirs.
506+ db_inc_paths = [
507+ '/usr/include/db4' ,
508+ '/usr/local/include/db4' ,
509+ '/opt/sfw/include/db4' ,
510+ '/sw/include/db4' ,
511+ '/usr/include/db3' ,
512+ '/usr/local/include/db3' ,
513+ '/opt/sfw/include/db3' ,
514+ '/sw/include/db3' ,
515+ ]
516+ # 4.x minor number specific paths
517+ for x in (0 ,1 ,2 ,3 ):
518+ db_inc_paths .append ('/usr/include/db4%d' % x )
519+ db_inc_paths .append ('/usr/local/BerkeleyDB.4.%d/include' % x )
520+ db_inc_paths .append ('/usr/local/include/db4%d' % x )
521+ db_inc_paths .append ('/pkg/db-4.%d/include' % x )
522+ # 3.x minor number specific paths
523+ for x in (2 ,3 ):
524+ db_inc_paths .append ('/usr/include/db3%d' % x )
525+ db_inc_paths .append ('/usr/local/BerkeleyDB.3.%d/include' % x )
526+ db_inc_paths .append ('/usr/local/include/db3%d' % x )
527+ db_inc_paths .append ('/pkg/db-3.%d/include' % x )
528+
529+ db_ver_inc_map = {}
530+
531+ class db_found (Exception ): pass
545532 try :
546533 # See whether there is a Sleepycat header in the standard
547534 # search path.
548- std_dbinc = None
549- for d in inc_dirs :
535+ for d in inc_dirs + db_inc_paths :
550536 f = os .path .join (d , "db.h" )
537+ if db_setup_debug : print "db: looking for db.h in" , f
551538 if os .path .exists (f ):
552539 f = open (f ).read ()
553- m = re .search (r"#define\WDB_VERSION_MAJOR\W([1-9] +)" , f )
540+ m = re .search (r"#define\WDB_VERSION_MAJOR\W(\d +)" , f )
554541 if m :
555- std_dbinc = 'db' + m .group (1 )
556- for dbkey in db_search_order :
557- dbd = db_try_this [dbkey ]
558- for dblib in dbd ['libs' ]:
559- # Prefer version-specific includes over standard
560- # include locations.
561- db_incs = find_file ('db.h' , [], dbd ['incdirs' ])
562- dblib_dir = find_library_file (self .compiler ,
563- dblib ,
564- lib_dirs ,
565- list (dbd ['libdirs' ]))
566- if (db_incs or dbkey == std_dbinc ) and \
567- dblib_dir is not None :
568- dblibs = [dblib ]
569- raise found
570- except found :
542+ db_major = int (m .group (1 ))
543+ m = re .search (r"#define\WDB_VERSION_MINOR\W(\d+)" , f )
544+ db_minor = int (m .group (1 ))
545+ db_ver = (db_major , db_minor )
546+
547+ if ( (not db_ver_inc_map .has_key (db_ver )) and
548+ (db_ver <= max_db_ver and db_ver >= min_db_ver ) ):
549+ # save the include directory with the db.h version
550+ # (first occurrance only)
551+ db_ver_inc_map [db_ver ] = d
552+ print "db.h: found" , db_ver , "in" , d
553+ else :
554+ # we already found a header for this library version
555+ if db_setup_debug : print "db.h: ignoring" , d
556+ else :
557+ # ignore this header, it didn't contain a version number
558+ if db_setup_debug : print "db.h: unsupported version" , db_ver , "in" , d
559+
560+ db_found_vers = db_ver_inc_map .keys ()
561+ db_found_vers .sort ()
562+
563+ while db_found_vers :
564+ db_ver = db_found_vers .pop ()
565+ db_incdir = db_ver_inc_map [db_ver ]
566+
567+ # check lib directories parallel to the location of the header
568+ db_dirs_to_check = [
569+ os .path .join (db_incdir , '..' , 'lib64' ),
570+ os .path .join (db_incdir , '..' , 'lib' ),
571+ os .path .join (db_incdir , '..' , '..' , 'lib64' ),
572+ os .path .join (db_incdir , '..' , '..' , 'lib' ),
573+ ]
574+ db_dirs_to_check = filter (os .path .isdir , db_dirs_to_check )
575+
576+ # Look for a version specific db-X.Y before an ambiguoius dbX
577+ # XXX should we -ever- look for a dbX name? Do any
578+ # systems really not name their library by version and
579+ # symlink to more general names?
580+ for dblib in (('db-%d.%d' % db_ver ), ('db%d' % db_ver [0 ])):
581+ dblib_file = self .compiler .find_library_file (
582+ db_dirs_to_check + lib_dirs , dblib )
583+ if dblib_file :
584+ dblib_dir = [ os .path .abspath (os .path .dirname (dblib_file )) ]
585+ raise db_found
586+ else :
587+ if db_setup_debug : print "db lib: " , dblib , "not found"
588+
589+ except db_found :
590+ print "db lib: using" , db_ver , dblib
591+ if db_setup_debug : print "db: lib dir" , dblib_dir , "inc dir" , db_incdir
592+ db_incs = [db_incdir ]
571593 dblibs = [dblib ]
572- # A default source build puts Berkeley DB in something like
573- # /usr/local/Berkeley.3.3 and the lib dir under that isn't
574- # normally on ld.so's search path, unless the sysadmin has hacked
575- # /etc/ld.so.conf. We add the directory to runtime_library_dirs
576- # so the proper -R/--rpath flags get passed to the linker. This
577- # is usually correct and most trouble free, but may cause problems
578- # in some unusual system configurations (e.g. the directory is on
579- # an NFS server that goes away).
594+ # We add the runtime_library_dirs argument because the
595+ # BerkeleyDB lib we're linking against often isn't in the
596+ # system dynamic library search path. This is usually
597+ # correct and most trouble free, but may cause problems in
598+ # some unusual system configurations (e.g. the directory
599+ # is on an NFS server that goes away).
580600 exts .append (Extension ('_bsddb' , ['_bsddb.c' ],
581601 library_dirs = dblib_dir ,
582602 runtime_library_dirs = dblib_dir ,
583603 include_dirs = db_incs ,
584604 libraries = dblibs ))
585605 else :
606+ if db_setup_debug : print "db: no appropriate library found"
586607 db_incs = None
587608 dblibs = []
588609 dblib_dir = None
0 commit comments