* 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
This commit is contained in:
nobu 2003-07-24 07:41:36 +00:00
Родитель 71c9abdd06
Коммит 1a890d82c3
3 изменённых файлов: 96 добавлений и 1 удалений

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

@ -1,3 +1,12 @@
Thu Jul 24 16:41:31 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* 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 <nobu.nokada@softhome.net>
* ChangeLog (add-log-time-format): "%c" contains timezone on

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

@ -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

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

@ -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')