1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/mkmf.rb (create_tmpsrc): add the hook for source.

[ruby-list:38122]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-08-26 11:03:53 +00:00
parent 822a11d47e
commit 4abb183807
2 changed files with 62 additions and 46 deletions

View file

@ -1,7 +1,12 @@
Tue Aug 26 20:03:50 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_tmpsrc): add the hook for source.
[ruby-list:38122]
Tue Aug 26 15:59:53 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net> Tue Aug 26 15:59:53 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* implicit.c (syck_type_id_to_taguri): corrected detection of * implicit.c (syck_type_id_to_taguri): corrected detection of
x-private types. x-private types.
Sun Aug 24 01:02:48 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Aug 24 01:02:48 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
@ -522,7 +527,6 @@ Mon Aug 4 17:25:18 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
For the changes before 1.8.0, see doc/ChangeLog-1.8.0 For the changes before 1.8.0, see doc/ChangeLog-1.8.0
Local variables:
add-log-time-format: (lambda () add-log-time-format: (lambda ()
(let* ((time (current-time)) (let* ((time (current-time))
(diff (+ (cadr time) 32400)) (diff (+ (cadr time) 32400))

View file

@ -194,14 +194,16 @@ EOM
end end
def create_tmpsrc(src) def create_tmpsrc(src)
src = yield(src) if block_given?
src = src.sub(/[^\n]\z/, "\\&\n")
open(CONFTEST_C, "w") do |cfile| open(CONFTEST_C, "w") do |cfile|
cfile.print src cfile.print src
end end
src
end end
def try_do(src, command) def try_do(src, command, &b)
src = src.sub(/[^\n]\z/, "\\&\n") src = create_tmpsrc(src, &b)
create_tmpsrc(src)
xsystem(command) xsystem(command)
ensure ensure
log_src(src) log_src(src)
@ -234,24 +236,24 @@ def libpathflag(libpath=$LIBPATH)
libpath.map{|x| LIBPATHFLAG % %["#{x}"]}.join libpath.map{|x| LIBPATHFLAG % %["#{x}"]}.join
end end
def try_link0(src, opt="") def try_link0(src, opt="", &b)
try_do(src, link_command("", opt)) try_do(src, link_command("", opt), &b)
end end
def try_link(src, opt="") def try_link(src, opt="", &b)
try_link0(src, opt) try_link0(src, opt, &b)
ensure ensure
rm_f "conftest*", "c0x32*" rm_f "conftest*", "c0x32*"
end end
def try_compile(src, opt="") def try_compile(src, opt="", &b)
try_do(src, cc_command(opt)) try_do(src, cc_command(opt), &b)
ensure ensure
rm_f "conftest*" rm_f "conftest*"
end end
def try_cpp(src, opt="") def try_cpp(src, opt="", &b)
try_do(src, cpp_command(CPPOUTFILE, opt)) try_do(src, cpp_command(CPPOUTFILE, opt), &b)
ensure ensure
rm_f "conftest*" rm_f "conftest*"
end end
@ -265,20 +267,23 @@ def cpp_include(header)
end end
end end
def try_static_assert(expr, headers = nil, opt = "") def try_static_assert(expr, headers = nil, opt = "", &b)
headers = cpp_include(headers) headers = cpp_include(headers)
try_compile(<<SRC, opt) try_compile(<<SRC, opt, &b)
#{COMMON_HEADERS} #{COMMON_HEADERS}
#{headers} #{headers}
/*top*/
int tmp[(#{expr}) ? 1 : -1]; int tmp[(#{expr}) ? 1 : -1];
SRC SRC
end end
def try_constant(const, headers = nil, opt = "") def try_constant(const, headers = nil, opt = "", &b)
headers = cpp_include(headers)
if CROSS_COMPILING if CROSS_COMPILING
unless try_compile(<<"SRC", opt) unless try_compile(<<"SRC", opt, &b)
#{COMMON_HEADERS} #{COMMON_HEADERS}
#{cpp_include(headers)} #{headers}
/*top*/
int tmp = #{const}; int tmp = #{const};
SRC SRC
return nil return nil
@ -306,11 +311,12 @@ SRC
return upper return upper
else else
src = %{#{COMMON_HEADERS} src = %{#{COMMON_HEADERS}
#{cpp_include(headers)} #{headers}
#include <stdio.h> #include <stdio.h>
/*top*/
int main() {printf("%d\\n", (int)(#{const})); return 0;} int main() {printf("%d\\n", (int)(#{const})); return 0;}
} }
if try_link0(src, opt) if try_link0(src, opt, &b)
xpopen("./conftest") do |f| xpopen("./conftest") do |f|
return Integer(f.gets) return Integer(f.gets)
end end
@ -319,23 +325,24 @@ int main() {printf("%d\\n", (int)(#{const})); return 0;}
nil nil
end end
def try_func(func, libs, headers = nil) def try_func(func, libs, headers = nil, &b)
headers = cpp_include(headers) headers = cpp_include(headers)
try_link(<<"SRC", libs) or try_link(<<"SRC", libs) try_link(<<"SRC", libs, &b) or try_link(<<"SRC", libs, &b)
#{headers} #{headers}
/*top*/
int main() { return 0; } int main() { return 0; }
int t() { #{func}(); return 0; } int t() { #{func}(); return 0; }
SRC SRC
#{COMMON_HEADERS} #{COMMON_HEADERS}
#{headers} #{headers}
/*top*/
int main() { return 0; } int main() { return 0; }
int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; } int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; }
SRC SRC
end end
def egrep_cpp(pat, src, opt="") def egrep_cpp(pat, src, opt = "", &b)
src = src.sub(/[^\n]\z/, "\\&\n") src = create_tmpsrc(src, &b)
create_tmpsrc(src)
xpopen(cpp_command('', opt)) do |f| xpopen(cpp_command('', opt)) do |f|
if Regexp === pat if Regexp === pat
puts(" ruby -ne 'print if #{pat.inspect}'") puts(" ruby -ne 'print if #{pat.inspect}'")
@ -360,17 +367,18 @@ ensure
log_src(src) log_src(src)
end end
def macro_defined?(macro, src, opt="") def macro_defined?(macro, src, opt = "", &b)
src = src.sub(/[^\n]\z/, "\\&\n") src = src.sub(/[^\n]\z/, "\\&\n")
try_cpp(src + <<"SRC", opt) try_cpp(src + <<"SRC", opt, &b)
/*top*/
#ifndef #{macro} #ifndef #{macro}
# error # error
#endif #endif
SRC SRC
end end
def try_run(src, opt="") def try_run(src, opt = "", &b)
if try_link0(src, opt) if try_link0(src, opt, &b)
xsystem("./conftest") xsystem("./conftest")
else else
nil nil
@ -446,14 +454,14 @@ def checking_for(m)
r r
end end
def have_library(lib, func=nil) def have_library(lib, func = nil, &b)
func = "main" if !func or func.empty? func = "main" if !func or func.empty?
checking_for "#{func}() in -l#{lib}" do checking_for "#{func}() in -l#{lib}" do
if COMMON_LIBS.include?(lib) if COMMON_LIBS.include?(lib)
true true
else else
libs = append_library($libs, lib) libs = append_library($libs, lib)
if try_func(func, libs) if try_func(func, libs, &b)
$libs = libs $libs = libs
true true
else else
@ -463,12 +471,12 @@ def have_library(lib, func=nil)
end end
end end
def find_library(lib, func, *paths) def find_library(lib, func, *paths, &b)
checking_for "#{func}() in -l#{lib}" do checking_for "#{func}() in -l#{lib}" do
libpath = $LIBPATH libpath = $LIBPATH
libs = append_library($libs, lib) libs = append_library($libs, lib)
begin begin
until r = try_func(func, libs) or paths.empty? until r = try_func(func, libs, &b) or paths.empty?
$LIBPATH = libpath | [paths.shift] $LIBPATH = libpath | [paths.shift]
end end
if r if r
@ -482,9 +490,9 @@ def find_library(lib, func, *paths)
end end
end end
def have_func(func, header=nil) def have_func(func, headers = nil, &b)
checking_for "#{func}()" do checking_for "#{func}()" do
if try_func(func, $libs, header) if try_func(func, $libs, headers, &b)
$defs.push(format("-DHAVE_%s", func.upcase)) $defs.push(format("-DHAVE_%s", func.upcase))
true true
else else
@ -493,9 +501,9 @@ def have_func(func, header=nil)
end end
end end
def have_header(header) def have_header(header, &b)
checking_for header do checking_for header do
if try_cpp(cpp_include(header)) if try_cpp(cpp_include(header), &b)
$defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___"))) $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___")))
true true
else else
@ -504,11 +512,12 @@ def have_header(header)
end end
end end
def have_struct_member(type, member, header=nil) def have_struct_member(type, member, header = nil, &b)
checking_for "#{type}.#{member}" do checking_for "#{type}.#{member}" do
if try_compile(<<"SRC") if try_compile(<<"SRC", &b)
#{COMMON_HEADERS} #{COMMON_HEADERS}
#{cpp_include(header)} #{cpp_include(header)}
/*top*/
int main() { return 0; } int main() { return 0; }
int s = (char *)&((#{type}*)0)->#{member} - (char *)0; int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
SRC SRC
@ -520,15 +529,18 @@ SRC
end end
end end
def have_type(type, header=nil, opt="") def have_type(type, header = nil, opt = "", &b)
checking_for type do checking_for type do
if try_compile(<<"SRC", opt) or try_compile(<<"SRC", opt) header = cpp_include(header)
if try_compile(<<"SRC", opt, &b) or try_compile(<<"SRC", opt, &b)
#{COMMON_HEADERS} #{COMMON_HEADERS}
#{cpp_include(header)} #{header}
/*top*/
static #{type} t; static #{type} t;
SRC SRC
#{COMMON_HEADERS} #{COMMON_HEADERS}
#{cpp_include(header)} #{header}
/*top*/
static #{type} *t; static #{type} *t;
SRC SRC
$defs.push(format("-DHAVE_TYPE_%s", type.upcase)) $defs.push(format("-DHAVE_TYPE_%s", type.upcase))
@ -539,12 +551,12 @@ SRC
end end
end end
def check_sizeof(type, header=nil) def check_sizeof(type, header = nil, &b)
expr = "sizeof(#{type})" expr = "sizeof(#{type})"
m = "checking size of #{type}... " m = "checking size of #{type}... "
message "%s", m message "%s", m
Logging::message "check_sizeof: %s--------------------\n", m Logging::message "check_sizeof: %s--------------------\n", m
if size = try_constant(expr, header) if size = try_constant(expr, header, &b)
$defs.push(format("-DSIZEOF_%s", type.upcase)) $defs.push(format("-DSIZEOF_%s", type.upcase))
end end
message(a = size ? "#{size}\n" : "failed\n") message(a = size ? "#{size}\n" : "failed\n")