summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-24 07:41:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-24 07:41:36 +0000
commit1a890d82c387d2902c22c9a5b86007281cfe86d2 (patch)
treee0c77d0e1ee5dec823f3f72040ef882c007f6f92 /lib
parent71c9abdd06bd07a6f8658a6f256b72afc813be2c (diff)
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/mkmf.rb86
1 files changed, 86 insertions, 0 deletions
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(<<SRC, opt)
+#{COMMON_HEADERS}
+#{headers}
+int tmp[(#{expr}) ? 1 : -1];
+SRC
+end
+
+def try_constant(const, headers = nil, opt = "")
+ if true # CROSS_COMPILING
+ unless try_compile(<<"SRC", opt)
+#{COMMON_HEADERS}
+#{cpp_include(headers)}
+int tmp = #{const};
+SRC
+ return nil
+ end
+ if try_static_assert("#{const} < 0", headers, opt)
+ neg = true
+ const = "-(#{const})"
+ elsif try_static_assert("#{const} == 0", headers, opt)
+ return 0
+ end
+ upper = 1
+ until try_static_assert("#{const} < #{upper}", headers, opt)
+ lower = upper
+ upper <<= 1
+ end
+ return nil unless lower
+ until try_static_assert("#{const} == #{upper}", headers, opt)
+ if try_static_assert("#{const} > #{(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 <stdio.h>
+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')