From 1a890d82c387d2902c22c9a5b86007281cfe86d2 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 24 Jul 2003 07:41:36 +0000 Subject: * 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/mkmf.rb | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'lib') 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') -- cgit v1.2.3