なかだです。

At Tue, 22 Aug 2000 01:35:25 +0900
WATANABE Hirofumi <eban / os.rim.or.jp> wrote:
> :$(topdir) の方がかち合わないのでいいような気がしますが、かわりに DLDFLAGS 
> :かなにかに -L$(topdir) とかが必要になります。
> 
> ext/extmk.rb.in には
>   if $configure_args['--enable-shared'] or /cygwin|mingw/ === RUBY_PLATFORM
>     $libs = "@LIBRUBYARG@ " + $libs
>     $DLDFLAGS = $DLDFLAGS + " -L" + $topdir
>   end
> が入ってますが, これじゃなくて?

  書き方が紛らわしかったですが、ext/ 以下の方じゃなくて外部の拡張ライブ
ラリの方です。というか、mkmf.rb をよく見ると $topdir じゃなくて libdir 
を設定してますね。


> #やけに ad hoc だな.

  たしかに。enable-shared 以外で $topdir が必要なのは libruby.a,
libruby.so 以外に第三のスタブライブラリを使うときと考えれば

  if $configure_args['--enable-shared'] or "@LIBRUBY@" != "@LIBRUBY_A@"

とか。mswin32 のときには -L の扱いは変えなきゃなりませんが。

# なんてやってたらまたデカいパッチになってしまった…。


diff -pruPX ./.excludes current/ext/extmk.rb.in devel/ext/extmk.rb.in --- current/ext/extmk.rb.in Thu Aug 10 06:27:09 2000 +++ devel/ext/extmk.rb.in Tue Aug 22 13:05:57 2000 @@ -1,6 +1,7 @@ #! /usr/local/bin/ruby $".push 'mkmf.rb' +ORIG_LIBPATH = ENV['LIB'] if ARGV[0] == 'static' $force_static = true @@ -91,7 +92,18 @@ def try_link0(src, opt="") cfile = open("conftest.c", "w") cfile.print src cfile.close - xsystem(format(LINK, $CFLAGS, $CPPFLAGS, $LDFLAGS, opt, $LOCAL_LIBS)) + ldflags = $LDFLAGS + if /mswin32/ =~ RUBY_PLATFORM and !$LIBPATH.empty? + ENV['LIB'] = ($LIBPATH + [ORIG_LIBPATH]).compact.join(';') + else + $LDFLAGS = ldflags.dup + $LIBPATH.each {|d| $LDFLAGS << " -L" + d} + end + begin + xsystem(format(LINK, $CFLAGS, $CPPFLAGS, $LDFLAGS, opt, $LOCAL_LIBS)) + ensure + ENV['LIB'] = ORIG_LIBPATH if /mswin32/ =~ RUBY_PLATFORM + end end def try_link(src, opt="") @@ -204,17 +216,17 @@ SRC end def find_library(lib, func, *paths) - ldflags = $LDFLAGS + libpath = $LIBPATH libs = append_library($libs, lib) until try_link(<<"SRC", libs) int main() { return 0; } int t() { #{func}(); return 0; } SRC if paths.size == 0 - $LDFLAGS = ldflags + $LIBPATH = libpath return false end - $LDFLAGS = ldflags + " -L"+paths.shift + $LIBPATH = libpath + [paths.shift] end $libs = libs return true @@ -315,19 +327,18 @@ def dir_config(target) dir = with_config("%s-dir"%target) if dir idir = " -I"+dir+"/include" - ldir = " -L"+dir+"/lib" + ldir = dir+"/lib" end unless idir dir = with_config("%s-include"%target) idir = " -I"+dir if dir end unless ldir - dir = with_config("%s-lib"%target) - ldir = " -L"+dir if dir + ldir = with_config("%s-lib"%target) end $CPPFLAGS += idir if idir - $LDFLAGS += ldir if ldir + $LIBPATH << ldir if ldir end def create_makefile(target) @@ -344,9 +355,9 @@ def create_makefile(target) $DLDFLAGS = '@DLDFLAGS@' - if $configure_args['--enable-shared'] or /cygwin|mingw/ === RUBY_PLATFORM + if $configure_args['--enable-shared'] or "@LIBRUBY@" != "@LIBRUBY_A@" $libs = "@LIBRUBYARG@ " + $libs - $DLDFLAGS = $DLDFLAGS + " -L" + $topdir + $LIBPATH << $topdir end defflag = '' @@ -357,6 +368,14 @@ def create_makefile(target) defflag = "--def=" + target + ".def" end + if RUBY_PLATFORM =~ /mswin32/ + libpath = $LIBPATH.collect {|d| + d.tr('/', '\\').gsub(/\$\((\w+)\)/, '$(\1:/=\)') + }.join(';') + else + $LIBPATH.each {|d| $DLDFLAGS << " -L" << d} + end + $srcdir = $top_srcdir + "/ext/" + $mdir mfile = open("Makefile", "w") mfile.binmode if /mingw/ =~ RUBY_PLATFORM @@ -379,6 +398,7 @@ CPPFLAGS = -I$(topdir) -I$(hdrdir) -I@in DLDFLAGS = #$DLDFLAGS #$LDFLAGS LDSHARED = @LDSHARED@ #{defflag} ", if $static then "" else "@CCDLFLAGS@" end, $defs.join(" ") +mfile.puts "LIBPATH = #{libpath}" if libpath mfile.printf "\ @@ -458,11 +478,12 @@ EOS mfile.printf "\n" if /mswin32/ =~ RUBY_PLATFORM - mfile.puts " + mfile.print " .c.obj: - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< + {$(srcdir)}.c{}.obj: - $(CC) -I. -I$(<D) $(CFLAGS) $(CPPFLAGS) -c $(<:/=\\) + $(CC) -I. -I$(<D) $(CFLAGS) $(CPPFLAGS) -o $@ -c $(<:/=\\) " else @@ -486,10 +507,11 @@ $(DLLIB): $(OBJS) " end elsif "@DLEXT@" != $OBJEXT - mfile.printf "\ -$(DLLIB): $(OBJS) - $(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS) -" + mfile.print "$(DLLIB): $(OBJS)\n" + if /mswin32/ =~ RUBY_PLATFORM + mfile.print "\tset LIB=$(LIBPATH);$(LIB)\n" + end + mfile.print "\t$(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS)\n" elsif RUBY_PLATFORM == "m68k-human" mfile.printf "\ $(DLLIB): $(OBJS) @@ -533,26 +555,26 @@ def extmake(target) $local_flags = "" if /mswin32/ =~ RUBY_PLATFORM $LIBEXT = "lib" - $local_flags = "$(topdir)/$(RUBY_SO_NAME).lib -link /EXPORT:Init_$(TARGET)" + $local_flags = "-link /INCREMENTAL:no /EXPORT:Init_$(TARGET)" end $LOCAL_LIBS = "" # to be assigned in extconf.rb dir = with_config("opt-dir") if dir idir = "-I"+dir+"/include" - ldir = "-L"+dir+"/lib" + ldir = dir+"/lib" end unless idir dir = with_config("opt-include") idir = "-I"+dir if dir end unless ldir - dir = with_config("opt-lib") - ldir = "-L"+dir if dir + ldir = with_config("opt-lib") end $CFLAGS = "" $CPPFLAGS = idir || "" - $LDFLAGS = ldir || "" + $LDFLAGS = "" + $LIBPATH = [ldir].compact begin Dir.mkdir target unless File.directory?(target) diff -pruPX ./.excludes current/ext/socket/extconf.rb devel/ext/socket/extconf.rb --- current/ext/socket/extconf.rb Mon Jul 10 13:49:18 2000 +++ devel/ext/socket/extconf.rb Tue Aug 22 13:10:45 2000 @@ -1,6 +1,6 @@ require 'mkmf' -$LDFLAGS += " -L/usr/local/lib" if File.directory?("/usr/local/lib") -$CFLAGS += " -Dss_family=__ss_family -Dss_len=__ss_len" +$LIBPATH << "/usr/local/lib" if File.directory?("/usr/local/lib") +$CPPFLAGS += " -Dss_family=__ss_family -Dss_len=__ss_len" case RUBY_PLATFORM when /mswin32|mingw/ diff -pruPX ./.excludes current/lib/mkmf.rb devel/lib/mkmf.rb --- current/lib/mkmf.rb Wed Aug 9 13:32:23 2000 +++ devel/lib/mkmf.rb Tue Aug 22 13:17:17 2000 @@ -5,6 +5,7 @@ require 'rbconfig' require 'find' CONFIG = Config::MAKEFILE_CONFIG +ORIG_LIBPATH = ENV['LIB'] SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"] @@ -75,7 +76,18 @@ def try_link0(src, opt="") cfile = open("conftest.c", "w") cfile.print src cfile.close - xsystem(format(LINK, $CFLAGS, $LDFLAGS, opt, $LOCAL_LIBS)) + ldflags = $LDFLAGS + if /mswin32/ =~ RUBY_PLATFORM and !$LIBPATH.empty? + ENV['LIB'] = ($LIBPATH + [ORIG_LIBPATH]).compact.join(';') + else + $LDFLAGS = ldflags.dup + $LIBPATH.each {|d| $LDFLAGS << " -L" + d} + end + begin + xsystem(format(LINK, $CFLAGS, $CPPFLAGS, $LDFLAGS, opt, $LOCAL_LIBS)) + ensure + ENV['LIB'] = ORIG_LIBPATH if /mswin32/ =~ RUBY_PLATFORM + end end def try_link(src, opt="") @@ -196,18 +208,18 @@ def find_library(lib, func, *paths) printf "checking for %s() in -l%s... ", func, lib STDOUT.flush - ldflags = $LDFLAGS + libpath = $LIBPATH libs = append_library($libs, lib) until try_link(<<"SRC", libs) int main() { return 0; } int t() { #{func}(); return 0; } SRC if paths.size == 0 - $LDFLAGS = ldflags + $LIBPATH = libpath print "no\n" return false end - $LDFLAGS = ldflags + " -L"+paths.shift + $LIBPATH = libpath + paths.shift end $libs = libs print "yes\n" @@ -262,7 +274,7 @@ SRC print "no\n" return false end - header.tr!("a-z\055./", "A-Z___") + header.tr!("a-z./\055", "A-Z___") $defs.push(format("-DHAVE_%s", header)) print "yes\n" return true @@ -317,19 +329,18 @@ def dir_config(target) dir = with_config("%s-dir"%target) if dir idir = " -I"+dir+"/include" - ldir = " -L"+dir+"/lib" + ldir = dir+"/lib" end unless idir dir = with_config("%s-include"%target) idir = " -I"+dir if dir end unless ldir - dir = with_config("%s-lib"%target) - ldir = " -L"+dir if dir + ldir = with_config("%s-lib"%target) end - $CFLAGS += idir if idir - $LDFLAGS += ldir if ldir + $CPPFLAGS += idir if idir + $LIBPATH += ldir if ldir end def create_makefile(target) @@ -343,11 +354,12 @@ def create_makefile(target) end $defs.push(format("-DEXTLIB='%s'", libs.join(","))) end + $DLDFLAGS = CONFIG["DLDFLAGS"] - if $configure_args['--enable-shared'] or /cygwin|mingw/ == RUBY_PLATFORM + if $configure_args['--enable-shared'] or CONFIG['LIBRUBY'] != CONFIG['LIBRUBY_A'] $libs = CONFIG["LIBRUBYARG"] + " " + $libs - $DLDFLAGS += " -L" + CONFIG["libdir"] + $LIBPATH << "$(topdir)" << CONFIG["libdir"] end defflag = '' @@ -358,6 +370,16 @@ def create_makefile(target) defflag = "--def=" + target + ".def" end + if RUBY_PLATFORM =~ /mswin32/ + libpath = $LIBPATH.collect {|d| + d.tr('/', '\\').gsub(/\$\((\w+)\)/, '$(\1:/=\)') + }.join(';') + drive = /\A\w:/ + else + $LIBPATH.each {|d| $DLDFLAGS << " -L" << d} + drive = /\A/ + end + unless $objs then $objs = [] for f in Dir["*.{#{SRC_EXT.join(%q{,})}}"] @@ -386,21 +408,22 @@ hdrdir = #{$hdrdir} CC = #{CONFIG["CC"]} CFLAGS = #{CONFIG["CCDLFLAGS"]} #{CFLAGS} #{$CFLAGS} - CPPFLAGS = -I$(hdrdir) -I#{CONFIG["includedir"]} #{$defs.join(" ")} #{CONFIG["CPPFLAGS"]} +CPPFLAGS = -I$(hdrdir) -I#{CONFIG["includedir"]} #{$defs.join(" ")} #{CONFIG["CPPFLAGS"]} CXXFLAGS = $(CFLAGS) DLDFLAGS = #{$DLDFLAGS} #{$LDFLAGS} LDSHARED = #{CONFIG["LDSHARED"]} #{defflag} +LIBPATH = #{libpath} RUBY_INSTALL_NAME = #{CONFIG["RUBY_INSTALL_NAME"]} RUBY_SO_NAME = #{CONFIG["RUBY_SO_NAME"]} -DESTDIR = -prefix = $(DESTDIR)#{CONFIG["prefix"]} -exec_prefix = $(DESTDIR)#{CONFIG["exec_prefix"]} -libdir = $(DESTDIR)#{$libdir} -archdir = $(DESTDIR)#{$archdir} -sitelibdir = $(DESTDIR)#{$sitelibdir} -sitearchdir = $(DESTDIR)#{$sitearchdir} +DESTDIR = #{CONFIG["prefix"].scan(drive)} +prefix = $(DESTDIR)#{CONFIG["prefix"].sub(drive, '')} +exec_prefix = $(DESTDIR)#{CONFIG["exec_prefix"].sub(drive, '')} +libdir = $(DESTDIR)#{$libdir.sub(drive, '')} +archdir = $(DESTDIR)#{$archdir.sub(drive, '')} +sitelibdir = $(DESTDIR)#{$sitelibdir.sub(drive, '')} +sitearchdir = $(DESTDIR)#{$sitearchdir.sub(drive, '')} #### End of system configuration section. #### @@ -465,7 +488,7 @@ EOMF if CONFIG["DLEXT"] != $OBJEXT mfile.print "$(DLLIB): $(OBJS)\n" if /mswin32/ =~ RUBY_PLATFORM - mfile.print "\tset LIB=$(topdir:/=\\);$(LIB)\n" + mfile.print "\tset LIB=$(LIBPATH);$(LIB)\n" end mfile.print "\t$(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS)\n" elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc") @@ -495,7 +518,7 @@ $libs = CONFIG["DLDLIBS"] $local_flags = "" case RUBY_PLATFORM when /mswin32/ - $local_flags = "$(RUBY_SO_NAME).lib -link /EXPORT:Init_$(TARGET)" + $local_flags = "-link /INCREMENTAL:no /EXPORT:Init_$(TARGET)" end $LOCAL_LIBS = "" $defs = [] @@ -503,16 +526,17 @@ $defs = [] dir = with_config("opt-dir") if dir idir = "-I"+dir+"/include" - ldir = "-L"+dir+"/lib" + ldir = dir+"/lib" end unless idir dir = with_config("opt-include") idir = "-I"+dir if dir end unless ldir - dir = with_config("opt-lib") - ldir = "-L"+dir if dir + ldir = with_config("opt-lib") end -$CFLAGS = idir || "" -$LDFLAGS = ldir || "" +$CFLAGS = "" +$CPPFLAGS = idir || "" +$LDFLAGS = "" +$LIBPATH = [ldir].compact diff -pruPX ./.excludes current/win32/Makefile.sub devel/win32/Makefile.sub --- current/win32/Makefile.sub Wed Aug 9 13:32:24 2000 +++ devel/win32/Makefile.sub Tue Aug 22 11:29:49 2000 @@ -53,7 +53,7 @@ ORGLIBPATH = $(LIB) LIBRUBY_A = lib$(RUBY_INSTALL_NAME).lib LIBRUBY_SO = $(RUBY_SO_NAME).dll -LIBRUBY = $(RUBY_SO_NAME).lib +LIBRUBY = $(RUBY_INSTALL_NAME).lib LIBRUBYARG = $(LIBRUBY) EXTOBJS = dmyext.obj @@ -124,11 +124,11 @@ miniruby$(EXEEXT): $(OBJS) $(MAINOBJ) $( $(PROGRAM): $(MAINOBJ) $(LIBRUBY_SO) $*.res $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINOBJ) $*.res \ - -o $@ $(LIBRUBYARG) -link /STACK:$(STACK) + -o $@ $(LIBRUBYARG) $(LIBS) -link /STACK:$(STACK) $(WPROGRAM): $(MAINOBJ) $(WINMAINOBJ) $(LIBRUBY_SO) $*.res $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(WINMAINOBJ) $*.res \ - -o $@ $(LIBRUBYARG) -link /STACK:$(STACK) /SUBSYSTEM:Windows + -o $@ $(LIBRUBYARG) $(LIBS) -link /STACK:$(STACK) /SUBSYSTEM:Windows $(LIBRUBY_A): $(OBJS) dmyext.obj lib -nologo /OUT:$@ $(OBJS) dmyext.obj @@ -136,10 +136,10 @@ $(LIBRUBY_A): $(OBJS) dmyext.obj $(LIBRUBY): $(RUBYDEF) lib -nologo /OUT:$@ /DEF:$(RUBYDEF) -$(LIBRUBY_SO): $(LIBRUBY_A) $(EXTOBJS) $(RUBYDEF) $@.res +$(LIBRUBY_SO): $(LIBRUBY_A) $(EXTOBJS) $(RUBYDEF) $(LIBRUBY_SO).res set LIB=./win32;$(ORGLIBPATH) - $(CC) $(LDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBY_A) $@.res $(LIBS) \ - -o $@ -link /DLL /DEF:$(RUBYDEF) + $(CC) $(LDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBY_A) $(LIBRUBY_SO).res $(LIBS) \ + -o $@ -link /DLL /DEF:$(RUBYDEF) /IMPLIB:$(LIBRUBY) !if "$(LIBRUBY_SO)" != "rubymw.dll" rubymw.dll: $(LIBRUBY) diff -pruPX ./.excludes current/win32/config.status.in devel/win32/config.status.in --- current/win32/config.status.in Wed Aug 9 13:32:24 2000 +++ devel/win32/config.status.in Tue Aug 22 11:20:45 2000 @@ -56,8 +56,8 @@ s%@RUBY_SO_NAME@%ruby.mswin32%g s%@LIBRUBY_A@%lib$(RUBY_INSTALL_NAME).lib%g s%@LIBRUBY_SO@%%g s%@LIBRUBY_ALIASES@%%g -s%@LIBRUBY@%$(RUBY_SO_NAME).lib%g -s%@LIBRUBYARG@%$(topdir)/$(RUBY_SO_NAME).lib%g +s%@LIBRUBY@%$(RUBY_INSTALL_NAME).lib%g +s%@LIBRUBYARG@%$(RUBY_INSTALL_NAME).lib%g s%@SOLIBS@%%g s%@DLDLIBS@%%g s%@arch@%i586-mswin32%g
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦