From 21ce8b68ab45872680f6ea30bb507a8d49951076 Mon Sep 17 00:00:00 2001 From: Ash Moran Date: Sun, 7 Aug 2011 08:52:36 +0100 Subject: [PATCH 1/4] Make the C wrapper compile BDB 5.1 as if it was a recent 4.X --- ext/bdb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/bdb.c b/ext/bdb.c index 8a70964..fefe1c0 100644 --- a/ext/bdb.c +++ b/ext/bdb.c @@ -827,7 +827,7 @@ VALUE db_join(VALUE obj, VALUE vacurs, VALUE vflags) return jcurs; } -#if DB_VERSION_MINOR > 3 +#if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 3 /* * call-seq: * db.compact(txn,start_key,stop_key,compact_opts,flags) -> end_key @@ -2105,7 +2105,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags) rv=dbh->db->get_type(dbh->db,&dbtype); if (rv) raise_error(rv,"db_stat %s",db_strerror(rv)); -#if DB_VERSION_MINOR > 2 +#if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 2 rv=dbh->db->stat(dbh->db,txn?txn->txn:NULL,&(su.stat),flags); #else rv=dbh->db->stat(dbh->db,&(su.stat),flags); @@ -2151,7 +2151,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags) bs_int(bt_nkeys); /* Number of unique keys. */ bs_int(bt_ndata); /* Number of data items. */ bs_int(bt_pagesize); /* Page size. */ -#if DB_VERSION_MINOR < 4 +#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4 bs_int(bt_maxkey); /* Maxkey value. */ #endif bs_int(bt_minkey); /* Minkey value. */ @@ -2162,7 +2162,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags) bs_int(bt_leaf_pg); /* Leaf pages. */ bs_int(bt_dup_pg); /* Duplicate pages. */ bs_int(bt_over_pg); /* Overflow pages. */ -#if DB_VERSION_MINOR > 2 +#if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 2 bs_int(bt_empty_pg); /* Empty pages. */ #endif bs_int(bt_free); /* Pages on the free list. */ @@ -3331,7 +3331,7 @@ EXCEPTIONS_CREATE rb_define_method(cDb,"sync",db_sync,0); rb_define_method(cDb,"truncate",db_truncate,1); -#if DB_VERSION_MINOR > 3 +#if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 3 rb_define_method(cDb,"compact",db_compact,5); #endif From ecbb0191748c52da252d7f5fa553c3ccc3253a21 Mon Sep 17 00:00:00 2001 From: Ash Moran Date: Sun, 7 Aug 2011 08:53:49 +0100 Subject: [PATCH 2/4] Add checks for BDB 5.0 and 5.1 --- ext/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index 1110a04..fd1a9dc 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -7,7 +7,7 @@ require 'mkmf' end end -%w(db-4.9 db-4.8 db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2).each do |ver| +%w(db-5.1 db-5.0 db-4.9 db-4.8 db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2).each do |ver| have_library ver, 'db_version', 'db.h' end From 46dc02f06b80d9ce2a17fcb01ffd75c77fc7c4cf Mon Sep 17 00:00:00 2001 From: Ash Moran Date: Sun, 7 Aug 2011 08:54:38 +0100 Subject: [PATCH 3/4] Re-order the directories mkmf searches for BDB so that a Homebrew install in /usr/local is detected --- ext/extconf.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index fd1a9dc..25a1b5f 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -1,7 +1,9 @@ #!/usr/bin/env ruby require 'mkmf' -%w[/usr/local /usr / /usr/local/db* /usr/local/BerkeleyDB*].each do |pdir| +# This list is checked in reverse order, so this order allows mkmf on my Mac +# to find BDB installed via Homebrew (/usr/local) before system installs +%w[/usr / /usr/local /usr/local/db* /usr/local/BerkeleyDB*].each do |pdir| Dir[pdir].each do |dir| dir_config('db', "#{dir}/include", "#{dir}/lib") end From c92eea42c3f768897113d9f91348c935a3f6ea97 Mon Sep 17 00:00:00 2001 From: Ash Moran Date: Sun, 7 Aug 2011 08:54:47 +0100 Subject: [PATCH 4/4] Trivial whitespace cleanup --- ext/extconf.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/extconf.rb b/ext/extconf.rb index 25a1b5f..bf07331 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -20,6 +20,7 @@ def create_header end message("Writing bdb_aux._c (defines), this takes a while\n") + db_header = $CPPFLAGS.split.select { |f| f =~ /^-I/ }.map { |e| f = File.join(e[2..-1], 'db.h') File.exists?(f) ? f : nil