2015-12-16 00:31:54 -05:00
|
|
|
# frozen_string_literal: false
|
2013-05-23 09: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-11 23:59:50 -04:00
|
|
|
# :stopdoc:
|
1999-01-19 23:59:39 -05:00
|
|
|
require 'mkmf'
|
1999-08-24 04:21:56 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
dir_config("dbm")
|
2001-05-02 00:22:21 -04:00
|
|
|
|
2006-09-16 03:14:37 -04:00
|
|
|
if dblib = with_config("dbm-type", nil)
|
|
|
|
dblib = dblib.split(/[ ,]+/)
|
|
|
|
else
|
2012-02-18 04:47:07 -05:00
|
|
|
dblib = %w(libc db db2 db1 db5 db4 db3 gdbm_compat gdbm qdbm)
|
2006-09-16 03:14:37 -04:00
|
|
|
end
|
2001-05-02 00:22:21 -04:00
|
|
|
|
2006-09-16 03:14:37 -04:00
|
|
|
headers = {
|
2012-02-17 07:10:32 -05:00
|
|
|
"libc" => ["ndbm.h"], # 4.3BSD original ndbm, Berkeley DB 1 in 4.4BSD libc.
|
2001-05-24 01:28:15 -04:00
|
|
|
"db" => ["db.h"],
|
2001-05-24 11:55:40 -04:00
|
|
|
"db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"],
|
2001-05-24 01:28:15 -04:00
|
|
|
"db2" => ["db2/db.h", "db2.h", "db.h"],
|
2010-06-11 11: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 03:42:00 -05: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 01:28:15 -04:00
|
|
|
}
|
|
|
|
|
2011-11-08 09:34:39 -05:00
|
|
|
class << headers
|
|
|
|
attr_accessor :found
|
2011-11-10 01:43:46 -05:00
|
|
|
attr_accessor :defs
|
2011-11-08 09:34:39 -05:00
|
|
|
end
|
|
|
|
headers.found = []
|
2011-11-10 01:43:46 -05:00
|
|
|
headers.defs = nil
|
2011-11-07 06:17:17 -05:00
|
|
|
|
2011-11-13 05:58:18 -05:00
|
|
|
def headers.db_check(db, hdr)
|
2011-11-13 01:41:19 -05:00
|
|
|
old_libs = $libs.dup
|
|
|
|
old_defs = $defs.dup
|
2011-11-13 05:58:18 -05:00
|
|
|
result = db_check2(db, hdr)
|
2011-11-12 22:47:07 -05:00
|
|
|
if !result
|
|
|
|
$libs = old_libs
|
|
|
|
$defs = old_defs
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2012-02-18 04:47:07 -05:00
|
|
|
def have_declared_libvar(var, headers = nil, opt = "", &b)
|
2011-12-05 22:38:07 -05:00
|
|
|
checking_for checking_message([*var].compact.join(' '), headers, opt) do
|
2012-02-18 04:47:07 -05: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-05 22:38:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-18 04:47:07 -05: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-05 22:38:07 -05: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 04:47:07 -05:00
|
|
|
$defs.push(format("-DHAVE_UNDECLARED_LIBVAR_%s", var.tr_cpp))
|
2011-12-05 22:38:07 -05:00
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-18 11:06:52 -05: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-05 22:38:07 -05:00
|
|
|
|
2011-11-13 05:58:18 -05:00
|
|
|
def headers.db_check2(db, hdr)
|
2012-02-18 04:47:07 -05:00
|
|
|
$defs.push(%{-DRUBYDBM_DBM_HEADER='"#{hdr}"'})
|
|
|
|
$defs.push(%{-DRUBYDBM_DBM_TYPE='"#{db}"'})
|
|
|
|
|
2006-09-16 03:14:37 -04:00
|
|
|
hsearch = nil
|
2001-05-07 06:56:01 -04:00
|
|
|
|
|
|
|
case db
|
2010-06-11 11:40:39 -04:00
|
|
|
when /^db[2-5]?$/
|
2011-11-10 01:43:46 -05:00
|
|
|
hsearch = "-DDB_DBM_HSEARCH"
|
2002-12-13 12:14:18 -05:00
|
|
|
when "gdbm_compat"
|
|
|
|
have_library("gdbm") or return false
|
2001-05-02 00:22:21 -04:00
|
|
|
end
|
2006-09-16 03:14:37 -04:00
|
|
|
|
2012-02-16 17:32:10 -05:00
|
|
|
if !have_type("DBM", hdr, hsearch)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-17 07:29:50 -05: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-16 17:32:10 -05: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 10:00:35 -05:00
|
|
|
# Skip a mismatch of Berkeley DB's ndbm.h and old GDBM library.
|
2012-02-17 07:29:50 -05: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 10:00:35 -05: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 07:29:50 -05:00
|
|
|
# and the library don't provide dbm_clearerr().
|
|
|
|
# Berkeley DB provides dbm_clearerr() as a usual function.
|
2012-02-20 10:00:35 -05:00
|
|
|
# So Berkeley DB header with GDBM library causes the problem.
|
2012-02-17 07:29:50 -05:00
|
|
|
#
|
2012-02-16 17:32:10 -05:00
|
|
|
if !have_func('dbm_clearerr((DBM *)0)', hdr, hsearch)
|
|
|
|
return false
|
2001-05-02 00:22:21 -04:00
|
|
|
end
|
2012-02-16 17:32:10 -05:00
|
|
|
|
2012-02-22 22:23:40 -05:00
|
|
|
# Berkeley DB's ndbm.h (since 1.85 at least) defines DBM_SUFFIX.
|
2012-09-03 20:57:31 -04:00
|
|
|
# Note that _DB_H_ is not defined on Mac OS X because
|
2012-02-22 22:23:40 -05: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-21 16:13:52 -05:00
|
|
|
|
2012-02-18 11:06:52 -05:00
|
|
|
# Old GDBM's ndbm.h, until 1.8.3, defines dbm_clearerr as a macro which
|
|
|
|
# expands to no tokens.
|
2012-02-20 05:16:25 -05:00
|
|
|
have_gdbm_header1 = have_empty_macro_dbm_clearerr(hdr, hsearch)
|
2012-02-18 11:06:52 -05:00
|
|
|
|
2012-02-18 04:47:07 -05: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 05:16:25 -05:00
|
|
|
have_gdbm_header2 = have_macro('_GDBM_H_', hdr, hsearch)
|
2012-02-18 04:47:07 -05:00
|
|
|
|
|
|
|
# 4.3BSD's ndbm.h defines _DBM_IOERR.
|
|
|
|
# The original ndbm is provided by libc in 4.3BSD.
|
2012-02-20 05:16:25 -05:00
|
|
|
have_ndbm_header = have_macro('_DBM_IOERR', hdr, hsearch)
|
2012-02-18 04:47:07 -05:00
|
|
|
|
2012-02-20 10:00:35 -05:00
|
|
|
# GDBM provides ndbm functions in libgdbm_compat since GDBM 1.8.1.
|
2012-02-18 10:31:09 -05:00
|
|
|
# GDBM's ndbm.h defines _GDBM_H_ since GDBM 1.9.
|
2012-02-20 05:16:25 -05:00
|
|
|
# If _GDBM_H_ is defined, 'gdbm_compat' is required and reject 'gdbm'.
|
|
|
|
if have_gdbm_header2 && db == 'gdbm'
|
2012-02-18 10:31:09 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-21 16:13:52 -05:00
|
|
|
if have_db_header
|
|
|
|
$defs.push('-DRUBYDBM_DB_HEADER')
|
|
|
|
end
|
|
|
|
|
2012-02-20 05:16:25 -05:00
|
|
|
have_gdbm_header = have_gdbm_header1 | have_gdbm_header2
|
|
|
|
if have_gdbm_header
|
2012-02-19 09:02:14 -05:00
|
|
|
$defs.push('-DRUBYDBM_GDBM_HEADER')
|
|
|
|
end
|
2012-02-18 11:06:52 -05:00
|
|
|
|
2012-02-20 10:00:35 -05:00
|
|
|
# ndbm.h is provided by the original (4.3BSD) ndbm,
|
2012-02-17 07:29:50 -05:00
|
|
|
# Berkeley DB 1 in libc of 4.4BSD and
|
2012-02-20 10:00:35 -05:00
|
|
|
# ndbm compatibility layer of GDBM.
|
2012-02-17 07:29:50 -05:00
|
|
|
# So, try to check header/library mismatch.
|
|
|
|
#
|
2012-02-20 10:00:35 -05: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 06:05:31 -05:00
|
|
|
if hdr == 'ndbm.h' && db != 'libc' && db != 'ndbm'
|
2012-02-20 05:16:25 -05:00
|
|
|
if /\Adb\d?\z/ !~ db && have_db_header
|
2012-02-17 07:29:50 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-02-20 05:16:25 -05:00
|
|
|
if /\Agdbm/ !~ db && have_gdbm_header
|
2012-02-17 07:29:50 -05:00
|
|
|
return false
|
|
|
|
end
|
2012-09-03 20:57:31 -04:00
|
|
|
|
2012-02-20 05:16:25 -05:00
|
|
|
if have_ndbm_header
|
2012-02-17 07:29:50 -05:00
|
|
|
return false
|
|
|
|
end
|
2012-02-16 17:32:10 -05:00
|
|
|
end
|
|
|
|
|
2012-02-18 04:47:07 -05:00
|
|
|
# Berkeley DB
|
|
|
|
have_func('db_version((int *)0, (int *)0, (int *)0)', hdr, hsearch)
|
|
|
|
|
|
|
|
# GDBM
|
2012-02-20 05:16:25 -05:00
|
|
|
have_gdbm_version = have_declared_libvar("gdbm_version", hdr, hsearch)
|
2012-02-20 10:00:35 -05: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 04:47:07 -05:00
|
|
|
# We can't include both ndbm.h and gdbm.h because they both define datum type.
|
2012-02-20 10:00:35 -05:00
|
|
|
# ndbm.h includes gdbm.h and gdbm_version is declared since GDBM 1.9.
|
2012-02-20 05:16:25 -05:00
|
|
|
have_gdbm_version |= have_undeclared_libvar(["gdbm_version", "char *"], hdr, hsearch)
|
2012-02-18 04:47:07 -05: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 05:16:25 -05:00
|
|
|
if have_gdbm_header && !have_gdbm_version
|
2012-02-18 04:47:07 -05:00
|
|
|
return false
|
2012-02-16 17:32:10 -05:00
|
|
|
end
|
2012-02-18 04:47:07 -05:00
|
|
|
|
2012-02-21 16:04:04 -05: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-16 17:32:10 -05:00
|
|
|
if hsearch
|
|
|
|
$defs << hsearch
|
|
|
|
@defs = hsearch
|
|
|
|
end
|
|
|
|
$defs << '-DDBM_HDR="<'+hdr+'>"'
|
|
|
|
@found << hdr
|
|
|
|
|
2012-02-19 09:44:24 -05:00
|
|
|
puts "header: #{hdr}"
|
|
|
|
puts "library: #{db}"
|
|
|
|
|
2012-02-16 17:32:10 -05:00
|
|
|
true
|
2001-05-02 00:22:21 -04:00
|
|
|
end
|
|
|
|
|
2011-11-13 05:58:18 -05:00
|
|
|
if dblib.any? {|db| headers.fetch(db, ["ndbm.h"]).any? {|hdr| headers.db_check(db, hdr) } }
|
2006-09-16 03:14:37 -04:00
|
|
|
have_header("cdefs.h")
|
|
|
|
have_header("sys/cdefs.h")
|
2011-11-11 07:03:51 -05:00
|
|
|
have_func("dbm_pagfno((DBM *)0)", headers.found, headers.defs)
|
|
|
|
have_func("dbm_dirfno((DBM *)0)", headers.found, headers.defs)
|
2011-11-13 09:47:31 -05:00
|
|
|
convertible_int("datum.dsize", headers.found, headers.defs)
|
2014-10-04 19: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 07:13:05 -05:00
|
|
|
create_makefile("dbm")
|
|
|
|
end
|
2013-08-11 23:59:50 -04:00
|
|
|
# :startdoc:
|