From: nobu.nakada@... Date: 2002-09-03T18:51:42+09:00 Subject: [ruby-dev:18162] Re: Shim with VC++5 なかだです。 At Fri, 30 Aug 2002 15:01:01 +0900, WATANABE Hirofumi wrote: > > そもそも、egrep_cppって使われてるの? とか思ったりもしたんで > > すけど(README.EXTにも書いてないし)、ext/etcとext/socketで使 > > ってますね... > > 構造体のmemberの確認とか定数がdefineされてるかどうかとかが多 > いようです。defineされてるかどうかはtry_cppだけでわかるから > ext/socket/extconf.rbでegrep_cppは使う必要がなさそうですね。 > memberの有無も専用の関数を用意するかtry_compileを作ったほう > がよさそう。 try_compileと、ついでに.SUFFIXESも追加してみました。 あと最近気づいたんですが、xsystemでもConfig.expandしているので 呼び出し側でやる必要はないような。 Index: ext/extmk.rb.in =================================================================== RCS file: /cvs/ruby/src/ruby/ext/extmk.rb.in,v retrieving revision 1.84 diff -u -2 -p -r1.84 ext/extmk.rb.in --- ext/extmk.rb.in 3 Sep 2002 08:40:47 -0000 1.84 +++ ext/extmk.rb.in 3 Sep 2002 09:29:16 -0000 @@ -63,4 +63,5 @@ end $LINK = "#{CONFIG['CC']} #{OUTFLAG}conftest -I#$topdir -I#$top_srcdir #{CFLAGS} %s %s #{CONFIG['LDFLAGS']} %s conftest.c %s %s #{CONFIG['LIBS']}" +$CC = "#{CONFIG['CC']} -c %s -I#$topdir -I#$top_srcdir #{CFLAGS} %s %s conftest.c" $CPP = "#{CONFIG['CPP']} #{CONFIG['CPPFLAGS']} %s -I#$topdir -I#$top_srcdir #{CFLAGS} %s %s conftest.c" Index: mkmf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v retrieving revision 1.90 diff -u -2 -p -r1.90 lib/mkmf.rb --- lib/mkmf.rb 3 Sep 2002 08:40:47 -0000 1.90 +++ lib/mkmf.rb 3 Sep 2002 09:17:27 -0000 @@ -87,4 +87,5 @@ else end $LINK = "#{CONFIG['CC']} #{OUTFLAG}conftest -I#{$hdrdir} #{CFLAGS} %s %s #{CONFIG['LDFLAGS']} %s conftest.c %s %s #{CONFIG['LIBS']}" +$CC = "#{CONFIG['CC']} -c %s -I#{$hdrdir} #{CFLAGS} %s %s conftest.c" $CPP = "#{CONFIG['CPP']} -E %s -I#{$hdrdir} #{CFLAGS} %s %s conftest.c" @@ -126,9 +127,11 @@ def xsystem command $stderr.reopen($log) $stdout.reopen($log) - puts command - r = system(command) - $stderr.reopen($orgerr) - $stdout.reopen($orgout) - return r + begin + puts command + system(command) + ensure + $stderr.reopen($orgerr) + $stdout.reopen($orgout) + end end @@ -145,5 +148,5 @@ def try_link0(src, opt="") end begin - xsystem(Config.expand(format($LINK, $CFLAGS, $CPPFLAGS, $LDFLAGS, opt, $LOCAL_LIBS))) + xsystem(format($LINK, $CFLAGS, $CPPFLAGS, $LDFLAGS, opt, $LOCAL_LIBS)) ensure $LDFLAGS = ldflags @@ -163,4 +166,15 @@ def try_link(src, opt="") end +def try_compile(src, opt="") + cfile = open("conftest.c", "w") + cfile.print src + cfile.close + begin + xsystem(format($CC, $CPPFLAGS, $CFLAGS, opt)) + ensure + rm_f "conftest*" + end +end + def try_cpp(src, opt="") cfile = open("conftest.c", "w") @@ -168,5 +182,5 @@ def try_cpp(src, opt="") cfile.close begin - xsystem(Config.expand(format($CPP, $CPPFLAGS, $CFLAGS, opt))) + xsystem(format($CPP, $CPPFLAGS, $CFLAGS, opt)) ensure rm_f "conftest*" @@ -178,6 +192,15 @@ def egrep_cpp(pat, src, opt="") cfile.print src cfile.close + if Regexp === pat + src = pat.source + else + pat = Regexp.new(src = pat) + end begin - xsystem(Config.expand(format($CPP, $CPPFLAGS, $CFLAGS, opt))+"|egrep #{pat}") + xsystem("|"+format(CPP, $CFLAGS, $CPPFLAGS, opt)) do |f| + puts(" #{src}") + f.grep(pat) {return true} + end + false ensure rm_f "conftest*" @@ -344,5 +367,5 @@ SRC r = try_link(src + <<"SRC", libs) int main() { return 0; } -int t() { void ((*p)()); p = (void ((*)()))#{func}; return 0; } +int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; } SRC end @@ -475,5 +498,5 @@ def create_makefile(target, srcprefix = $DLDFLAGS = CONFIG["DLDFLAGS"] - $libs = CONFIG["LIBRUBYARG"] + " " + $libs + $libs = CONFIG["LIBRUBYARG"] + " " + $libs + CONFIG["LIBS"] $configure_args['--enable-shared'] or $LIBPATH |= [$topdir] $LIBPATH |= [CONFIG["libdir"]] @@ -648,4 +671,6 @@ EOMF cxxopt = '-Tp' end + + mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n" unless /nmake/i =~ $make if /bccwin32/ =~ RUBY_PLATFORM -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦