diff --git a/ChangeLog b/ChangeLog index e418956208..d02a755408 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Thu Jul 24 16:41:31 2003 Nobuyoshi Nakada + + * lib/mkmf.rb (have_type): check if a type is defined. + + * lib/mkmf.rb (check_sizeof): check size of a type. + + * ext/dbm/extconf.rb: check if type DBM is defined. + [ruby-talk:76693] + Thu Jul 24 16:18:40 2003 Nobuyoshi Nakada * ChangeLog (add-log-time-format): "%c" contains timezone on diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb index 1fc443c280..5a67603e69 100644 --- a/ext/dbm/extconf.rb +++ b/ext/dbm/extconf.rb @@ -32,7 +32,7 @@ def db_check(db) 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) + if have_header(hdr.dup) and have_type("DBM", hdr.dup, hsearch) $CFLAGS += " " + hsearch + '-DDBM_HDR="<'+hdr+'>"' return true end diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 513e7683b5..51eb169217 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -249,6 +249,60 @@ def cpp_include(header) end end +def try_static_assert(expr, headers = nil, opt = "") + headers = cpp_include(headers) + try_compile(< #{(upper+lower)/2}", headers, opt) + lower = (upper+lower)/2 + else + upper = (upper+lower)/2 + end + end + upper = -upper if neg + return upper + else + src = %{#{COMMON_HEADERS} +#{cpp_include(headers)} +#include +int main() {printf("%d\\n", (int)(#{const})); return 0;} +} + if try_link0(src, opt) + xpopen("./conftest") do |f| + return Integer(f.gets) + end + end + end + nil +end + def try_func(func, libs, headers = nil) headers = cpp_include(headers) try_link(<<"SRC", libs) or try_link(<<"SRC", libs) @@ -442,6 +496,38 @@ SRC end end +def have_type(type, header=nil, opt="") + checking_for type do + if try_compile(<<"SRC", opt) or try_compile(<<"SRC", opt) +#{COMMON_HEADERS} +#{cpp_include(header)} +static #{type} t; +SRC +#{COMMON_HEADERS} +#{cpp_include(header)} +static #{type} *t; +SRC + $defs.push(format("-DHAVE_TYPE_%s", type.upcase)) + true + else + false + end + end +end + +def check_sizeof(type, header=nil) + expr = "sizeof(#{type})" + m = "checking size of #{type}... " + message "%s", m + Logging::message "check_sizeof: %s--------------------\n", m + if size = try_constant(expr, header) + $defs.push(format("-DSIZEOF_%s", type.upcase)) + end + message(a = size ? "#{size}\n" : "failed\n") + Logging::message "-------------------- %s\n", a + r +end + def find_executable0(bin, path = nil) path = (path || ENV['PATH']).split(File::PATH_SEPARATOR) ext = config_string('EXEEXT')