From 0e47c138c9bba4396fc7d956b05e5725000012f1 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 22 Dec 2000 03:22:25 +0000 Subject: matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/extmk.rb.in | 93 ++++++++++++++++++++++++++++++++++----------------- ext/socket/extconf.rb | 5 +-- 2 files changed, 65 insertions(+), 33 deletions(-) (limited to 'ext') diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in index b93781658f..92d11d0f6e 100644 --- a/ext/extmk.rb.in +++ b/ext/extmk.rb.in @@ -1,6 +1,8 @@ #! /usr/local/bin/ruby +# -*- ruby -*- $".push 'mkmf.rb' +ORIG_LIBPATH = ENV['LIB'] if ARGV[0] == 'static' $force_static = true @@ -90,7 +92,19 @@ 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 + $LDFLAGS = ldflags + ENV['LIB'] = ORIG_LIBPATH if /mswin32/ =~ RUBY_PLATFORM + end end def try_link(src, opt="") @@ -205,17 +219,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 @@ -270,7 +284,7 @@ def arg_config(config, default=nil) $configure_args = {} args = "@configure_args@" if /mswin32|mingw/ =~ RUBY_PLATFORM and ENV["CONFIGURE_ARGS"] - args = args + " " + ENV["CONFIGURE_ARGS"] + args << " " << ENV["CONFIGURE_ARGS"] end for arg in args.split next unless /^--/ =~ arg @@ -321,19 +335,18 @@ def dir_config(target, idefault=nil, ldefault=nil) dir = with_config("%s-dir"%target, default) if dir idir = " -I"+dir+"/include" - ldir = " -L"+dir+"/lib" + ldir = dir+"/lib" end unless idir dir = with_config("%s-include"%target, idefault) idir = " -I"+dir if dir end unless ldir - dir = with_config("%s-lib"%target, ldefault) - ldir = " -L"+dir if dir + ldir = with_config("%s-lib"%target, ldefault) end - $CFLAGS += idir if idir - $LDFLAGS += ldir if ldir + $CPPFLAGS += idir if idir + $LIBPATH |= [ldir] if ldir end def create_makefile(target) @@ -355,9 +368,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 = '' @@ -368,6 +381,12 @@ def create_makefile(target) defflag = "--def=" + target + ".def" end + if RUBY_PLATFORM =~ /mswin32/ + libpath = $LIBPATH.join(';') + else + $LIBPATH.each {|d| $DLDFLAGS << " -L" << d} + end + $srcdir = $top_srcdir + "/ext/" + $mdir mfile = open("Makefile", "w") mfile.binmode if /mingw/ =~ RUBY_PLATFORM @@ -389,6 +408,9 @@ CPPFLAGS = -I$(topdir) -I$(hdrdir) -I@includedir@ %s #$CPPFLAGS DLDFLAGS = #$DLDFLAGS #$LDFLAGS LDSHARED = @LDSHARED@ #{defflag} ", if $static then "" else "@CCDLFLAGS@" end, $defs.join(" ") + mfile.puts "LIBPATH = #{libpath}" if libpath + + mfile.puts ".SUFFIXES: .@OBJEXT@" unless "@OBJEXT@" == "o" mfile.printf "\ @@ -425,9 +447,8 @@ archdir = $(pkglibdir)/@arch@ mfile.printf "\n" ruby_interpreter = "$(topdir)/miniruby@EXEEXT@" - if /mswin32/ =~ RUBY_PLATFORM - ruby_interpreter = $topdir + "/miniruby@EXEEXT@" - ruby_interpreter.gsub!("/", "\\") + if /nmake/i =~ $make + ruby_interpreter = '$(topdir:/=\)\miniruby@EXEEXT@' end if defined? CROSS_COMPILING ruby_interpreter = "@MINIRUBY@" @@ -467,18 +488,23 @@ EOS install_rb(mfile, $srcdir) mfile.printf "\n" - if /mswin32/ =~ RUBY_PLATFORM + if /mswin32/ !~ RUBY_PLATFORM mfile.puts " -.c.obj: +.c.@OBJEXT@: $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -{$(srcdir)}.c{}.obj: - $(CC) -I. -I$(