2013-05-23 17:49:10 +04:00
|
|
|
# configure option:
|
|
|
|
# --with-dbm-type=COMMA-SEPARATED-NDBM-TYPES
|
|
|
|
#
|
|
|
|
# ndbm type:
|
|
|
|
# libc ndbm compatible library in libc.
|
|
|
|
# db Berkeley DB (libdb)
|
|
|
|
# db2 Berkeley DB (libdb2)
|
|
|
|
# db1 Berkeley DB (libdb1)
|
|
|
|
# db5 Berkeley DB (libdb5)
|
|
|
|
# db4 Berkeley DB (libdb4)
|
|
|
|
# db3 Berkeley DB (libdb3)
|
|
|
|
# gdbm_compat GDBM since 1.8.1 (libgdbm_compat)
|
|
|
|
# gdbm GDBM until 1.8.0 (libgdbm)
|
|
|
|
# qdbm QDBM (libqdbm)
|
|
|
|
# ndbm Some legacy OS may have libndbm.
|
|
|
|
|
2013-08-12 07:59:50 +04:00
|
|
|
# :stopdoc:
|
1999-01-20 07:59:39 +03:00
|
|
|
require 'mkmf'
|
1999-08-24 12:21:56 +04:00
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
dir_config("dbm")
|
2001-05-02 08:22:21 +04:00
|
|
|
|
2006-09-16 11:14:37 +04:00
|
|
|
if dblib = with_config("dbm-type", nil)
|
|
|
|
dblib = dblib.split(/[ ,]+/)
|
|
|
|
else
|
2012-02-18 13:47:07 +04:00
|
|
|
dblib = %w(libc db db2 db1 db5 db4 db3 gdbm_compat gdbm qdbm)
|
2006-09-16 11:14:37 +04:00
|
|
|
end
|
2001-05-02 08:22:21 +04:00
|
|
|
|
2006-09-16 11:14:37 +04:00
|
|
|
headers = {
|
2012-02-17 16:10:32 +04:00
|
|
|
"libc" => ["ndbm.h"], # 4.3BSD original ndbm, Berkeley DB 1 in 4.4BSD libc.
|
2001-05-24 09:28:15 +04:00
|
|
|
"db" => ["db.h"],
|
2001-05-24 19:55:40 +04:00
|
|
|
"db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"],
|
2001-05-24 09:28:15 +04:00
|
|
|
"db2" => ["db2/db.h", "db2.h", "db.h"],
|
2010-06-11 19:40:39 +04:00
|
|
|
"db3" => ["db3/db.h", "db3.h", "db.h"],
|
|
|
|
"db4" => ["db4/db.h", "db4.h", "db.h"],
|
|
|
|
"db5" => ["db5/db.h", "db5.h", "db.h"],
|
2012-02-25 12:42:00 +04:00
|
|
|
"gdbm_compat" => ["gdbm-ndbm.h", "gdbm/ndbm.h", "ndbm.h"], # GDBM since 1.8.1
|
|
|
|
"gdbm" => ["gdbm-ndbm.h", "gdbm/ndbm.h", "ndbm.h"], # GDBM until 1.8.0
|
|
|
|
"qdbm" => ["qdbm/relic.h", "relic.h"],
|
2001-05-24 09:28:15 +04:00
|
|
|
}
|
|
|
|
|
2011-11-08 18:34:39 +04:00
|
|
|
class << headers
|
|
|
|
attr_accessor :found
|
2011-11-10 10:43:46 +04:00
|
|
|
attr_accessor :defs
|
2011-11-08 18:34:39 +04:00
|
|
|
end
|
|
|
|
headers.found = []
|
2011-11-10 10:43:46 +04:00
|
|
|
headers.defs = nil
|
2011-11-07 15:17:17 +04:00
|
|
|
|
2011-11-13 14:58:18 +04:00
|
|
|
def headers.db_check(db, hdr)
|
2011-11-13 10:41:19 +04:00
|
|
|
old_libs = $libs.dup
|
|
|
|
old_defs = $defs.dup
|
2011-11-13 14:58:18 +04:00
|
|
|
result = db_check2(db, hdr)
|
2011-11-13 07:47:07 +04:00
|
|
|
if !result
|
|
|
|
$libs = old_libs
|
|
|
|
$defs = old_defs
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2012-02-18 13:47:07 +04:00
|
|
|
def have_declared_libvar(var, headers = nil, opt = "", &b)
|
2011-12-06 07:38:07 +04:00
|
|
|
checking_for checking_message([*var].compact.join(' '), headers, opt) do
|
2012-02-18 13:47:07 +04:00
|
|
|
try_declared_libvar(var, headers, opt, &b)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_declared_libvar(var, headers = nil, opt = "", &b)
|
|
|
|
if try_link(<<"SRC", opt, &b)
|
|
|
|
#{cpp_include(headers)}
|
|
|
|
/*top*/
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
void *conftest_var = &#{var};
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SRC
|
|
|
|
$defs.push(format("-DHAVE_DECLARED_LIBVAR_%s", var.tr_cpp))
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
2011-12-06 07:38:07 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-18 13:47:07 +04:00
|
|
|
def have_undeclared_libvar(var, headers = nil, opt = "", &b)
|
|
|
|
checking_for checking_message([*var].compact.join(' '), headers, opt) do
|
|
|
|
try_undeclared_libvar(var, headers, opt, &b)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_undeclared_libvar(var, headers = nil, opt = "", &b)
|
2011-12-06 07:38:07 +04:00
|
|
|
var, type = *var
|
|
|
|
if try_link(<<"SRC", opt, &b)
|
|
|
|
#{cpp_include(headers)}
|
|
|
|
/*top*/
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
typedef #{type || 'int'} conftest_type;
|
|
|
|
extern conftest_type #{var};
|
|
|
|
conftest_type *conftest_var = &#{var};
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SRC
|
2012-02-18 13:47:07 +04:00
|
|
|
$defs.push(format("-DHAVE_UNDECLARED_LIBVAR_%s", var.tr_cpp))
|
2011-12-06 07:38:07 +04:00
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-18 20:06:52 +04:00
|
|
|
def have_empty_macro_dbm_clearerr(headers = nil, opt = "", &b)
|
|
|
|
checking_for checking_message('empty macro of dbm_clearerr(foobarbaz)',
|
|
|
|
headers, opt) do
|
|
|
|
try_toplevel('dbm_clearerr(foobarbaz)', headers, opt, &b)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_toplevel(src, headers = nil, opt = "", &b)
|
|
|
|
if try_compile(<<"SRC", opt, &b)
|
|
|
|
#{cpp_include(headers)}
|
|
|
|
/*top*/
|
|
|
|
#{src}
|
|
|
|
SRC
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-06 07:38:07 +04:00
|
|
|
|
2011-11-13 14:58:18 +04:00
|
|
|
def headers.db_check2(db, hdr)
|
2012-02-18 13:47:07 +04:00
|
|
|
$defs.push(%{-DRUBYDBM_DBM_HEADER='"#{hdr}"'})
|
|
|
|
$defs.push(%{-DRUBYDBM_DBM_TYPE='"#{db}"'})
|
|
|
|
|
2006-09-16 11:14:37 +04:00
|
|
|
hsearch = nil
|
2001-05-07 14:56:01 +04:00
|
|
|
|
|
|
|
case db
|
2010-06-11 19:40:39 +04:00
|
|
|
when /^db[2-5]?$/
|
2011-11-10 10:43:46 +04:00
|
|
|
hsearch = "-DDB_DBM_HSEARCH"
|
2002-12-13 20:14:18 +03:00
|
|
|
when "gdbm_compat"
|
|
|
|
have_library("gdbm") or return false
|
2001-05-02 08:22:21 +04:00
|
|
|
end
|
2006-09-16 11:14:37 +04:00
|
|
|
|
2012-02-17 02:32:10 +04:00
|
|
|
if !have_type("DBM", hdr, hsearch)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-17 16:29:50 +04:00
|
|
|
# 'libc' means ndbm is provided by libc.
|
|
|
|
# 4.3BSD original ndbm is contained in libc.
|
|
|
|
# 4.4BSD (and its derivatives such as NetBSD) contains Berkeley DB 1 in libc.
|
2012-02-17 02:32:10 +04:00
|
|
|
if !(db == 'libc' ? have_func('dbm_open("", 0, 0)', hdr, hsearch) :
|
|
|
|
have_library(db, 'dbm_open("", 0, 0)', hdr, hsearch))
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-20 19:00:35 +04:00
|
|
|
# Skip a mismatch of Berkeley DB's ndbm.h and old GDBM library.
|
2012-02-17 16:29:50 +04:00
|
|
|
#
|
|
|
|
# dbm_clearerr() should be available for any ndbm implementation.
|
|
|
|
# It is available since the original (4.3BSD) ndbm and standardized by POSIX.
|
|
|
|
#
|
|
|
|
# However "can't resolve symbol 'dbm_clearerr'" problem may be caused by
|
2012-02-20 19:00:35 +04:00
|
|
|
# header/library mismatch: Berkeley DB ndbm.h and GDBM library until 1.8.3.
|
|
|
|
# GDBM (until 1.8.3) provides dbm_clearerr() as a empty macro in the header
|
2012-02-17 16:29:50 +04:00
|
|
|
# and the library don't provide dbm_clearerr().
|
|
|
|
# Berkeley DB provides dbm_clearerr() as a usual function.
|
2012-02-20 19:00:35 +04:00
|
|
|
# So Berkeley DB header with GDBM library causes the problem.
|
2012-02-17 16:29:50 +04:00
|
|
|
#
|
2012-02-17 02:32:10 +04:00
|
|
|
if !have_func('dbm_clearerr((DBM *)0)', hdr, hsearch)
|
|
|
|
return false
|
2001-05-02 08:22:21 +04:00
|
|
|
end
|
2012-02-17 02:32:10 +04:00
|
|
|
|
2012-02-23 07:23:40 +04:00
|
|
|
# Berkeley DB's ndbm.h (since 1.85 at least) defines DBM_SUFFIX.
|
2012-09-04 04:57:31 +04:00
|
|
|
# Note that _DB_H_ is not defined on Mac OS X because
|
2012-02-23 07:23:40 +04:00
|
|
|
# it uses Berkeley DB 1 but ndbm.h doesn't include db.h.
|
|
|
|
have_db_header = have_macro('DBM_SUFFIX', hdr, hsearch)
|
2012-02-22 01:13:52 +04:00
|
|
|
|
2012-02-18 20:06:52 +04:00
|
|
|
# Old GDBM's ndbm.h, until 1.8.3, defines dbm_clearerr as a macro which
|
|
|
|
# expands to no tokens.
|
2012-02-20 14:16:25 +04:00
|
|
|
have_gdbm_header1 = have_empty_macro_dbm_clearerr(hdr, hsearch)
|
2012-02-18 20:06:52 +04:00
|
|
|
|
2012-02-18 13:47:07 +04:00
|
|
|
# Recent GDBM's ndbm.h, since 1.9, includes gdbm.h and it defines _GDBM_H_.
|
|
|
|
# ndbm compatibility layer of GDBM is provided by libgdbm (until 1.8.0)
|
|
|
|
# and libgdbm_compat (since 1.8.1).
|
2012-02-20 14:16:25 +04:00
|
|
|
have_gdbm_header2 = have_macro('_GDBM_H_', hdr, hsearch)
|
2012-02-18 13:47:07 +04:00
|
|
|
|
|
|
|
# 4.3BSD's ndbm.h defines _DBM_IOERR.
|
|
|
|
# The original ndbm is provided by libc in 4.3BSD.
|
2012-02-20 14:16:25 +04:00
|
|
|
have_ndbm_header = have_macro('_DBM_IOERR', hdr, hsearch)
|
2012-02-18 13:47:07 +04:00
|
|
|
|
2012-02-20 19:00:35 +04:00
|
|
|
# GDBM provides ndbm functions in libgdbm_compat since GDBM 1.8.1.
|
2012-02-18 19:31:09 +04:00
|
|
|
# GDBM's ndbm.h defines _GDBM_H_ since GDBM 1.9.
|
2012-02-20 14:16:25 +04:00
|
|
|
# If _GDBM_H_ is defined, 'gdbm_compat' is required and reject 'gdbm'.
|
|
|
|
if have_gdbm_header2 && db == 'gdbm'
|
2012-02-18 19:31:09 +04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-22 01:13:52 +04:00
|
|
|
if have_db_header
|
|
|
|
$defs.push('-DRUBYDBM_DB_HEADER')
|
|
|
|
end
|
|
|
|
|
2012-02-20 14:16:25 +04:00
|
|
|
have_gdbm_header = have_gdbm_header1 | have_gdbm_header2
|
|
|
|
if have_gdbm_header
|
2012-02-19 18:02:14 +04:00
|
|
|
$defs.push('-DRUBYDBM_GDBM_HEADER')
|
|
|
|
end
|
2012-02-18 20:06:52 +04:00
|
|
|
|
2012-02-20 19:00:35 +04:00
|
|
|
# ndbm.h is provided by the original (4.3BSD) ndbm,
|
2012-02-17 16:29:50 +04:00
|
|
|
# Berkeley DB 1 in libc of 4.4BSD and
|
2012-02-20 19:00:35 +04:00
|
|
|
# ndbm compatibility layer of GDBM.
|
2012-02-17 16:29:50 +04:00
|
|
|
# So, try to check header/library mismatch.
|
|
|
|
#
|
2012-02-20 19:00:35 +04:00
|
|
|
# Several (possibly historical) distributions provides libndbm.
|
|
|
|
# It may be Berkeley DB, GDBM or 4.3BSD ndbm.
|
|
|
|
# So mismatch check is not performed for that.
|
|
|
|
# Note that libndbm is searched only when --with-dbm-type=ndbm is
|
|
|
|
# given for configure.
|
|
|
|
#
|
2012-02-20 15:05:31 +04:00
|
|
|
if hdr == 'ndbm.h' && db != 'libc' && db != 'ndbm'
|
2012-02-20 14:16:25 +04:00
|
|
|
if /\Adb\d?\z/ !~ db && have_db_header
|
2012-02-17 16:29:50 +04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-20 14:16:25 +04:00
|
|
|
if /\Agdbm/ !~ db && have_gdbm_header
|
2012-02-17 16:29:50 +04:00
|
|
|
return false
|
|
|
|
end
|
2012-09-04 04:57:31 +04:00
|
|
|
|
2012-02-20 14:16:25 +04:00
|
|
|
if have_ndbm_header
|
2012-02-17 16:29:50 +04:00
|
|
|
return false
|
|
|
|
end
|
2012-02-17 02:32:10 +04:00
|
|
|
end
|
|
|
|
|
2012-02-18 13:47:07 +04:00
|
|
|
# Berkeley DB
|
|
|
|
have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
|
|
|
|
|
|
|
|
# GDBM
|
2012-02-20 14:16:25 +04:00
|
|
|
have_gdbm_version = have_declared_libvar("gdbm_version", hdr, hsearch)
|
2012-02-20 19:00:35 +04:00
|
|
|
# gdbm_version is available since very old version (GDBM 1.5 at least).
|
|
|
|
# However it is not declared by ndbm.h until GDBM 1.8.3.
|
2012-02-18 13:47:07 +04:00
|
|
|
# We can't include both ndbm.h and gdbm.h because they both define datum type.
|
2012-02-20 19:00:35 +04:00
|
|
|
# ndbm.h includes gdbm.h and gdbm_version is declared since GDBM 1.9.
|
2012-02-20 14:16:25 +04:00
|
|
|
have_gdbm_version |= have_undeclared_libvar(["gdbm_version", "char *"], hdr, hsearch)
|
2012-02-18 13:47:07 +04:00
|
|
|
|
|
|
|
# QDBM
|
|
|
|
have_var("dpversion", hdr, hsearch)
|
|
|
|
|
|
|
|
# detect mismatch between GDBM header and other library.
|
|
|
|
# If GDBM header is included, GDBM library should be linked.
|
2012-02-20 14:16:25 +04:00
|
|
|
if have_gdbm_header && !have_gdbm_version
|
2012-02-18 13:47:07 +04:00
|
|
|
return false
|
2012-02-17 02:32:10 +04:00
|
|
|
end
|
2012-02-18 13:47:07 +04:00
|
|
|
|
2012-02-22 01:04:04 +04:00
|
|
|
# DBC type is required to disable error messages by Berkeley DB 2 or later.
|
|
|
|
if have_db_header
|
|
|
|
have_type("DBC", hdr, hsearch)
|
|
|
|
end
|
|
|
|
|
2012-02-17 02:32:10 +04:00
|
|
|
if hsearch
|
|
|
|
$defs << hsearch
|
|
|
|
@defs = hsearch
|
|
|
|
end
|
|
|
|
$defs << '-DDBM_HDR="<'+hdr+'>"'
|
|
|
|
@found << hdr
|
|
|
|
|
2012-02-19 18:44:24 +04:00
|
|
|
puts "header: #{hdr}"
|
|
|
|
puts "library: #{db}"
|
|
|
|
|
2012-02-17 02:32:10 +04:00
|
|
|
true
|
2001-05-02 08:22:21 +04:00
|
|
|
end
|
|
|
|
|
2011-11-13 14:58:18 +04:00
|
|
|
if dblib.any? {|db| headers.fetch(db, ["ndbm.h"]).any? {|hdr| headers.db_check(db, hdr) } }
|
2006-09-16 11:14:37 +04:00
|
|
|
have_header("cdefs.h")
|
|
|
|
have_header("sys/cdefs.h")
|
2011-11-11 16:03:51 +04:00
|
|
|
have_func("dbm_pagfno((DBM *)0)", headers.found, headers.defs)
|
|
|
|
have_func("dbm_dirfno((DBM *)0)", headers.found, headers.defs)
|
2011-11-13 18:47:31 +04:00
|
|
|
convertible_int("datum.dsize", headers.found, headers.defs)
|
2014-10-05 03:33:01 +04:00
|
|
|
checking_for("sizeof(DBM) is available") {
|
|
|
|
if try_compile(<<SRC)
|
|
|
|
#ifdef HAVE_CDEFS_H
|
|
|
|
# include <cdefs.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_CDEFS_H
|
|
|
|
# include <sys/cdefs.h>
|
|
|
|
#endif
|
|
|
|
#include DBM_HDR
|
|
|
|
|
|
|
|
const int sizeof_DBM = (int)sizeof(DBM);
|
|
|
|
SRC
|
|
|
|
$defs << '-DDBM_SIZEOF_DBM=sizeof(DBM)'
|
|
|
|
else
|
|
|
|
$defs << '-DDBM_SIZEOF_DBM=0'
|
|
|
|
end
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
create_makefile("dbm")
|
|
|
|
end
|
2013-08-12 07:59:50 +04:00
|
|
|
# :startdoc:
|