* ext/dbm/extconf.rb: detect GDBM's ndbm.h by testing dbm_clearerr is

an empty macro.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2012-02-18 16:06:52 +00:00
Родитель 0ffc74dece
Коммит 0187905af2
3 изменённых файлов: 34 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Sun Feb 19 01:05:41 2012 Tanaka Akira <akr@fsij.org>
* ext/dbm/extconf.rb: detect GDBM's ndbm.h by testing dbm_clearerr is
an empty macro.
Sun Feb 19 00:25:55 2012 Tanaka Akira <akr@fsij.org>
* ext/dbm/extconf.rb: don't choose 'dbm' if _GDB_H_ is defined which

Просмотреть файл

@ -1096,7 +1096,7 @@ Init_dbm(void)
rb_define_const(rb_cDBM, "VERSION", rb_sprintf("QDBM %s", dpversion));
#elif defined(_DB_H_)
rb_define_const(rb_cDBM, "VERSION", rb_str_new2("Berkeley DB (unknown)"));
#elif defined(_GDBM_H_)
#elif defined(_GDBM_H_) || defined(HAVE_EMPTY_MACRO_DBM_CLEARERR)
rb_define_const(rb_cDBM, "VERSION", rb_str_new2("GDBM (unknown)"));
#elif defined(_DBM_IOERR)
rb_define_const(rb_cDBM, "VERSION", rb_str_new2("NDBM (4.3BSD)"));

Просмотреть файл

@ -86,6 +86,26 @@ SRC
end
end
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
$defs.push("-DHAVE_EMPTY_MACRO_DBM_CLEARERR")
true
else
false
end
end
def headers.db_check2(db, hdr)
$defs.push(%{-DRUBYDBM_DBM_HEADER='"#{hdr}"'})
@ -132,10 +152,14 @@ def headers.db_check2(db, hdr)
# it defines _DB_H_.
have_db_header_macro = have_macro('_DB_H_', hdr, hsearch)
# Old GDBM's ndbm.h, until 1.8.3, defines dbm_clearerr as a macro which
# expands to no tokens.
have_gdbm_header_macro1 = have_empty_macro_dbm_clearerr(hdr, hsearch)
# 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).
have_gdbm_header_macro = have_macro('_GDBM_H_', hdr, hsearch)
have_gdbm_header_macro2 = have_macro('_GDBM_H_', hdr, hsearch)
# 4.3BSD's ndbm.h defines _DBM_IOERR.
# The original ndbm is provided by libc in 4.3BSD.
@ -144,10 +168,12 @@ def headers.db_check2(db, hdr)
# GDBM provides NDBM functions in libgdbm_compat since GDBM 1.8.1.
# GDBM's ndbm.h defines _GDBM_H_ since GDBM 1.9.
# So, reject 'gdbm'. 'gdbm_compat' is required.
if have_gdbm_header_macro && db == 'gdbm'
if have_gdbm_header_macro2 && db == 'gdbm'
return false
end
have_gdbm_header_macro = have_gdbm_header_macro1 | have_gdbm_header_macro2
# ndbm.h is provided by the original (4.3BSD) dbm,
# Berkeley DB 1 in libc of 4.4BSD and
# ndbm compatibility layer of gdbm.