From: "Nobuyoshi.Nakada" Date: 2000-08-22T13:30:16+09:00 Subject: [ruby-dev:10668] Re: bmingw package なかだです。 At Tue, 22 Aug 2000 01:35:25 +0900 WATANABE Hirofumi 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$(