diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-12-22 03:22:25 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-12-22 03:22:25 +0000 |
commit | 0e47c138c9bba4396fc7d956b05e5725000012f1 (patch) | |
tree | 54fac5b90c2ce6664e7017d954add4d06e388a09 /ext/extmk.rb.in | |
parent | 31c53aaa7dc3da8bc9ba6b3007c183dcbeeafe11 (diff) | |
download | ruby-0e47c138c9bba4396fc7d956b05e5725000012f1.tar.gz |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/extmk.rb.in')
-rw-r--r-- | ext/extmk.rb.in | 93 |
1 files changed, 62 insertions, 31 deletions
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$(<D) $(CFLAGS) $(CPPFLAGS) -c $(<:/=\\) +" + elsif /nmake/i =~ $make + mfile.print " +{$(srcdir)}.c{}.@OBJEXT@: + $(CC) -I. -I$(<D) $(CFLAGS) $(CPPFLAGS) -c $(<:/=\\) +.c.@OBJEXT@: + $(CC) $(CFLAGS) $(CPPFLAGS) -c $(<:/=\\) " else - mfile.puts " + mfile.print " .c.@OBJEXT@: - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< + $(CC) $(CFLAGS) $(CPPFLAGS) -c $(subst /,\\\\,$<) " end @@ -496,10 +522,15 @@ $(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 + if /nmake/i =~ $make + mfile.print "\tset LIB=$(LIBPATH:/=\\);$(LIB)\n" + else + mfile.print "\tenv LIB='$(subst /,\\\\,$(LIBPATH));$(LIB)' \\\n" + end + end + mfile.print "\t$(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS)\n" elsif RUBY_PLATFORM == "m68k-human" mfile.printf "\ $(DLLIB): $(OBJS) @@ -517,7 +548,7 @@ $(DLLIB): $(OBJS) mfile.printf "###\n" while line = dfile.gets() line.gsub!(/\.o\b/, ".#{$OBJEXT}") - line.gsub!(/(\s)([^\s\/]+\.[ch])/, '\1$(srcdir)/\2') if /mswin32/ =~ RUBY_PLATFORM + line.gsub!(/(\s)([^\s\/]+\.[ch])/, '\1$(srcdir)/\2') if /nmake/i =~ $make mfile.printf "%s", line.gsub('\$\(hdrdir\)/config.h', '$(topdir)/config.h') end dfile.close @@ -543,26 +574,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) |