From 5e6bf721d59f372a66207c38d9b3f5f7a2e3f468 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 16 Sep 2006 07:14:37 +0000 Subject: * ext/dbm/extconf.rb: allow multiple candidates for dbm-type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dbm/extconf.rb | 60 +++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'ext/dbm') diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb index 52ec688952..0074ab605b 100644 --- a/ext/dbm/extconf.rb +++ b/ext/dbm/extconf.rb @@ -2,9 +2,13 @@ require 'mkmf' dir_config("dbm") -dblib = with_config("dbm-type", nil) +if dblib = with_config("dbm-type", nil) + dblib = dblib.split(/[ ,]+/) +else + dblib = %w(db db2 db1 dbm gdbm gdbm_compat qdbm) +end -$dbm_conf_headers = { +headers = { "db" => ["db.h"], "db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"], "db2" => ["db2/db.h", "db2.h", "db.h"], @@ -14,48 +18,36 @@ $dbm_conf_headers = { "qdbm" => ["relic.h"], } -def db_check(db) - $dbm_conf_db_prefix = "" - $dbm_conf_have_gdbm = false - hsearch = "" +def headers.db_check(db) + db_prefix = nil + have_gdbm = false + hsearch = nil case db when /^db2?$/ - $dbm_conf_db_prefix = "__db_n" + db_prefix = "__db_n" hsearch = "-DDB_DBM_HSEARCH " when "gdbm" - $dbm_conf_have_gdbm = true + have_gdbm = true when "gdbm_compat" - $dbm_conf_have_gdbm = true + have_gdbm = true have_library("gdbm") or return false end - - if have_library(db, db_prefix("dbm_open")) || have_func(db_prefix("dbm_open")) - for hdr in $dbm_conf_headers.fetch(db, ["ndbm.h"]) - if have_header(hdr.dup) and have_type("DBM", hdr.dup, hsearch) - $defs << hsearch << '-DDBM_HDR="<'+hdr+'>"' - return true - end - end - end - return false -end - -def db_prefix(func) - $dbm_conf_db_prefix+func -end - -if dblib - dbm_hdr = db_check(dblib) -else - dbm_hdr = %w(db db2 db1 dbm gdbm gdbm_compat qdbm).any? do |dblib| - db_check(dblib) + db_prefix ||= "" + + if (have_library(db, db_prefix+"dbm_open") || have_func(db_prefix+"dbm_open")) and + hdr = self.fetch(db, ["ndbm.h"]).find {|hdr| have_type("DBM", hdr, hsearch)} + have_func(db_prefix+"dbm_clearerr") unless have_gdbm + $defs << hsearch if hsearch + $defs << '-DDBM_HDR="<'+hdr+'>"' + true + else + false end end -have_header("cdefs.h") -have_header("sys/cdefs.h") -if dbm_hdr and have_func(db_prefix("dbm_open")) - have_func(db_prefix("dbm_clearerr")) unless $dbm_conf_have_gdbm +if dblib.any? {|db| headers.db_check(db)} + have_header("cdefs.h") + have_header("sys/cdefs.h") create_makefile("dbm") end -- cgit v1.2.3