From: nobu.nakada@... Date: 2003-08-05T17:24:06+09:00 Subject: [ruby-dev:21140] Re: with-static-linked-ext なかだです。 At Tue, 5 Aug 2003 16:44:03 +0900, Nobuyoshi-Nakada wrote: > --with-static-linked-ext=yesでconfigureすると、rubyをリンクする > ところで失敗します。原因は、ライブラリパスを分離した$LIBPATHを > EXTLDFLAGSで渡していないためです。 --enable-shared --with-static-linked-ext=yesのときに、拡張ライ ブラリがLIBRUBY_SOとruby両方にリンクされてしまってたので、訂正。 それと書き忘れましたが、Init_ext()での初期化順序を指定するため に、$preloadという変数を追加しています。そのライブラリよりも先 に初期化すべきライブラリ名の配列です。 Index: Makefile.in =================================================================== RCS file: /cvs/ruby/src/ruby/Makefile.in,v retrieving revision 1.44 diff -u -2 -p -r1.44 Makefile.in --- Makefile.in 21 May 2003 11:51:55 -0000 1.44 +++ Makefile.in 5 Aug 2003 08:08:47 -0000 @@ -31,5 +31,5 @@ LIBS = @LIBS@ $(EXTLIBS) MISSING = @LIBOBJS@ @ALLOCA@ LDSHARED = @LIBRUBY_LDSHARED@ -DLDFLAGS = @LIBRUBY_DLDFLAGS@ +DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) SOLIBS = @SOLIBS@ MAINLIBS = @MAINLIBS@ @@ -59,5 +59,7 @@ PREP = @PREP@ @ARCHFILE@ SETUP = -EXTOBJS = +EXTOBJS = $(DMYEXT) +DLDOBJS = $(DMYEXT) +DMYEXT = dmyext.@OBJEXT@ MAINOBJ = main.@OBJEXT@ @@ -111,7 +113,7 @@ all: @MAKEFILES@ miniruby$(EXEEXT) rbco @$(MINIRUBY) $(srcdir)/ext/extmk.rb --extstatic="@EXTSTATIC@" $(SCRIPT_ARGS) -miniruby$(EXEEXT): config.status $(LIBRUBY_A) $(MAINOBJ) dmyext.@OBJEXT@ +miniruby$(EXEEXT): config.status $(LIBRUBY_A) $(MAINOBJ) $(DMYEXT) @rm -f $@ - $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) dmyext.@OBJEXT@ $(LIBRUBY_A) $(LIBS) -o $@ + $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(DMYEXT) $(LIBRUBY_A) $(LIBS) -o $@ $(PROGRAM): $(LIBRUBY) $(MAINOBJ) $(EXTOBJS) $(SETUP) miniruby$(EXEEXT) @@ -119,10 +121,10 @@ $(PROGRAM): $(LIBRUBY) $(MAINOBJ) $( $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ -$(LIBRUBY_A): $(OBJS) dmyext.@OBJEXT@ - @AR@ rcu $@ $(OBJS) dmyext.@OBJEXT@ +$(LIBRUBY_A): $(OBJS) $(DMYEXT) + @AR@ rcu $@ $(OBJS) $(DMYEXT) @-@RANLIB@ $@ 2> /dev/null || true -$(LIBRUBY_SO): $(OBJS) dmyext.@OBJEXT@ miniruby$(EXEEXT) $(PREP) - $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.@OBJEXT@ $(SOLIBS) -o $@ +$(LIBRUBY_SO): $(OBJS) $(DLDOBJS) miniruby$(EXEEXT) $(PREP) + $(LDSHARED) $(DLDFLAGS) $(OBJS) $(DLDOBJS) $(SOLIBS) -o $@ @-$(MINIRUBY) -e 'ARGV.each{|link| File.delete link if File.exist? link; \ File.symlink "$(LIBRUBY_SO)", link}' \ Index: extmk.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/extmk.rb,v retrieving revision 1.37 diff -u -2 -p -r1.37 extmk.rb --- extmk.rb 2 Aug 2003 06:14:53 -0000 1.37 +++ extmk.rb 5 Aug 2003 07:58:59 -0000 @@ -61,4 +61,5 @@ def extmake(target) $mdir = target $srcdir = File.join($top_srcdir, "ext", $mdir) + $preload = nil unless $ignore if $static || @@ -89,5 +90,5 @@ def extmake(target) if File.exist?("./Makefile") if $static - $extlist.push [$static, $target, File.basename($target)] + $extlist.push [$static, $target, File.basename($target), $preload] end unless system($make, *sysquote($mflags)) @@ -102,8 +103,10 @@ def extmake(target) $extflags ||= "" $extlibs ||= "" - $extflags += " " + $DLDFLAGS if $DLDFLAGS - $extflags += " " + $LDFLAGS unless $LDFLAGS == "" - $extlibs += " " + $libs unless $libs == "" - $extlibs += " " + $LOCAL_LIBS unless $LOCAL_LIBS == "" + $extpath ||= [] + $extflags += " " + $DLDFLAGS unless $DLDFLAGS.empty? + $extflags += " " + $LDFLAGS unless $LDFLAGS.empty? + libs = ($libs.split+$LOCAL_LIBS.split).uniq + $extlibs = [$extlibs, *libs].join(" ") unless libs.empty? + $extpath |= $LIBPATH end ensure @@ -213,5 +216,5 @@ Dir::chdir('ext') ext_prefix = "#{$top_srcdir}/ext" -Dir.glob("#{ext_prefix}/**/MANIFEST") do |d| +Dir.glob("#{ext_prefix}/*/**/MANIFEST") do |d| d = File.dirname(d) d.slice!(0, ext_prefix.length + 1) @@ -227,13 +230,23 @@ if $extlist.size > 0 $extinit ||= "" $extobjs ||= "" - for s,t,i in $extlist + list = $extlist.dup + until list.empty? + s,t,i,r = list.shift + if r and list.any? {|l| r.include?(l[1])} + list << [s,t,i] + next + end f = format("%s/%s.%s", s, i, $LIBEXT) if File.exist?(f) - $extinit += "\tInit_#{i}();\n\trb_provide(\"#{t}.so\");\n" + $extinit += "\tinit(Init_#{i}, \"#{t}.so\");\n" $extobjs += "ext/#{f} " end end - src = "void Init_ext() {\n#$extinit}\n" + src = < 0 $extlibs.gsub!("-L/usr/local/lib", "") if $extlibs end + $extpath.delete("$(topdir)") + $extflags = libpathflag($extpath) << " " << $extflags.strip conf = [ ['SETUP', $setup], ['EXTOBJS', $extobjs], Index: lib/mkmf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v retrieving revision 1.143 diff -u -2 -p -r1.143 mkmf.rb --- lib/mkmf.rb 2 Aug 2003 05:54:00 -0000 1.143 +++ lib/mkmf.rb 5 Aug 2003 01:35:07 -0000 @@ -145,4 +145,20 @@ module Logging end end + + def self::temporary + tmplog = "mkmftmp.log" + open do + log, *save = @log, @logfile, @orgout, @orgerr + @log, @logfile, @orgout, @orgerr = nil, tmplog, log, log + begin + log.print(open {yield}) + @log.close + File::open(tmplog) {|t| FileUtils.copy_stream(t, log)} + ensure + @log, @logfile, @orgout, @orgerr = log, *save + rm_f tmplog + end + end + end end @@ -419,8 +435,11 @@ def checking_for(m) m = "checking for #{m}... " message "%s", m - Logging::message "%s%s--------------------\n", f, m - r = yield - message(a = r ? "yes\n" : "no\n") - Logging::message "-------------------- %s\n", a + r = nil + Logging::temporary do + r = yield + message(a = r ? "yes\n" : "no\n") + "#{f}#{m}-------------------- #{a}\n" + end + Logging::message "--------------------\n\n" r end @@ -631,5 +650,5 @@ def pkg_config(pkg) $CFLAGS += " " << cflags $LDFLAGS += " " << ldflags - $LIBS += " " << libs + $libs += " " << libs Logging::message "package configuration for %s\n", pkg Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", Index: ext/digest/sha1/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/digest/sha1/extconf.rb,v retrieving revision 1.4 diff -u -2 -p -r1.4 extconf.rb --- ext/digest/sha1/extconf.rb 26 Sep 2002 17:44:33 -0000 1.4 +++ ext/digest/sha1/extconf.rb 5 Aug 2003 01:15:07 -0000 @@ -13,5 +13,4 @@ if !with_config("bundled-sha1") && have_library("crypto") && have_header("openssl/sha.h") $objs << "sha1ossl.#{$OBJEXT}" - $libs << " -lcrypto" else $objs << "sha1.#{$OBJEXT}" << "sha1hl.#{$OBJEXT}" -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦